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

AbstractMatcherFactory.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
23 abstract class AbstractMatcherFactory implements MatcherFactoryInterface
24 {
26 protected $repository;
27
29 protected $matchConfig;
30
32 protected $matchers;
33
39 protected $matcherRelativeNamespace;
40
47 protected $alreadyMatched;
48
49 public function __construct(Repository $repository, array $matchConfig = [])
50 {
51 @trigger_error(
52 "BlockMatcherFactory is deprecated, and will be removed in ezpublish-kernel 6.1.\n" .
53 'Use the ServiceAwareMatcherFactory with the relative namespace as a constructor argument instead.',
54 E_USER_DEPRECATED
55 );
56
57 $this->repository = $repository;
58 $this->matchConfig = $matchConfig;
59 $this->matchers = [];
60 $this->alreadyMatched = [];
61 }
62
74 protected function getMatcher($matcherIdentifier)
75 {
76 // Not a FQ class name, so take the relative namespace.
77 if ($matcherIdentifier[0] !== '\\' && defined('static::MATCHER_RELATIVE_NAMESPACE')) {
78 $matcherIdentifier = static::MATCHER_RELATIVE_NAMESPACE . "\\$matcherIdentifier";
79 }
80
81 // Retrieving the matcher instance from in-memory cache
82 if (isset($this->matchers[$matcherIdentifier])) {
83 return $this->matchers[$matcherIdentifier];
84 }
85
86 if (!class_exists($matcherIdentifier)) {
87 throw new InvalidArgumentException("Invalid matcher class '$matcherIdentifier'");
88 }
89 $this->matchers[$matcherIdentifier] = new $matcherIdentifier();
90
91 if ($this->matchers[$matcherIdentifier] instanceof RepositoryAwareInterface) {
92 $this->matchers[$matcherIdentifier]->setRepository($this->repository);
93 }
94
95 return $this->matchers[$matcherIdentifier];
96 }
97
107 public function match(View $view)
108 {
109 $viewType = $view->getViewType();
110
111 if (!isset($this->matchConfig[$viewType])) {
112 return null;
113 }
114
115 if (!isset($this->alreadyMatched[$viewType])) {
116 $this->alreadyMatched[$viewType] = new SplObjectStorage();
117 }
118
119 // If we already matched, just returned the matched value.
120 if (isset($this->alreadyMatched[$viewType][$view])) {
121 return $this->alreadyMatched[$viewType][$view];
122 }
123
124 foreach ($this->matchConfig[$viewType] as $configHash) {
125 $hasMatched = true;
126 $matcher = null;
127 foreach ($configHash['match'] as $matcherIdentifier => $value) {
128 $matcher = $this->getMatcher($matcherIdentifier);
129 $matcher->setMatchingConfig($value);
130 if (!$matcher->match($view)) {
131 $hasMatched = false;
132 }
133 }
134
135 if ($hasMatched) {
136 return $this->alreadyMatched[$viewType][$view] = $configHash + ['matcher' => $matcher];
137 }
138 }
139
140 return $this->alreadyMatched[$viewType][$view] = null;
141 }
142
151 abstract protected function doMatch(MatcherInterface $matcher, View $valueObject);
152 }
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory
Base for MatcherFactory classes.
Definition: AbstractMatcherFactory.php:24
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\match
match(View $view)
Checks if $valueObject has a usable configuration for $viewType.
Definition: AbstractMatcherFactory.php:107
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\$alreadyMatched
$alreadyMatched
Definition: AbstractMatcherFactory.php:47
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\$repository
$repository
Definition: AbstractMatcherFactory.php:26
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\getMatcher
getMatcher($matcherIdentifier)
Returns the matcher object.
Definition: AbstractMatcherFactory.php:74
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\$matcherRelativeNamespace
$matcherRelativeNamespace
Definition: AbstractMatcherFactory.php:39
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\$matchers
$matchers
Definition: AbstractMatcherFactory.php:32
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\$matchConfig
$matchConfig
Definition: AbstractMatcherFactory.php:29
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\doMatch
doMatch(MatcherInterface $matcher, View $valueObject)
Checks if $valueObject matches $matcher rules.
eZ\Publish\Core\MVC\Symfony\Matcher\AbstractMatcherFactory\__construct
__construct(Repository $repository, array $matchConfig=[])
Definition: AbstractMatcherFactory.php:49
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\Matcher\MatcherInterface
Base interface for matchers.
Definition: MatcherInterface.php:15
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+.