/** * Bootstrap the container. * * @return self */ private function bootstrapContainer() { $this->container = new ContainerBuilder(); $yaml = new Definition('Modrepo\\Configuration\\Yaml', [$this->configPath]); $this->container->setDefinition('config', $yaml); foreach ($this->getInitialServices() as $service => $class) { $this->container->register($service, $class); } return $this; }
/** * Build dependency injection container * * @throws \phpbb\install\exception\cannot_build_container_exception When container cannot be built */ protected function build_container() { // If the container has been already built just return. // Although this should never happen if ($this->container instanceof \Symfony\Component\DependencyInjection\ContainerInterface) { return; } // Check whether container can be built // We need config.php for that so let's check if it has been set up yet if (!filesize($this->phpbb_root_path . 'config.' . $this->php_ext)) { throw new cannot_build_container_exception(); } $phpbb_config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext); $phpbb_container_builder = new \phpbb\di\container_builder($this->phpbb_root_path, $this->php_ext); // For BC with functions that we need during install global $phpbb_container, $table_prefix; $disable_super_globals = $this->request->super_globals_disabled(); // This is needed because container_builder::get_env_parameters() uses $_SERVER if ($disable_super_globals) { $this->request->enable_super_globals(); } $other_config_path = $this->phpbb_root_path . 'install/update/new/config'; $config_path = is_dir($other_config_path) ? $other_config_path : $this->phpbb_root_path . 'config'; $this->container = $phpbb_container_builder->with_environment('production')->with_config($phpbb_config_php_file)->with_config_path($config_path)->without_cache()->without_compiled_container()->get_container(); // Setting request is required for the compatibility globals as those are generated from // this container $this->container->register('request')->setSynthetic(true); $this->container->set('request', $this->request); $this->container->register('language')->setSynthetic(true); $this->container->set('language', $this->language); // Replace cache service, as config gets cached, and we don't want that when we are installing if (!is_dir($other_config_path)) { $this->container->register('cache.driver')->setSynthetic(true); $this->container->set('cache.driver', new dummy()); } $this->container->compile(); $phpbb_container = $this->container; $table_prefix = $phpbb_config_php_file->get('table_prefix'); // Restore super globals to previous state if ($disable_super_globals) { $this->request->disable_super_globals(); } // Get compatibilty globals and constants $this->update_helper->include_file('includes/compatibility_globals.' . $this->php_ext); $this->update_helper->include_file('includes/constants.' . $this->php_ext); }
/** * Load a dbclient configuration as a service in the container. A client can use multiple servers * @param ContainerInterface $container The container * @param string $alias Alias of the client * @param array $config Base config of the client * @param array $servers List of available servers as describe in the config file * @param string $type db or multi * * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @return void */ protected function loadClient($container, $alias, array $config, array $servers, $type = 'cache') { $configuration = array('timeout' => $config['timeout'], 'server_config' => array()); if (array_key_exists('readwritetimeout', $config)) { $configuration['read_write_timeout'] = $config['readwritetimeout']; } if (array_key_exists('reconnect', $config)) { $configuration['reconnect'] = $config['reconnect']; } if ('cache' === $type) { // check namespace if (!isset($config['namespace'])) { throw new InvalidConfigurationException("namespace Parameter for M6Redis cache server is required"); } $configuration['namespace'] = $config['namespace']; $configuration['compress'] = $config['compress']; } $configuration['server_config'] = $this->getServers($servers, $config['servers'], $alias); if (count($configuration['server_config']) === 0) { throw new InvalidConfigurationException(sprintf("no server found for M6Redis client %s", $alias)); } switch ($type) { case 'cache': $redisCacheId = sprintf('m6_redis.cache.%s', $alias); $container->register($redisCacheId, 'M6Web\\Component\\Redis\\Cache')->addArgument($configuration); $serviceId = $alias == 'default' ? 'm6_redis' : 'm6_redis.' . $alias; $definition = new Definition($config['class']); $definition->addArgument(new Reference($redisCacheId)); break; case 'db': $serviceId = $alias == 'default' ? 'm6_dbredis' : 'm6_dbredis.' . $alias; $definition = new Definition('M6Web\\Component\\Redis\\DB'); $definition->addArgument($configuration); break; case 'multi': $serviceId = $alias == 'default' ? 'm6_multiredis' : 'm6_multiredis.' . $alias; $definition = new Definition('M6Web\\Component\\Redis\\Multi'); $definition->addArgument($configuration); break; default: throw new InvalidConfigurationException("Invalid client type"); } $definition->setScope(ContainerInterface::SCOPE_CONTAINER); $definition->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher'), 'M6Web\\Bundle\\RedisBundle\\EventDispatcher\\RedisEvent')); $container->setDefinition($serviceId, $definition); }