‪TYPO3CMS  9.5
AbstractXmlSitemapDataProvider.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\ServerRequestInterface;
22 
27 {
31  protected ‪$key;
32 
36  protected ‪$lastModified;
37 
41  protected ‪$items = [];
42 
46  protected ‪$config = [];
47 
51  protected ‪$cObj;
52 
56  protected ‪$numberOfItemsPerPage = 1000;
57 
61  protected ‪$request;
62 
71  public function ‪__construct(ServerRequestInterface ‪$request, string ‪$key, array ‪$config = [], ‪ContentObjectRenderer ‪$cObj = null)
72  {
73  $this->key = ‪$key;
74  $this->config = ‪$config;
75  $this->request = ‪$request;
76 
77  if (‪$cObj === null) {
78  ‪$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
79  }
80  $this->cObj = ‪$cObj;
81  }
82 
86  public function ‪getKey(): string
87  {
88  return ‪$this->key;
89  }
90 
94  public function ‪getNumberOfPages(): int
95  {
96  return (int)ceil(count($this->items) / $this->numberOfItemsPerPage);
97  }
98 
102  public function ‪getLastModified(): int
103  {
104  $lastMod = 0;
105  foreach ($this->items as $item) {
106  if ((int)$item['lastMod'] > $lastMod) {
107  $lastMod = (int)$item['lastMod'];
108  }
109  }
110 
111  return $lastMod;
112  }
113 
118  protected function ‪defineUrl(array $data): array
119  {
120  return $data;
121  }
122 
126  public function ‪getItems(): array
127  {
128  $pageNumber = (int)($this->request->getQueryParams()['page'] ?? 0);
129  $page = $pageNumber > 0 ? $pageNumber : 0;
130  ‪$items = array_slice(
131  $this->items,
132  $page * $this->numberOfItemsPerPage,
133  $this->numberOfItemsPerPage
134  );
135 
136  return array_map([$this, 'defineUrl'], ‪$items);
137  }
138 }
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getKey
‪string getKey()
Definition: AbstractXmlSitemapDataProvider.php:79
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$key
‪string $key
Definition: AbstractXmlSitemapDataProvider.php:30
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getNumberOfPages
‪int getNumberOfPages()
Definition: AbstractXmlSitemapDataProvider.php:87
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$config
‪array $config
Definition: AbstractXmlSitemapDataProvider.php:42
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getLastModified
‪int getLastModified()
Definition: AbstractXmlSitemapDataProvider.php:95
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$numberOfItemsPerPage
‪int $numberOfItemsPerPage
Definition: AbstractXmlSitemapDataProvider.php:50
‪TYPO3\CMS\Seo\XmlSitemap\XmlSitemapDataProviderInterface
Definition: XmlSitemapDataProviderInterface.php:26
‪TYPO3\CMS\Seo\XmlSitemap
Definition: AbstractXmlSitemapDataProvider.php:4
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$items
‪array $items
Definition: AbstractXmlSitemapDataProvider.php:38
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\defineUrl
‪array defineUrl(array $data)
Definition: AbstractXmlSitemapDataProvider.php:111
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$request
‪ServerRequestInterface $request
Definition: AbstractXmlSitemapDataProvider.php:54
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getItems
‪array getItems()
Definition: AbstractXmlSitemapDataProvider.php:119
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider
Definition: AbstractXmlSitemapDataProvider.php:27
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\__construct
‪__construct(ServerRequestInterface $request, string $key, array $config=[], ContentObjectRenderer $cObj=null)
Definition: AbstractXmlSitemapDataProvider.php:64
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$lastModified
‪int $lastModified
Definition: AbstractXmlSitemapDataProvider.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractXmlSitemapDataProvider.php:46