If PHP-DI's container is wrapped by another container, we can
set this so that PHP-DI will use the wrapper rather than itself for building objects.
public wrapContainer ( Interop\Container\ContainerInterface $otherContainer ) | ||
$otherContainer | Interop\Container\ContainerInterface |
public function setUp() { $loader = (include __DIR__ . '/../vendor/autoload.php'); AnnotationRegistry::registerLoader(array($loader, 'loadClass')); $container = new CompositeContainer(); $builder = new ContainerBuilder(); $builder->useAnnotations(true); $builder->wrapContainer($container); $diContainer = $builder->build(); $container->addContainer($diContainer); $reader = new AnnotationReader(); $routeLoader = new RouteAnnotationClassLoader($reader); $loader = new AnnotationDirectoryLoader(new FileLocator([__DIR__ . '/app']), $routeLoader); $routes = $loader->load(__DIR__ . '/app'); $context = new RequestContext(); $matcher = new UrlMatcher($routes, $context); $hookReader = new HookReader($reader); $executor = new AnnotExecutor($container, $hookReader); $this->app = new App($matcher, $executor); }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * @return Container */ public function createService(ServiceLocatorInterface $serviceLocator) { if ($this->container !== null) { return $this->container; } $builder = new ContainerBuilder(); $config = $this->getConfig($serviceLocator); $configFile = $this->getDefinitionsFilePath($config); $builder->addDefinitions($configFile); $useAnnotations = $this->shouldUseAnnotations($config); $builder->useAnnotations($useAnnotations); $acclimator = new ContainerAcclimator(); $zfContainer = $acclimator->acclimate($serviceLocator); $builder->wrapContainer($zfContainer); /** * @var $cache Cache */ $cache = $this->getCache($serviceLocator, $config); if ($cache) { $builder->setDefinitionCache($cache); } $this->container = $builder->build(); return $this->container; }