*/ private array $resolved = []; /** * @param Closure(int): ?array{jpeg?: string, width?: int, height?: int, note?: string, grant: ?Grant, version: ?ContentElementVersion} $resolve */ public function __construct(private readonly Closure $resolve) {} /** * @return array{jpeg?: string, width?: int, height?: int, note?: string}|null */ public function __invoke(int $id): ?array { if (! array_key_exists($id, $this->resolved)) { $this->resolved[$id] = ($this->resolve)($id); } return $this->resolved[$id]; } /** * @return list */ public function used(): array { $used = []; foreach ($this->resolved as $found) { if ($found !== null && isset($found['jpeg']) && $found['version'] instanceof ContentElementVersion && $found['grant'] instanceof Grant) { $used[] = ['version' => $found['version'], 'grant' => $found['grant']]; } } return $used; } }