‪TYPO3CMS  10.4
Demand.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;
21 
26 class ‪Demand
27 {
31  protected ‪$sourceHost;
32 
36  protected ‪$sourcePath;
37 
41  protected ‪$target;
42 
46  protected ‪$statusCode;
47 
51  protected ‪$limit = 50;
52 
56  protected ‪$page;
57 
66  public function ‪__construct(int ‪$page = 1, string ‪$sourceHost = '', string ‪$sourcePath = '', string ‪$target = '', int ‪$statusCode = 0)
67  {
68  $this->page = ‪$page;
69  $this->sourceHost = ‪$sourceHost;
70  $this->sourcePath = ‪$sourcePath;
71  $this->target = ‪$target;
72  $this->statusCode = ‪$statusCode;
73  }
74 
81  public static function ‪createFromRequest(ServerRequestInterface $request): ‪Demand
82  {
83  ‪$page = (int)($request->getQueryParams()['page'] ?? $request->getParsedBody()['page'] ?? 1);
84  $demand = $request->getQueryParams()['demand'] ?? $request->getParsedBody()['demand'];
85  if (empty($demand)) {
86  return new self(‪$page);
87  }
88  ‪$sourceHost = $demand['source_host'] ?? '';
89  ‪$sourcePath = $demand['source_path'] ?? '';
90  ‪$statusCode = (int)($demand['target_statuscode'] ?? 0);
91  ‪$target = $demand['target'] ?? '';
93  }
94 
98  public function ‪getSourceHost(): string
99  {
101  }
102 
106  public function ‪getSourcePath(): string
107  {
109  }
110 
114  public function ‪getTarget(): string
115  {
117  }
118 
122  public function ‪getLimit(): int
123  {
125  }
126 
130  public function ‪getStatusCode(): int
131  {
133  }
134 
138  public function ‪hasSourceHost(): bool
139  {
140  return $this->sourceHost !== '';
141  }
142 
146  public function ‪hasSourcePath(): bool
147  {
148  return $this->sourcePath !== '';
149  }
150 
154  public function ‪hasTarget(): bool
155  {
156  return $this->target !== '';
157  }
158 
162  public function ‪hasStatusCode(): bool
163  {
164  return $this->statusCode !== 0;
165  }
166 
170  public function ‪hasConstraints(): bool
171  {
172  return $this->‪hasSourcePath()
173  || $this->‪hasSourceHost()
174  || $this->‪hasTarget();
175  }
176 
182  public function ‪getPage(): int
183  {
184  return ‪$this->page;
185  }
186 
192  public function ‪getOffset(): int
193  {
194  return ($this->page - 1) * ‪$this->limit;
195  }
196 
200  public function ‪getParameters(): array
201  {
202  $parameters = [];
203  if ($this->‪hasSourcePath()) {
204  $parameters['source_path'] = $this->‪getSourcePath();
205  }
206  if ($this->‪hasSourceHost()) {
207  $parameters['source_host'] = $this->‪getSourceHost();
208  }
209  if ($this->‪hasTarget()) {
210  $parameters['target'] = $this->‪getTarget();
211  }
212  if ($this->‪hasStatusCode()) {
213  $parameters['target_statuscode'] = $this->‪getStatusCode();
214  }
215  return $parameters;
216  }
217 }
‪TYPO3\CMS\Redirects\Repository\Demand
Definition: Demand.php:27
‪TYPO3\CMS\Redirects\Repository\Demand\getSourcePath
‪string getSourcePath()
Definition: Demand.php:100
‪TYPO3\CMS\Redirects\Repository\Demand\getLimit
‪int getLimit()
Definition: Demand.php:116
‪TYPO3\CMS\Redirects\Repository\Demand\$statusCode
‪int $statusCode
Definition: Demand.php:42
‪TYPO3\CMS\Redirects\Repository\Demand\getTarget
‪string getTarget()
Definition: Demand.php:108
‪TYPO3\CMS\Redirects\Repository\Demand\$sourceHost
‪string $sourceHost
Definition: Demand.php:30
‪TYPO3\CMS\Redirects\Repository\Demand\hasTarget
‪bool hasTarget()
Definition: Demand.php:148
‪TYPO3\CMS\Redirects\Repository\Demand\hasSourceHost
‪bool hasSourceHost()
Definition: Demand.php:132
‪TYPO3\CMS\Redirects\Repository\Demand\getPage
‪int getPage()
Definition: Demand.php:176
‪TYPO3\CMS\Redirects\Repository\Demand\getOffset
‪int getOffset()
Definition: Demand.php:186
‪TYPO3\CMS\Redirects\Repository\Demand\$target
‪string $target
Definition: Demand.php:38
‪TYPO3\CMS\Redirects\Repository\Demand\getSourceHost
‪string getSourceHost()
Definition: Demand.php:92
‪TYPO3\CMS\Redirects\Repository\Demand\hasConstraints
‪bool hasConstraints()
Definition: Demand.php:164
‪TYPO3\CMS\Redirects\Repository\Demand\$limit
‪int $limit
Definition: Demand.php:46
‪TYPO3\CMS\Redirects\Repository\Demand\getStatusCode
‪int getStatusCode()
Definition: Demand.php:124
‪TYPO3\CMS\Redirects\Repository\Demand\hasStatusCode
‪bool hasStatusCode()
Definition: Demand.php:156
‪TYPO3\CMS\Redirects\Repository\Demand\hasSourcePath
‪bool hasSourcePath()
Definition: Demand.php:140
‪TYPO3\CMS\Redirects\Repository\Demand\$page
‪int $page
Definition: Demand.php:50
‪TYPO3\CMS\Redirects\Repository
Definition: Demand.php:18
‪TYPO3\CMS\Redirects\Repository\Demand\$sourcePath
‪string $sourcePath
Definition: Demand.php:34
‪TYPO3\CMS\Redirects\Repository\Demand\__construct
‪__construct(int $page=1, string $sourceHost='', string $sourcePath='', string $target='', int $statusCode=0)
Definition: Demand.php:60
‪TYPO3\CMS\Redirects\Repository\Demand\getParameters
‪array getParameters()
Definition: Demand.php:194
‪TYPO3\CMS\Redirects\Repository\Demand\createFromRequest
‪static Demand createFromRequest(ServerRequestInterface $request)
Definition: Demand.php:75