/** * Process interception inheritance * * @param string $type * @return bool */ protected function _inheritInterception($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]; }
/** * Create instance with call time arguments * * @param string $requestedType * @param array $arguments * @return object * @throws \Exception * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function create($requestedType, array $arguments = array()) { $type = $this->config->getInstanceType($requestedType); $parameters = $this->definitions->getParameters($type); if ($parameters == null) { return new $type(); } if (isset($this->creationStack[$requestedType])) { $lastFound = end($this->creationStack); $this->creationStack = array(); throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa."); } $this->creationStack[$requestedType] = $requestedType; try { $args = $this->_resolveArguments($requestedType, $parameters, $arguments); unset($this->creationStack[$requestedType]); } catch (\Exception $e) { unset($this->creationStack[$requestedType]); throw $e; } switch (count($args)) { case 1: return new $type($args[0]); case 2: return new $type($args[0], $args[1]); case 3: return new $type($args[0], $args[1], $args[2]); case 4: return new $type($args[0], $args[1], $args[2], $args[3]); case 5: return new $type($args[0], $args[1], $args[2], $args[3], $args[4]); case 6: return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); case 7: return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); case 8: return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); default: $reflection = new \ReflectionClass($type); return $reflection->newInstanceArgs($args); } }
/** * Create instance with call time arguments * * @param string $requestedType * @param array $arguments * @return object * @throws \Exception * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function create($requestedType, array $arguments = array()) { $type = $this->config->getInstanceType($requestedType); $parameters = $this->definitions->getParameters($type); if ($parameters == null) { return new $type(); } if (isset($this->creationStack[$requestedType])) { $lastFound = end($this->creationStack); $this->creationStack = array(); throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa."); } $this->creationStack[$requestedType] = $requestedType; try { $args = $this->_resolveArguments($requestedType, $parameters, $arguments); unset($this->creationStack[$requestedType]); } catch (\Exception $e) { unset($this->creationStack[$requestedType]); throw $e; } $reflection = new \ReflectionClass($type); return $reflection->newInstanceArgs($args); }