public function createInjector($class) { $filename = $this->container->getParameter('jms_di_extra.cache_dir') . '/controller_injectors/' . str_replace('\\', '', $class) . '.php'; $cache = new ConfigCache($filename, $this->container->getParameter('kernel.debug')); if (!$cache->isFresh()) { $metadata = $this->container->get('jms_di_extra.metadata.metadata_factory')->getMetadataForClass($class); if (null === $metadata) { $metadata = new ClassHierarchyMetadata(); $metadata->addClassMetadata(new ClassMetadata($class)); } $this->prepareContainer($cache, $filename, $metadata, $class); } if (!class_exists($class . '__JMSInjector', false)) { require $filename; } return array($class . '__JMSInjector', 'inject'); }
protected function createController($controller) { if (false === ($pos = strpos($controller, '::'))) { $count = substr_count($controller, ':'); if (2 == $count) { // controller in the a:b:c notation then $controller = $this->parser->parse($controller); $pos = strpos($controller, '::'); } elseif (1 == $count) { // controller in the service:method notation list($service, $method) = explode(':', $controller); return array($this->container->get($service), $method); } else { throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller)); } } $class = substr($controller, 0, $pos); $method = substr($controller, $pos + 2); if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); } $filename = $this->container->getParameter('jms_di_extra.cache_dir') . '/controller_injectors/' . str_replace('\\', '', $class) . '.php'; $cache = new ConfigCache($filename, $this->container->getParameter('kernel.debug')); if (!$cache->isFresh()) { $metadata = $this->container->get('jms_di_extra.metadata.metadata_factory')->getMetadataForClass($class); if (null === $metadata) { $metadata = new ClassHierarchyMetadata(); $metadata->addClassMetadata(new ClassMetadata($class)); } $this->prepareContainer($cache, $filename, $metadata); } $inject = (require $filename); $controller = $inject($this->container); if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->container); } return array($controller, $method); }
public function createInjector($class) { $filename = $this->container->getParameter('jms_di_extra.cache_dir') . '/controller_injectors/' . str_replace('\\', '', $class) . '.php'; $cache = new ConfigCache($filename, $this->container->getParameter('kernel.debug')); if (!$cache->isFresh()) { $metadata = $this->container->get('jms_di_extra.metadata.metadata_factory')->getMetadataForClass($class); if (null === $metadata) { $metadata = new ClassHierarchyMetadata(); $metadata->addClassMetadata(new ClassMetadata($class)); } // If the cache warmer tries to warm up a service controller that uses // annotations, we need to bail out as this is handled by the service // container directly. if (null !== $metadata->getOutsideClassMetadata()->id && 0 !== strpos($metadata->getOutsideClassMetadata()->id, '_jms_di_extra.unnamed.service')) { return; } $this->prepareContainer($cache, $filename, $metadata, $class); } if (!class_exists($class . '__JMSInjector', false)) { require $filename; } return array($class . '__JMSInjector', 'inject'); }