‪TYPO3CMS  ‪main
SearchDemand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
22 
29 {
30  public const ‪DEFAULT_LIMIT = 20;
31 
35  protected array ‪$demandProperties = [];
36 
40  final public function ‪__construct(array ‪$demandProperties = [])
41  {
42  $this->demandProperties = array_reduce(‪$demandProperties, static function (array $result, ‪DemandProperty $item) {
43  $result[$item->‪getName()->name] = $item;
44  return $result;
45  }, []);
46  }
47 
48  public function ‪getProperty(‪DemandPropertyName $demandPropertyName): ?‪DemandProperty
49  {
50  return $this->demandProperties[$demandPropertyName->name] ?? null;
51  }
52 
56  public function ‪getProperties(): array
57  {
59  }
60 
61  public function ‪getPageId(): int
62  {
63  return (int)($this->‪getProperty(DemandPropertyName::pageId)?->getValue() ?? 0);
64  }
65 
66  public function ‪getQuery(): string
67  {
68  return $this->‪getProperty(DemandPropertyName::query)?->getValue() ?? '';
69  }
70 
71  public function ‪getLimit(): int
72  {
73  return (int)($this->‪getProperty(DemandPropertyName::limit)?->getValue() ?? ‪self::DEFAULT_LIMIT);
74  }
75 
76  public function ‪getOffset(): int
77  {
78  return (int)($this->‪getProperty(DemandPropertyName::offset)?->getValue() ?? 0);
79  }
80 
84  public function ‪getSearchProviders(): array
85  {
86  return $this->‪getProperty(‪DemandPropertyName::searchProviders)?->getValue() ?? [];
87  }
88 
89  public static function ‪fromRequest(ServerRequestInterface $request): static
90  {
92  foreach (DemandPropertyName::cases() as $demandProperty) {
93  $demandPropertyName = $demandProperty->name;
94  $valueFromRequest = $request->getParsedBody()[$demandPropertyName] ?? $request->getQueryParams()[$demandPropertyName] ?? null;
95  if ($valueFromRequest !== null) {
96  ‪$demandProperties[] = new ‪DemandProperty($demandProperty, $valueFromRequest);
97  }
98  }
99 
100  return new static(‪$demandProperties);
101  }
102 }
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getProperty
‪getProperty(DemandPropertyName $demandPropertyName)
Definition: SearchDemand.php:48
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand
Definition: DemandProperty.php:18
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getProperties
‪DemandProperty[] getProperties()
Definition: SearchDemand.php:56
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getSearchProviders
‪class string< SearchProviderInterface >[] getSearchProviders()
Definition: SearchDemand.php:84
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\DemandPropertyName
‪DemandPropertyName
Definition: DemandPropertyName.php:21
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getPageId
‪getPageId()
Definition: SearchDemand.php:61
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\DemandProperty
Definition: DemandProperty.php:21
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand
Definition: SearchDemand.php:29
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getQuery
‪getQuery()
Definition: SearchDemand.php:66
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\$demandProperties
‪array $demandProperties
Definition: SearchDemand.php:35
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getOffset
‪getOffset()
Definition: SearchDemand.php:76
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\DEFAULT_LIMIT
‪const DEFAULT_LIMIT
Definition: SearchDemand.php:30
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\fromRequest
‪static fromRequest(ServerRequestInterface $request)
Definition: SearchDemand.php:89
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\searchProviders
‪@ searchProviders
Definition: DemandPropertyName.php:26
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\DemandProperty\getName
‪getName()
Definition: DemandProperty.php:27
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\getLimit
‪getLimit()
Definition: SearchDemand.php:71
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand\__construct
‪__construct(array $demandProperties=[])
Definition: SearchDemand.php:40
‪TYPO3\CMS\Backend\Search\LiveSearch\SearchProviderInterface
Definition: SearchProviderInterface.php:28