‪TYPO3CMS  ‪main
Page.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 
18 namespace ‪TYPO3\CMS\Core\Domain;
19 
23 class ‪Page implements \ArrayAccess
24 {
25  use ‪PropertyTrait;
26 
27  protected array ‪$specialPropertyNames = [
28  '_language',
29  '_LOCALIZED_UID',
30  '_REQUESTED_OVERLAY_LANGUAGE',
31  '_MP_PARAM',
32  '_ORIG_uid',
33  '_ORIG_pid',
34  '_SHORTCUT_ORIGINAL_PAGE_UID',
35  '_TRANSLATION_SOURCE',
36  ];
37 
38  protected array ‪$specialProperties = [];
39 
40  public function ‪__construct(array $properties)
41  {
42  foreach ($properties as $propertyName => $propertyValue) {
43  if (in_array($propertyName, $this->specialPropertyNames)) {
44  if ($propertyName === '_TRANSLATION_SOURCE' && !$propertyValue instanceof ‪Page) {
45  $this->specialProperties[$propertyName] = new ‪Page($propertyValue);
46  } else {
47  $this->specialProperties[$propertyName] = $propertyValue;
48  }
49  } else {
50  $this->properties[$propertyName] = $propertyValue;
51  }
52  }
53  }
54 
55  public function ‪getLanguageId(): int
56  {
57  return $this->specialProperties['_language'] ?? $this->properties['sys_language_uid'];
58  }
59 
60  public function ‪getPageId(): int
61  {
62  $pageId = isset($this->properties['l10n_parent']) && $this->properties['l10n_parent'] > 0 ? $this->properties['l10n_parent'] : $this->properties['uid'];
63  return (int)$pageId;
64  }
65 
66  public function ‪getTranslationSource(): ?‪Page
67  {
68  return $this->specialProperties['_TRANSLATION_SOURCE'] ?? null;
69  }
70 
71  public function ‪getRequestedLanguage(): ?int
72  {
73  return $this->specialProperties['_REQUESTED_OVERLAY_LANGUAGE'] ?? null;
74  }
75 
76  public function ‪toArray(bool $includeSpecialProperties = false): array
77  {
78  if ($includeSpecialProperties) {
79  return $this->properties + ‪$this->specialProperties;
80  }
81  return $this->properties;
82  }
83 }
‪TYPO3\CMS\Core\Domain\Page\getPageId
‪getPageId()
Definition: Page.php:60
‪TYPO3\CMS\Core\Domain\Page
Definition: Page.php:24
‪TYPO3\CMS\Core\Domain\Page\$specialProperties
‪array $specialProperties
Definition: Page.php:38
‪TYPO3\CMS\Core\Domain\PropertyTrait
Definition: PropertyTrait.php:24
‪TYPO3\CMS\Core\Domain
‪TYPO3\CMS\Core\Domain\Page\toArray
‪toArray(bool $includeSpecialProperties=false)
Definition: Page.php:76
‪TYPO3\CMS\Core\Domain\Page\getTranslationSource
‪getTranslationSource()
Definition: Page.php:66
‪TYPO3\CMS\Core\Domain\Page\getLanguageId
‪getLanguageId()
Definition: Page.php:55
‪TYPO3\CMS\Core\Domain\Page\$specialPropertyNames
‪array $specialPropertyNames
Definition: Page.php:27
‪TYPO3\CMS\Core\Domain\Page\getRequestedLanguage
‪getRequestedLanguage()
Definition: Page.php:71
‪TYPO3\CMS\Core\Domain\Page\__construct
‪__construct(array $properties)
Definition: Page.php:40