/** * {@inheritdoc} */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { if (parent::has($id)) { return parent::get($id, $invalidBehavior); } return $this->injector->getInstance($id); }
/** * {@inheritdoc} */ public function get(AbstractUri $uri) { if (isset($this->patterns[$uri->method])) { foreach ($this->patterns[$uri->method] as $regex => $resource) { if (!preg_match(sprintf('!^%s\\z!', $regex), $uri->path)) { continue; } $class = sprintf('%s%s\\Resource\\%s\\%s', $this->namespace, $this->path, ucfirst($uri->scheme), $resource); $instance = $this->injector->getInstance($class); return $instance; } } $class = $this->namespace . $this->path . '\\Resource' . str_replace(' ', '\\', ucwords(str_replace('/', ' ', ' ' . $uri->scheme . $uri->path))); $instance = $this->injector->getInstance($class); return $instance; }
/** * Compile fluent interface * * @param string $class * * @return self */ public function compile($class) { $this->injector->getInstance($class); $this->logger->setMapRef($class); $this->cache->save($this->cacheKey, $this); return $this; }
/** * @param \ArrayObject $bindings * @param string $class * * @return object */ private function getToProviderBound(\ArrayObject $bindings, $class) { $provider = $bindings[$class]['*']['to'][1]; $in = isset($bindings[$class]['*']['in']) ? $bindings[$class]['*']['in'] : null; if ($in !== Scope::SINGLETON) { $instance = $this->injector->getInstance($provider)->get(); return $instance; } if ($this->container->has($class)) { return $this->container->get($class); } $instance = $this->injector->getInstance($provider)->get(); $this->container->set($class, $instance); return $instance; }
/** * @param \ReflectionParameter $parameter * @param array $params * @param string $index * @param string $class * * @return array * @throws Exception\NotBound */ private function getNoBoundConstructorParam(\ReflectionParameter $parameter, array $params, $index, $class) { // has constructor default value ? if ($parameter->isDefaultValueAvailable() === true) { return $params; } // is typehint class ? $classRef = $parameter->getClass(); if ($classRef && !$classRef->isInterface()) { $params[$index] = $this->injector->getInstance($classRef->name); return $params; } $msg = is_null($classRef) ? "Valid interface is not found. (array ?)" : "Interface [{$classRef->name}] is not bound."; $msg .= " Injection requested at argument #{$index} \${$parameter->name} in {$class} constructor."; throw new Exception\NotBound($msg); }
private function getView(\Exception $e) { // exception screen in develop if (isset($this->injector)) { /** @noinspection PhpUnusedLocalVariableInspection */ $dependencyBindings = (string) $this->injector; /** @noinspection PhpUnusedLocalVariableInspection */ $modules = $this->injector->getModule()->modules; } elseif (isset($e->module)) { /** @noinspection PhpUnusedLocalVariableInspection */ $dependencyBindings = (string) $e->module; /** @noinspection PhpUnusedLocalVariableInspection */ $modules = $e->module->modules; } else { /** @noinspection PhpUnusedLocalVariableInspection */ $dependencyBindings = 'n/a'; /** @noinspection PhpUnusedLocalVariableInspection */ $modules = 'n/a'; } /** @noinspection PhpIncludeInspection */ return include $this->viewTemplate; }
/** * @return \Twig_Environment */ public function get() { $class = $this->injector->getInstance(FormTokenParser::class); $this->twig->addTokenParser($class); return $this->twig; }