/** * @param string $id * @param mixed $service */ public static function set($id, $service) { if (self::$container === null || self::$container->isFrozen()) { self::load(); } self::$container->set($id, $service); $definition = new Definition(get_class($service)); self::$container->setDefinition($id, $definition); }
/** * Runs a command and returns the exit status. * * If an output manager is not provided, a new one will be created. The * new output stream will use a memory stream, and the instance will be * set as the `$output` argument by reference. * * @param InputInterface $input The input manager. * @param OutputInterface &$output The output manager. * * @return integer The exit status. */ public function runCommand(InputInterface $input = null, OutputInterface &$output = null) { if ($this->container instanceof ContainerBuilder && !$this->container->isFrozen()) { $this->container->compile(); } if (null === $output) { $output = new StreamOutput(fopen('php://memory', 'r+')); } return $this->application->run($input, $output); }
public function dump(array $options = array()) { $this->reflectionObject = new ReflectionObject($this); $options = array_merge(array('class' => 'ProjectServiceContainer', 'base_class' => '\\Nucleus\\DependencyInjection\\BaseServiceContainer', 'namespace' => ''), $options); $code = $this->call('startClass', $options['class'], $options['base_class'], $options['namespace']); $code .= $this->addCustom($options); if ($this->container->isFrozen()) { $code .= $this->call('addFrozenConstructor'); } else { $code .= $this->call('addConstructor'); } $code .= $this->call('addServices') . $this->call('addDefaultParametersMethod') . $this->call('endClass') . $this->call('addProxyClasses'); return $code; }
/** * @param $id The service id * @return object */ private function getService($id) { if (!$this->serviceContainer->isFrozen()) { throw new \RuntimeException(sprintf('The Service "%s" can not be accessed. Maybe you forgot to call the "build" method?', $id)); } return $this->serviceContainer->get($id); }
private function getService($name) { if (!$this->serviceContainer->isFrozen()) { throw new \RuntimeException(sprintf('The service with ID "%s" cannot be accessed before the application is built')); } if (!$this->serviceContainer->has($name)) { throw new \RuntimeException(sprintf('The service with ID "%s" is not registered')); } return $this->serviceContainer->get($name); }
/** * {@inheritdoc} */ public function __construct(ContainerBuilder $container) { if (!$container->isFrozen()) { @trigger_error('Dumping an uncompiled ContainerBuilder is deprecated since version 3.3 and will not be supported anymore in 4.0. Compile the container beforehand.', E_USER_DEPRECATED); } parent::__construct($container); $this->inlinedDefinitions = new \SplObjectStorage(); }
/** * Tests that parameter processing works properly. * * @covers ::getParameters * @covers ::prepareParameters * @covers ::escape * @covers ::dumpValue * @covers ::getReferenceCall * * @dataProvider getParametersDataProvider */ public function testGetParameters($parameters, $definition_parameters, $is_frozen) { $this->containerDefinition['parameters'] = $definition_parameters; $this->containerDefinition['frozen'] = $is_frozen; $parameter_bag = new ParameterBag($parameters); $this->containerBuilder->getParameterBag()->willReturn($parameter_bag); $this->containerBuilder->isFrozen()->willReturn($is_frozen); if (isset($parameters['reference'])) { $definition = new Definition('\\stdClass'); $this->containerBuilder->getDefinition('referenced_service')->willReturn($definition); } $this->assertEquals($this->containerDefinition, $this->dumper->getArray(), 'Expected definition matches dump.'); }
public function doRun(InputInterface $input, OutputInterface $output) { if (!$this->container->isFrozen()) { $this->loadConfigurationFile($input); $this->registerExtensions(); $this->container->compile(); $eventDispatcher = $this->container->get('event_dispatcher'); if ($eventDispatcher instanceof ContainerAwareEventDispatcher) { $this->setDispatcher($eventDispatcher); } $this->registerCommands(); if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->run(); return 0; } } if (true === $input->hasParameterOption(array('--init'))) { $this->add($this->container->get('phpzone.phpzone.console.command.init')); $input = new ArrayInput(array('command' => 'phpzone:init')); } return parent::doRun($input, $output); }
/** * Returns ContainerBuilder by including the default file 'containerBuilder.php' from settings directory. * * @throws \RuntimeException */ protected function getContainer() { if ($this->innerContainer instanceof ContainerInterface) { // Do nothing } elseif (!is_readable($this->innerContainer)) { throw new RuntimeException(sprintf("Unable to read file %s\n", $this->innerContainer)); } else { // 'containerBuilder.php' file expects $installDir variable to be set by caller $installDir = $this->installDir; $this->innerContainer = (require_once $this->innerContainer); } // Compile container if necessary if ($this->innerContainer instanceof ContainerBuilder && !$this->innerContainer->isFrozen()) { $this->innerContainer->compile(); } }
public function isFrozen() { return $this->delegate->isFrozen(); }