demandProperties = array_reduce($demandProperties, static function (array $result, DemandProperty $item) { $result[$item->getName()->name] = $item; return $result; }, []); } public function getProperty(DemandPropertyName $demandPropertyName): ?DemandProperty { return $this->demandProperties[$demandPropertyName->name] ?? null; } /** * @return DemandProperty[] */ public function getProperties(): array { return $this->demandProperties; } public function getPageId(): int { return (int)($this->getProperty(DemandPropertyName::pageId)?->getValue() ?? 0); } public function getQuery(): string { return $this->getProperty(DemandPropertyName::query)?->getValue() ?? ''; } public function getLimit(): int { return (int)($this->getProperty(DemandPropertyName::limit)?->getValue() ?? self::DEFAULT_LIMIT); } public function getOffset(): int { return (int)($this->getProperty(DemandPropertyName::offset)?->getValue() ?? 0); } /** * @return class-string[] */ public function getSearchProviders(): array { return $this->getProperty(DemandPropertyName::searchProviders)?->getValue() ?? []; } public static function fromRequest(ServerRequestInterface $request): static { $demandProperties = []; foreach (DemandPropertyName::cases() as $demandProperty) { $demandPropertyName = $demandProperty->name; $valueFromRequest = $request->getParsedBody()[$demandPropertyName] ?? $request->getQueryParams()[$demandPropertyName] ?? null; if ($valueFromRequest !== null) { $demandProperties[] = new DemandProperty($demandProperty, $valueFromRequest); } } return new static($demandProperties); } }