| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- declare(strict_types=1);
- namespace App\Domain\Jobs;
- use App\Domain\Time\Clock;
- use Psr\Log\LoggerInterface;
- /**
- * Per-invocation state passed into Job::run().
- *
- * Carries the clock + logger plus arbitrary params (e.g. `full=true` for
- * RecomputeScoresJob). `param()` is the only safe way to read params —
- * defaults handle missing keys without forcing every job to validate them.
- */
- final class JobContext
- {
- /**
- * @param array<string, mixed> $params
- */
- public function __construct(
- public readonly Clock $clock,
- public readonly LoggerInterface $logger,
- public readonly array $params = [],
- ) {
- }
- public function param(string $key, mixed $default = null): mixed
- {
- return $this->params[$key] ?? $default;
- }
- }
|