Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

HostElement.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher;
8
9 use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest;
10 use eZ\Publish\Core\MVC\Symfony\SiteAccess\VersatileMatcher;
11
12 class HostElement implements VersatileMatcher
13 {
15 private $request;
16
22 private $elementNumber;
23
29 private $hostElements;
30
36 public function __construct($elementNumber)
37 {
38 if (is_array($elementNumber)) {
39 // DI config parser will create an array with 'value' => number
40 $elementNumber = current($elementNumber);
41 }
42
43 $this->elementNumber = (int)$elementNumber;
44 }
45
46 public function __sleep()
47 {
48 return ['elementNumber', 'hostElements'];
49 }
50
56 public function match()
57 {
58 $elements = $this->getHostElements();
59
60 return isset($elements[$this->elementNumber - 1]) ? $elements[$this->elementNumber - 1] : false;
61 }
62
63 public function getName()
64 {
65 return 'host:element';
66 }
67
73 public function setRequest(SimplifiedRequest $request)
74 {
75 $this->request = $request;
76 }
77
78 public function getRequest()
79 {
80 return $this->request;
81 }
82
83 public function reverseMatch($siteAccessName)
84 {
85 $hostElements = explode('.', $this->request->host);
86 $elementNumber = $this->elementNumber - 1;
87 if (!isset($hostElements[$elementNumber])) {
88 return null;
89 }
90
91 $hostElements[$elementNumber] = $siteAccessName;
92 $this->request->setHost(implode('.', $hostElements));
93
94 return $this;
95 }
96
100 private function getHostElements()
101 {
102 if (isset($this->hostElements)) {
103 return $this->hostElements;
104 } elseif (!isset($this->request)) {
105 return [];
106 }
107
108 $elements = explode('.', $this->request->host);
109
110 return $this->hostElements = $elements;
111 }
112 }
eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest
Definition: SimplifiedRequest.php:21
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement
Definition: HostElement.php:13
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\getRequest
getRequest()
Returns the SimplifiedRequest object corresponding to the reverse match.
Definition: HostElement.php:78
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\$request
$request
Definition: HostElement.php:15
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\getName
getName()
Returns the matcher's name.
Definition: HostElement.php:63
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\$hostElements
$hostElements
Definition: HostElement.php:29
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\reverseMatch
reverseMatch($siteAccessName)
Returns matcher object corresponding to $siteAccessName or null if non applicable.
Definition: HostElement.php:83
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\__sleep
__sleep()
Definition: HostElement.php:46
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\__construct
__construct($elementNumber)
Constructor.
Definition: HostElement.php:36
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\setRequest
setRequest(SimplifiedRequest $request)
Injects the request object to match against.
Definition: HostElement.php:73
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\match
match()
Returns matching Siteaccess.
Definition: HostElement.php:56
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\getHostElements
getHostElements()
Definition: HostElement.php:100
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement\$elementNumber
$elementNumber
Definition: HostElement.php:22
eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher
Interface for SiteAccess matchers.
Definition: Publish/Core/MVC/Symfony/SiteAccess/Matcher.php:15
eZ\Publish\Core\MVC\Symfony\SiteAccess\VersatileMatcher
Interface for SiteAccess matchers.
Definition: VersatileMatcher.php:16
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.