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

ClassNameMatcherFactory.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\MVC\Symfony\Matcher;
8
9 use eZ\Publish\API\Repository\Repository;
10 use eZ\Publish\Core\MVC\RepositoryAwareInterface;
11 use eZ\Publish\Core\MVC\Symfony\View\View;
12 use SplObjectStorage;
13 use InvalidArgumentException;
14
21 class ClassNameMatcherFactory implements MatcherFactoryInterface
22 {
24 protected $repository;
25
32 protected $matchConfig;
33
35 protected $matchers = [];
36
42 protected $matcherRelativeNamespace;
43
50 protected $alreadyMatched = [];
51
52 public function __construct(Repository $repository, $relativeNamespace = null, array $matchConfig = [])
53 {
54 $this->repository = $repository;
55 $this->matcherRelativeNamespace = $relativeNamespace;
56 $this->matchConfig = $matchConfig;
57 }
58
71 protected function getMatcher($matcherIdentifier)
72 {
73 // Not a FQ class name, so take the relative namespace.
74 if ($matcherIdentifier[0] !== '\\' && $this->matcherRelativeNamespace !== null) {
75 $matcherIdentifier = $this->matcherRelativeNamespace . "\\$matcherIdentifier";
76 }
77
78 // Retrieving the matcher instance from in-memory cache
79 if (isset($this->matchers[$matcherIdentifier])) {
80 return $this->matchers[$matcherIdentifier];
81 }
82
83 if (!class_exists($matcherIdentifier)) {
84 throw new InvalidArgumentException("Invalid matcher class '$matcherIdentifier'");
85 }
86 $this->matchers[$matcherIdentifier] = new $matcherIdentifier();
87
88 if ($this->matchers[$matcherIdentifier] instanceof RepositoryAwareInterface) {
89 $this->matchers[$matcherIdentifier]->setRepository($this->repository);
90 }
91
92 return $this->matchers[$matcherIdentifier];
93 }
94
104 public function match(View $view)
105 {
106 $viewType = $view->getViewType();
107
108 if (!isset($this->matchConfig[$viewType])) {
109 return null;
110 }
111
112 if (!isset($this->alreadyMatched[$viewType])) {
113 $this->alreadyMatched[$viewType] = new SplObjectStorage();
114 }
115
116 // If we already matched, just returned the matched value.
117 if (isset($this->alreadyMatched[$viewType][$view])) {
118 return $this->alreadyMatched[$viewType][$view];
119 }
120
121 foreach ($this->matchConfig[$viewType] as $configHash) {
122 $hasMatched = true;
123 $matcher = null;
124 foreach ($configHash['match'] as $matcherIdentifier => $value) {
125 $matcher = $this->getMatcher($matcherIdentifier);
126 $matcher->setMatchingConfig($value);
127 if (!$matcher->match($view)) {
128 $hasMatched = false;
129 }
130 }
131
132 if ($hasMatched) {
133 return $this->alreadyMatched[$viewType][$view] = $configHash + ['matcher' => $matcher];
134 }
135 }
136
137 return $this->alreadyMatched[$viewType][$view] = null;
138 }
139
145 public function setMatchConfig($matchConfig)
146 {
147 $this->matchConfig = $matchConfig;
148
149 return $this;
150 }
151 }
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory
A matcher factory based on namespaces: matchers will be searched for as classes.
Definition: ClassNameMatcherFactory.php:22
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\$matcherRelativeNamespace
$matcherRelativeNamespace
Definition: ClassNameMatcherFactory.php:42
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\$alreadyMatched
$alreadyMatched
Definition: ClassNameMatcherFactory.php:50
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\$matchers
$matchers
Definition: ClassNameMatcherFactory.php:35
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\$matchConfig
$matchConfig
Definition: ClassNameMatcherFactory.php:32
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\match
match(View $view)
Checks if $valueObject has a usable configuration for $viewType.
Definition: ClassNameMatcherFactory.php:104
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\__construct
__construct(Repository $repository, $relativeNamespace=null, array $matchConfig=[])
Definition: ClassNameMatcherFactory.php:52
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\getMatcher
getMatcher($matcherIdentifier)
Returns the matcher object.
Definition: ClassNameMatcherFactory.php:71
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\setMatchConfig
setMatchConfig($matchConfig)
Definition: ClassNameMatcherFactory.php:145
eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory\$repository
$repository
Definition: ClassNameMatcherFactory.php:24
eZ\Publish\API\Repository\Repository
Repository interface.
Definition: API/Repository/Repository.php:16
eZ\Publish\Core\MVC\RepositoryAwareInterface
Definition: RepositoryAwareInterface.php:12
eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface
Definition: MatcherFactoryInterface.php:12
eZ\Publish\Core\MVC\Symfony\View\View
Main interface for Views of Value objects (content, block...).
Definition: Publish/Core/MVC/Symfony/View/View.php:16
eZ\Publish\Core\MVC\Symfony\View\View\getViewType
getViewType()
eZ\Publish\Core\MVC\Symfony\Matcher
Definition: AbstractMatcherFactory.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.