123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Developer\Model\Di;
- use Magento\Framework\Interception;
- use Magento\Framework\Interception\DefinitionInterface;
- /**
- * Provides plugin list configuration
- */
- class PluginList extends Interception\PluginList\PluginList
- {
- /**#@+
- * Constants for the plugin types
- */
- const PLUGIN_TYPE_BEFORE = 'before';
- const PLUGIN_TYPE_AROUND = 'around';
- const PLUGIN_TYPE_AFTER = 'after';
- /**#@-*/
- /**#@-*/
- private $pluginList = [
- self::PLUGIN_TYPE_BEFORE => [],
- self::PLUGIN_TYPE_AROUND => [],
- self::PLUGIN_TYPE_AFTER => []
- ];
- /**
- * Mapping of plugin type codes to plugin types
- * @var array
- */
- private $pluginTypeMapping = [
- DefinitionInterface::LISTENER_AROUND => self::PLUGIN_TYPE_AROUND,
- DefinitionInterface::LISTENER_BEFORE => self::PLUGIN_TYPE_BEFORE,
- DefinitionInterface::LISTENER_AFTER => self::PLUGIN_TYPE_AFTER
- ];
- /**
- * Returns plugins config
- *
- * @return array
- */
- public function getPluginsConfig()
- {
- $this->_loadScopedData();
- return $this->_inherited;
- }
- /**
- * Sets scope priority scheme
- *
- * @param array $areaCodes
- *
- * @return void
- */
- public function setScopePriorityScheme($areaCodes)
- {
- $this->_scopePriorityScheme = $areaCodes;
- }
- /**
- * Whether scope code is current scope code
- *
- * @param string $scopeCode
- *
- * @return bool
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- protected function isCurrentScope($scopeCode)
- {
- return false;
- }
- /**
- * Load the plugins information
- *
- * @param string $type
- * @return array
- */
- private function getPlugins($type)
- {
- $this->_loadScopedData();
- if (!isset($this->_inherited[$type]) && !array_key_exists($type, $this->_inherited)) {
- $this->_inheritPlugins($type);
- }
- return $this->_inherited[$type];
- }
- /**
- * Return the list of plugins for the class
- *
- * @param string $className
- * @return array
- * @throws \InvalidArgumentException
- */
- public function getPluginsListByClass($className)
- {
- $this->getPlugins($className);
- if (!isset($this->_inherited[$className])) {
- return $this->pluginList;
- }
- foreach ($this->_inherited[$className] as $plugin) {
- foreach ($this->_definitions->getMethodList($plugin['instance']) as $pluginMethod => $methodTypes) {
- $this->addPluginToList(
- $plugin['instance'],
- $pluginMethod,
- $methodTypes,
- DefinitionInterface::LISTENER_AROUND
- );
- $this->addPluginToList(
- $plugin['instance'],
- $pluginMethod,
- $methodTypes,
- DefinitionInterface::LISTENER_BEFORE
- );
- $this->addPluginToList(
- $plugin['instance'],
- $pluginMethod,
- $methodTypes,
- DefinitionInterface::LISTENER_AFTER
- );
- }
- }
- return $this->pluginList;
- }
- /**
- * Add plugin to the appropriate type bucket
- *
- * @param string $pluginInstance
- * @param string $pluginMethod
- * @param int $methodTypes
- * @param int $typeCode
- * @return void
- */
- private function addPluginToList($pluginInstance, $pluginMethod, $methodTypes, $typeCode)
- {
- if ($methodTypes & $typeCode) {
- if (!array_key_exists($pluginInstance, $this->pluginList[$this->pluginTypeMapping[$typeCode]])) {
- $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance] = [];
- }
- if (!in_array($pluginMethod, $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance])) {
- $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance][] = $pluginMethod;
- }
- }
- }
- }
|