- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
92 lines
2.2 KiB
PHP
92 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
use App\Domain\SmartLink\Entities\SmartLink;
|
|
use App\Domain\SmartLink\Enums\LinkStatus;
|
|
use App\Domain\SmartLink\Repositories\SmartLinkRepository;
|
|
use App\Domain\SmartLink\ValueObjects\ShortCode;
|
|
use App\Domain\SmartLink\ValueObjects\SmartLinkId;
|
|
|
|
final class InMemorySmartLinkRepository implements SmartLinkRepository
|
|
{
|
|
/** @var array<string, SmartLink> */
|
|
private array $links = [];
|
|
|
|
/** @var array<string, int> */
|
|
private array $clicks = [];
|
|
|
|
public function save(SmartLink $link): void
|
|
{
|
|
$this->links[$link->id->toString()] = $link;
|
|
}
|
|
|
|
public function findById(SmartLinkId $id): ?SmartLink
|
|
{
|
|
return $this->links[$id->toString()] ?? null;
|
|
}
|
|
|
|
public function findByShortCode(ShortCode $shortCode): ?SmartLink
|
|
{
|
|
foreach ($this->links as $link) {
|
|
if ($link->shortCode->equals($shortCode)) {
|
|
return $link;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function findByUserId(string $userId, ?LinkStatus $status = null): array
|
|
{
|
|
$result = [];
|
|
|
|
foreach ($this->links as $link) {
|
|
if ($link->userId === $userId) {
|
|
if ($status === null || $link->status === $status) {
|
|
$result[] = $link;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function existsShortCode(ShortCode $shortCode): bool
|
|
{
|
|
return $this->findByShortCode($shortCode) !== null;
|
|
}
|
|
|
|
public function delete(SmartLinkId $id): void
|
|
{
|
|
unset($this->links[$id->toString()]);
|
|
}
|
|
|
|
public function findActiveLinks(): array
|
|
{
|
|
return array_filter(
|
|
$this->links,
|
|
fn(SmartLink $link) => $link->status === LinkStatus::ACTIVE
|
|
);
|
|
}
|
|
|
|
public function getTotalClicks(SmartLinkId $id): int
|
|
{
|
|
return $this->clicks[$id->toString()] ?? 0;
|
|
}
|
|
|
|
// Test helpers
|
|
public function clear(): void
|
|
{
|
|
$this->links = [];
|
|
$this->clicks = [];
|
|
}
|
|
|
|
public function setClicks(SmartLinkId $id, int $clicks): void
|
|
{
|
|
$this->clicks[$id->toString()] = $clicks;
|
|
}
|
|
}
|