Exemple #1
0
 /**
  * Process interception inheritance
  *
  * @param string $type
  * @return bool
  */
 protected function _inheritInterception($type)
 {
     $type = ltrim($type, '\\');
     if (!isset($this->_intercepted[$type])) {
         $realType = $this->_omConfig->getOriginalInstanceType($type);
         if ($type !== $realType) {
             if ($this->_inheritInterception($realType)) {
                 $this->_intercepted[$type] = true;
                 return true;
             }
         } else {
             $parts = explode('\\', $type);
             if (!in_array(end($parts), $this->_serviceClassTypes) && $this->_relations->has($type)) {
                 $relations = $this->_relations->getParents($type);
                 foreach ($relations as $relation) {
                     if ($relation && $this->_inheritInterception($relation)) {
                         $this->_intercepted[$type] = true;
                         return true;
                     }
                 }
             }
         }
         $this->_intercepted[$type] = false;
     }
     return $this->_intercepted[$type];
 }
Exemple #2
0
 /**
  * Collect parent types configuration for requested type
  *
  * @param string $type
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _collectConfiguration($type)
 {
     if (!isset($this->_mergedArguments[$type])) {
         if (isset($this->_virtualTypes[$type])) {
             $arguments = $this->_collectConfiguration($this->_virtualTypes[$type]);
         } elseif ($this->_relations->has($type)) {
             $relations = $this->_relations->getParents($type);
             $arguments = [];
             foreach ($relations as $relation) {
                 if ($relation) {
                     $relationArguments = $this->_collectConfiguration($relation);
                     if ($relationArguments) {
                         $arguments = array_replace($arguments, $relationArguments);
                     }
                 }
             }
         } else {
             $arguments = [];
         }
         if (isset($this->_arguments[$type])) {
             if ($arguments && count($arguments)) {
                 $arguments = array_replace_recursive($arguments, $this->_arguments[$type]);
             } else {
                 $arguments = $this->_arguments[$type];
             }
         }
         $this->_mergedArguments[$type] = $arguments;
         return $arguments;
     }
     return $this->_mergedArguments[$type];
 }
Exemple #3
0
 /**
  * Collect parent types configuration for requested type
  *
  * @param string $type
  * @return array
  * @throws \InvalidArgumentException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _inheritPlugins($type)
 {
     $type = ltrim($type, '\\');
     if (!array_key_exists($type, $this->_inherited)) {
         $realType = $this->_omConfig->getOriginalInstanceType($type);
         if ($realType !== $type) {
             $plugins = $this->_inheritPlugins($realType);
         } elseif ($this->_relations->has($type)) {
             $relations = $this->_relations->getParents($type);
             $plugins = [];
             foreach ($relations as $relation) {
                 if ($relation) {
                     $relationPlugins = $this->_inheritPlugins($relation);
                     if ($relationPlugins) {
                         $plugins = array_replace_recursive($plugins, $relationPlugins);
                     }
                 }
             }
         } else {
             $plugins = [];
         }
         if (isset($this->_data[$type])) {
             if (!$plugins) {
                 $plugins = $this->_data[$type];
             } else {
                 $plugins = array_replace_recursive($plugins, $this->_data[$type]);
             }
         }
         $this->_inherited[$type] = null;
         if (is_array($plugins) && count($plugins)) {
             uasort($plugins, [$this, '_sort']);
             $this->trimInstanceStartingBackslash($plugins);
             $this->_inherited[$type] = $plugins;
             $lastPerMethod = [];
             foreach ($plugins as $key => $plugin) {
                 // skip disabled plugins
                 if (isset($plugin['disabled']) && $plugin['disabled']) {
                     unset($plugins[$key]);
                     continue;
                 }
                 $pluginType = $this->_omConfig->getOriginalInstanceType($plugin['instance']);
                 if (!class_exists($pluginType)) {
                     throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist');
                 }
                 foreach ($this->_definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) {
                     $current = isset($lastPerMethod[$pluginMethod]) ? $lastPerMethod[$pluginMethod] : '__self';
                     $currentKey = $type . '_' . $pluginMethod . '_' . $current;
                     if ($methodTypes & DefinitionInterface::LISTENER_AROUND) {
                         $this->_processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key;
                         $lastPerMethod[$pluginMethod] = $key;
                     }
                     if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) {
                         $this->_processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key;
                     }
                     if ($methodTypes & DefinitionInterface::LISTENER_AFTER) {
                         $this->_processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key;
                     }
                 }
             }
         }
         return $plugins;
     }
     return $this->_inherited[$type];
 }