114 ClassDefinitions $classDefinitions,
115 array $scopePriorityScheme = [
'global'],
116 $cacheId =
'plugins',
119 $this->serializer = $serializer ?:
$objectManager->get(Serialize::class);
120 parent::__construct($reader, $configScope,
$cache, $cacheId, $this->serializer);
121 $this->_omConfig = $omConfig;
122 $this->_relations = $relations;
123 $this->_definitions = $definitions;
124 $this->_classDefinitions = $classDefinitions;
125 $this->_scopePriorityScheme = $scopePriorityScheme;
141 if (!array_key_exists(
$type, $this->_inherited)) {
142 $realType = $this->_omConfig->getOriginalInstanceType(
$type);
144 if ($realType !==
$type) {
147 $relations = $this->_relations->getParents(
$type);
149 foreach ($relations as $relation) {
152 if ($relationPlugins) {
153 $plugins = array_replace_recursive($plugins, $relationPlugins);
160 if (isset($this->_data[
$type])) {
162 $plugins = $this->_data[
$type];
164 $plugins = array_replace_recursive($plugins, $this->_data[
$type]);
167 $this->_inherited[
$type] =
null;
168 if (is_array($plugins) && count($plugins)) {
169 $this->filterPlugins($plugins);
170 uasort($plugins, [$this,
'_sort']);
171 $this->trimInstanceStartingBackslash($plugins);
172 $this->_inherited[
$type] = $plugins;
174 foreach ($plugins as $key => $plugin) {
176 if (isset($plugin[
'disabled']) && $plugin[
'disabled']) {
177 unset($plugins[$key]);
180 $pluginType = $this->_omConfig->getOriginalInstanceType($plugin[
'instance']);
182 throw new \InvalidArgumentException(
'Plugin class ' . $pluginType .
' doesn\'t exist');
184 foreach ($this->_definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) {
185 $current = isset($lastPerMethod[$pluginMethod]) ? $lastPerMethod[$pluginMethod] :
'__self';
186 $currentKey =
$type .
'_' . $pluginMethod .
'_' . $current;
189 $lastPerMethod[$pluginMethod] = $key;
202 return $this->_inherited[
$type];
211 private function trimInstanceStartingBackslash(&$plugins)
213 foreach ($plugins as &$plugin) {
214 $plugin[
'instance'] = ltrim($plugin[
'instance'],
'\\');
225 protected function _sort($itemA, $itemB)
227 if (isset($itemA[
'sortOrder'])) {
228 if (isset($itemB[
'sortOrder'])) {
229 return $itemA[
'sortOrder'] - $itemB[
'sortOrder'];
231 return $itemA[
'sortOrder'];
232 }
elseif (isset($itemB[
'sortOrder'])) {
233 return (0 - (
int)$itemB[
'sortOrder']);
248 if (!isset($this->_pluginInstances[
$type][
$code])) {
249 $this->_pluginInstances[
$type][
$code] = $this->_objectManager->get(
267 if (!isset($this->_inherited[
$type]) && !array_key_exists(
$type, $this->_inherited)) {
271 return $this->_processed[$key] ??
null;
282 $scope = $this->_configScope->getCurrentScope();
283 if (
false == isset($this->_loadedScopes[$scope])) {
284 if (
false == in_array($scope, $this->_scopePriorityScheme)) {
285 $this->_scopePriorityScheme[] = $scope;
287 $cacheId = implode(
'|', $this->_scopePriorityScheme) .
"|" .
$this->_cacheId;
288 $data = $this->_cache->load($cacheId);
290 list($this->_data, $this->_inherited, $this->_processed) = $this->serializer->unserialize(
$data);
291 foreach ($this->_scopePriorityScheme as $scopeCode) {
292 $this->_loadedScopes[$scopeCode] =
true;
296 foreach ($this->_scopePriorityScheme as $scopeCode) {
297 if (
false == isset($this->_loadedScopes[$scopeCode])) {
298 $data = $this->_reader->read($scopeCode) ?: [];
299 unset(
$data[
'preferences']);
300 if (count(
$data) > 0) {
301 $this->_inherited = [];
302 $this->_processed = [];
310 $this->_loadedScopes[$scopeCode] =
true;
316 foreach ($virtualTypes as
$class) {
323 $this->serializer->serialize([$this->_data, $this->_inherited, $this->_processed]),
327 $this->_pluginInstances = [];
339 return $this->_configScope->getCurrentScope() == $scopeCode;
349 return $this->_classDefinitions->getClasses();
361 if (isset($typeConfig[
'plugins'])) {
363 if (isset($this->_data[
$type])) {
364 $this->_data[
$type] = array_replace_recursive($this->_data[
$type], $typeConfig[
'plugins']);
366 $this->_data[
$type] = $typeConfig[
'plugins'];
378 private function filterPlugins(array &$plugins)
380 foreach ($plugins as
$name => $plugin) {
381 if (empty($plugin[
'instance'])) {
382 unset($plugins[
$name]);
383 $this->getLogger()->info(
"Reference to undeclared plugin with name '{$name}'.");
394 private function getLogger()
396 if ($this->logger ===
null) {
397 $this->logger = $this->_objectManager->get(\Psr\Log\LoggerInterface::class);
399 return $this->logger;
elseif(isset( $params[ 'redirect_parent']))
$_option $_optionId $class
__construct(ReaderInterface $reader, ScopeInterface $configScope, CacheInterface $cache, RelationsInterface $relations, ConfigInterface $omConfig, DefinitionInterface $definitions, ObjectManagerInterface $objectManager, ClassDefinitions $classDefinitions, array $scopePriorityScheme=['global'], $cacheId='plugins', SerializerInterface $serializer=null)
isCurrentScope($scopeCode)
getNext($type, $method, $code='__self')
if(!isset($_GET['name'])) $name