phpbb\di\container_builder::get_container PHP Метод

get_container() публичный Метод

Build and return a new Container respecting the current configuration
public get_container ( ) : phpbb_cache_container | ContainerBuilder
Результат phpbb_cache_container | Symfony\Component\DependencyInjection\ContainerBuilder
    public function get_container()
    {
        $container_filename = $this->get_container_filename();
        $config_cache = new ConfigCache($container_filename, defined('DEBUG'));
        if ($this->use_cache && $config_cache->isFresh()) {
            require $config_cache->getPath();
            $this->container = new \phpbb_cache_container();
        } else {
            $this->container_extensions = array(new extension\core($this->get_config_path()));
            if ($this->use_extensions) {
                $this->load_extensions();
            }
            // Inject the config
            if ($this->config_php_file) {
                $this->container_extensions[] = new extension\config($this->config_php_file);
            }
            $this->container = $this->create_container($this->container_extensions);
            // Easy collections through tags
            $this->container->addCompilerPass(new pass\collection_pass());
            // Event listeners "phpBB style"
            $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener'));
            // Event listeners "Symfony style"
            $this->container->addCompilerPass(new RegisterListenersPass('dispatcher'));
            $filesystem = new filesystem();
            $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path())));
            $loader->load($this->container->getParameter('core.environment') . '/config.yml');
            $this->inject_custom_parameters();
            if ($this->compile_container) {
                $this->container->compile();
                if ($this->use_cache) {
                    $this->dump_container($config_cache);
                }
            }
        }
        if ($this->compile_container && $this->config_php_file) {
            $this->container->set('config.php', $this->config_php_file);
        }
        return $this->container;
    }

Usage Example

Пример #1
0
 public function test_with_custom_parameters()
 {
     $this->builder->with_custom_parameters(array('my_parameter' => true));
     $container = $this->builder->get_container();
     $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\ContainerBuilder', $container);
     $this->assertTrue($container->hasParameter('my_parameter'));
 }