‪TYPO3CMS  10.4
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 {
32  protected ‪$key;
33 
37  protected ‪$lastModified;
38 
42  protected ‪$items = [];
43 
47  protected ‪$config = [];
48 
52  protected ‪$cObj;
53 
57  protected ‪$numberOfItemsPerPage = 1000;
58 
62  protected ‪$request;
63 
72  public function ‪__construct(ServerRequestInterface ‪$request, string ‪$key, array ‪$config = [], ‪ContentObjectRenderer ‪$cObj = null)
73  {
74  $this->key = ‪$key;
75  $this->config = ‪$config;
76  $this->request = ‪$request;
77 
78  if (‪$cObj === null) {
79  ‪$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
80  }
81  $this->cObj = ‪$cObj;
82  }
83 
87  public function ‪getKey(): string
88  {
89  return ‪$this->key;
90  }
91 
95  public function ‪getNumberOfPages(): int
96  {
97  return (int)ceil(count($this->items) / $this->numberOfItemsPerPage);
98  }
99 
103  public function ‪getLastModified(): int
104  {
105  $lastMod = 0;
106  foreach ($this->items as $item) {
107  if ((int)$item['lastMod'] > $lastMod) {
108  $lastMod = (int)$item['lastMod'];
109  }
110  }
111 
112  return $lastMod;
113  }
114 
119  protected function ‪defineUrl(array $data): array
120  {
121  return $data;
122  }
123 
127  public function ‪getItems(): array
128  {
129  $pageNumber = (int)($this->request->getQueryParams()['page'] ?? 0);
130  $page = $pageNumber > 0 ? $pageNumber : 0;
131  ‪$items = array_slice(
132  $this->items,
133  $page * $this->numberOfItemsPerPage,
134  $this->numberOfItemsPerPage
135  );
136 
137  return array_map([$this, 'defineUrl'], ‪$items);
138  }
139 }
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getKey
‪string getKey()
Definition: AbstractXmlSitemapDataProvider.php:80
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$key
‪string $key
Definition: AbstractXmlSitemapDataProvider.php:31
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getNumberOfPages
‪int getNumberOfPages()
Definition: AbstractXmlSitemapDataProvider.php:88
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$config
‪array $config
Definition: AbstractXmlSitemapDataProvider.php:43
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getLastModified
‪int getLastModified()
Definition: AbstractXmlSitemapDataProvider.php:96
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$numberOfItemsPerPage
‪int $numberOfItemsPerPage
Definition: AbstractXmlSitemapDataProvider.php:51
‪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:39
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\defineUrl
‪array defineUrl(array $data)
Definition: AbstractXmlSitemapDataProvider.php:112
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$request
‪ServerRequestInterface $request
Definition: AbstractXmlSitemapDataProvider.php:55
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\getItems
‪array getItems()
Definition: AbstractXmlSitemapDataProvider.php:120
‪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:65
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$lastModified
‪int $lastModified
Definition: AbstractXmlSitemapDataProvider.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractXmlSitemapDataProvider.php:47