public function testGetOriginalInstanceTypeReturnsInterceptedClass() { $this->interceptionConfig->expects($this->once())->method('hasPlugins')->will($this->returnValue(true)); $this->model->setInterceptionConfig($this->interceptionConfig); $this->assertEquals('SomeClass\\Interceptor', $this->model->getInstanceType('SomeClass')); $this->assertEquals('SomeClass', $this->model->getOriginalInstanceType('SomeClass')); }
/** * Collect parent types configuration for requested type * * @param string $type * @return array * @throws InvalidArgumentException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _inheritPlugins($type) { if (!array_key_exists($type, $this->_inherited)) { $realType = $this->_omConfig->getOriginalInstanceType($type); if ($realType !== $type) { $plugins = $this->_inheritPlugins($realType); } else { if ($this->_relations->has($type)) { $relations = $this->_relations->getParents($type); $plugins = array(); foreach ($relations as $relation) { if ($relation) { $relationPlugins = $this->_inheritPlugins($relation); if ($relationPlugins) { $plugins = array_replace_recursive($plugins, $relationPlugins); } } } } else { $plugins = array(); } } 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, array($this, '_sort')); $this->_inherited[$type] = $plugins; $lastPerMethod = array(); 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 & Definition::LISTENER_AROUND) { $this->_processed[$currentKey][Definition::LISTENER_AROUND] = $key; $lastPerMethod[$pluginMethod] = $key; } if ($methodTypes & Definition::LISTENER_BEFORE) { $this->_processed[$currentKey][Definition::LISTENER_BEFORE][] = $key; } if ($methodTypes & Definition::LISTENER_AFTER) { $this->_processed[$currentKey][Definition::LISTENER_AFTER][] = $key; } } } } return $plugins; } return $this->_inherited[$type]; }