‪TYPO3CMS  ‪main
AbstractXmlSitemapDataProvider.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;
23 
28 {
29  protected string ‪$key;
30  protected array ‪$items = [];
31  protected array ‪$config = [];
33  protected int ‪$numberOfItemsPerPage = 1000;
34  protected ServerRequestInterface ‪$request;
35 
36  public function ‪__construct(ServerRequestInterface ‪$request, string ‪$key, array ‪$config = [], ‪ContentObjectRenderer ‪$cObj = null)
37  {
38  $this->key = ‪$key;
39  $this->config = ‪$config;
40  $this->request = ‪$request;
41  $this->cObj = ‪$cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class);
42  }
43 
44  public function ‪getKey(): string
45  {
46  return ‪$this->key;
47  }
48 
49  public function ‪getNumberOfPages(): int
50  {
51  return (int)ceil(count($this->items) / $this->numberOfItemsPerPage);
52  }
53 
54  public function ‪getLastModified(): int
55  {
56  $lastMod = 0;
57  foreach ($this->items as $item) {
58  if ((int)($item['lastMod'] ?? 0) > $lastMod) {
59  $lastMod = (int)$item['lastMod'];
60  }
61  }
62 
63  return $lastMod;
64  }
65 
66  protected function ‪defineUrl(array $data): array
67  {
68  return $data;
69  }
70 
71  public function ‪getItems(): array
72  {
73  $pageNumber = (int)($this->request->getQueryParams()['page'] ?? 0);
74  $page = $pageNumber > 0 ? $pageNumber : 0;
75  ‪$items = array_slice(
76  $this->items,
77  $page * $this->numberOfItemsPerPage,
78  $this->numberOfItemsPerPage
79  );
80 
81  return array_map([$this, 'defineUrl'], ‪$items);
82  }
83 }
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$key
‪string $key
Definition: AbstractXmlSitemapDataProvider.php:29
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$config
‪array $config
Definition: AbstractXmlSitemapDataProvider.php:31
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$numberOfItemsPerPage
‪int $numberOfItemsPerPage
Definition: AbstractXmlSitemapDataProvider.php:33
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getNumberOfPages
‪getNumberOfPages()
Definition: AbstractXmlSitemapDataProvider.php:49
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getKey
‪getKey()
Definition: AbstractXmlSitemapDataProvider.php:44
‪TYPO3\CMS\Seo\XmlSitemap\XmlSitemapDataProviderInterface
Definition: XmlSitemapDataProviderInterface.php:27
‪TYPO3\CMS\Seo\XmlSitemap
Definition: AbstractXmlSitemapDataProvider.php:18
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$items
‪array $items
Definition: AbstractXmlSitemapDataProvider.php:30
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\defineUrl
‪defineUrl(array $data)
Definition: AbstractXmlSitemapDataProvider.php:66
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$request
‪ServerRequestInterface $request
Definition: AbstractXmlSitemapDataProvider.php:34
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider
Definition: AbstractXmlSitemapDataProvider.php:28
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\__construct
‪__construct(ServerRequestInterface $request, string $key, array $config=[], ContentObjectRenderer $cObj=null)
Definition: AbstractXmlSitemapDataProvider.php:36
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getLastModified
‪getLastModified()
Definition: AbstractXmlSitemapDataProvider.php:54
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getItems
‪getItems()
Definition: AbstractXmlSitemapDataProvider.php:71
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractXmlSitemapDataProvider.php:32