Build PHP-DI container.

@param Configuration|null $configuration

@throws \RuntimeException

@return DIContainer
515198
public static function build(Configuration $configuration = null): DIContainer
    {
        if ($configuration === null) {
            $configuration = new Configuration();
        }

        $defaultDefinitions = \array_merge(
            require __DIR__ . '/definitions.php',
            [Configuration::class => $configuration]
        );
        $customDefinitions = self::parseDefinitions($configuration->getDefinitions());

        return self::getContainerBuilder($configuration)
            ->addDefinitions($defaultDefinitions, ...$customDefinitions)
            ->build();
    }
238388
protected static function loadAdditionalConfiguration(Configuration $configuration)
    {
        if (null !== ($pattern = $configuration->getAdditionalConfigurationDirectory())) {
            $iterator = new \DirectoryIterator(sprintf($pattern, dirname($configuration->getIdentity())));
            foreach ($iterator as $file) {
                $configuration->merge(Configuration::createFromFile($file->getRealPath()));
            }
        }
    }
182710
public function build(Configuration $configuration, array $data): Definition
    {
        foreach (['name', 'source', 'target'] as $key) {
            if (!array_key_exists($key, $data)) {
                throw new \InvalidArgumentException('Missing key "' . $key . '"');
            }
        }
        $overrides = $this->getDictionaryOverrides($data);
        $name      = $data['name'];
        $source    = $this->makeDictionary($configuration, $data['source'], $overrides, $name . '.source');
        $target    = $this->makeDictionary($configuration, $data['target'], $overrides, $name . '.target');
        unset($data['name'], $data['source'], $data['target']);

        return new CopyJobDefinition($name, $source, $target, $data);
    }
465879
public function cachedContainer(): ContainerInterface
    {
        /**
         * @noinspection   PhpIncludeInspection Include generated file
         * @psalm-suppress UnresolvableInclude Include generated file
         */
        include_once $this->getContainerClassPath();

        /** @psalm-var class-string<\Symfony\Component\DependencyInjection\Container> $containerClassName */
        $containerClassName = $this->getContainerClassName();

        /** @var ContainerInterface $container */
        $container = new $containerClassName();

        return $container;
    }
755029
protected function redisFactory(array $configuration): Redis
	{
		return (new Redis($this->container->get(RedisConnectionManager::class)->connection($configuration['configuration']), $this->classWhitelist))->setPrefix($configuration['prefix'] ?? '');
	}
530469
public static function create($configuration)
    {
        $currentConfiguration = is_array($configuration) ?
                array_merge(self::$defaultConfiguration, $configuration)
                : self::$defaultConfiguration;
        $class = self::className($currentConfiguration);
        return new $class($currentConfiguration["params"]);
    }
650994
public function integrationModulesEdit(array $configuration)
    {
        if (!count($configuration) || empty($configuration['code'])) {
            throw new \InvalidArgumentException(
                'Parameter `configuration` must contains a data & configuration `code` must be set'
            );
        }

        /* @noinspection PhpUndefinedMethodInspection */
        return $this->client->makeRequest(
            sprintf('/integration-modules/%s/edit', $configuration['code']),
            "POST",
            ['integrationModule' => json_encode($configuration)]
        );
    }
824423
public function provideServiceLayerDependencies(Container $container): Container
    {
        $container = parent::provideServiceLayerDependencies($container);

        $container = $this->addConditionalAvailabilitySkuSearchQueryPlugin($container);
        $container = $this->addConditionalAvailabilitySkuSearchQueryExpanderPlugins($container);
        $container = $this->addConditionalAvailabilitySkuSearchQueryFormatterPlugins($container);
        $container = $this->addConditionalAvailabilityPingSearchQueryPlugin($container);
        $container = $this->addConditionalAvailabilityPingSearchQueryExpanderPlugins($container);
        $container = $this->addConditionalAvailabilityPingSearchQueryFormatterPlugins($container);

        return $container;
    }
369844
public function buildContainer(\Asgard\Container\ContainerInterface $container) {
		#Config
		$container->setParentClass('config', 'Asgard\Config\ConfigInterface');

		#Cache
		$container->setParentClass('systemcache', 'Asgard\Cache\CacheInterface');
		$container->register('systemcache', function($container) {
			if($cache = $container['kernel']->getCache())
				return new \Asgard\Cache\Cache($cache);
			else
				return new \Asgard\Cache\Cache;#null cache
		});

		#Db
		$container->setParentClass('schema', 'Asgard\Db\SchemaInterface');
		$container->register('schema', function($container) {
			return new \Asgard\Db\Schema($container['db']);
		});
		$container->setParentClass('db', 'Asgard\Db\DBInterface');
		$container->register('db', function($container) {
			return new \Asgard\Db\DB($container['config']['database']);
		});

		#Email
		$container->setParentClass('email', 'Asgard\Email\DriverInterface');
		$container->register('email', function($container) {
			$emailDriver = '\\'.trim($container['config']['email.driver'], '\\');
			$email = new $emailDriver();
			$email->transport($container['config']['email']);
			return $email;
		});

		#Entity
		$container->setParentClass('entityManager', 'Asgard\Entity\EntityManagerInterface');
		$container->register('entityManager', function($container) {
			$entityManager = new \Asgard\Entity\EntityManager($container, $container['systemcache']);
			$entityManager->setHookManager($container['hooks']);
			$entityManager->setDefaultLocale($container['config']['locale']);
			$entityManager->setValidatorFactory($container['validator_factory']);
			return $entityManager;
		});
		$container->register('Asgard.Entity.PropertyType.file', function($container, $params) {
			$prop = new \Asgard\Entity\Property\FileProperty($params);
			$prop->setWebDir($container['config']['webdir']);
			if($container['httpKernel']->getRequest())
				$prop->setUrl($container['httpKernel']->getRequest()->url);
			return $prop;
		});

		#FORMInterface
		$container->setParentClass('WidgetManager', 'Asgard\Form\WidgetManagerInterface');
		$container->register('WidgetManager', function() { return new \Asgard\Form\WidgetManager; });
		$container->setParentClass('EntityFieldSolver', 'Asgard\EntityForm\EntityFieldSolverInterface');
		$container->register('EntityFieldSolver', function() { return new \Asgard\Entityform\EntityFieldSolver; });
		$container->setParentClass('entityForm', 'Asgard\EntityForm\EntityFormInterface');
		$container->register('entityForm', function($container, $entity, $params=[], $request=null) {
			if($request === null)
				$request = $container['httpKernel']->getRequest();
			$EntityFieldSolver = clone $container['EntityFieldSolver'];
			$form = new \Asgard\Entityform\EntityForm($entity, $params, $request, $EntityFieldSolver, $container['dataMapper']);
			$form->setWidgetManager(clone $container['WidgetManager']);
			$form->setTranslator($container['translator']);
			$form->setValidatorFactory($container['validator_factory']);
			return $form;
		});
		$container->setParentClass('form', 'Asgard\Form\FormInterface');
		$container->register('form', function($container, $name=null, $params=[], $request=null, $fields=[]) {
			if($request === null)
				$request = $container['httpKernel']->getRequest();
			$form = new \Asgard\Form\Form($name, $params, $request, $fields);
			$form->setWidgetManager(clone $container['WidgetManager']);
			$form->setTranslator($container['translator']);
			$form->setValidatorFactory($container['validator_factory']);
			return $form;
		});

		#Hook
		$container->setParentClass('hooks', 'Asgard\Hook\HookManagerInterface');
		$container->register('hooks', function($container) { return new \Asgard\Hook\HookManager($container); } );
		$container->setParentClass('hooksAnnotationReader', 'Asgard\Hook\AnnotationReader');
		$container->register('hooksAnnotationReader', function($container) { return $container['kernel']->getHooksAnnotationReader(); } );

		#Http
		$container->setParentClass('httpKernel', 'Asgard\Http\HttpKernelInterface');
		$container->register('httpKernel', function($container) {
			$httpKernel = new \Asgard\Http\HttpKernel($container);
			$httpKernel->setDebug($container['config']['debug']);
			if($container->has('flash'))
				$httpKernel->setFlash($container['flash']);
			if($container->has('templateEngine_factory'))
				$httpKernel->setTemplateEngineFactory($container['templateEngine_factory']);
			$httpKernel->setHookManager($container['hooks']);
			if($container->has('errorHandler'))
				$httpKernel->setErrorHandler($container['errorHandler']);
			$httpKernel->setTranslator($container['translator']);
			$httpKernel->setResolver($container['resolver']);
			$container['resolver']->setHttpKernel($httpKernel);
			return $httpKernel;
		});
		$container->setParentClass('resolver', 'Asgard\Http\ResolverInterface');
		$container->register('resolver', function($container) {
			return new \Asgard\Http\Resolver($container['systemcache']);
		});
		$container->setParentClass('browser', 'Asgard\Http\Browser\BrowserInterface');
		$container->register('browser', function($container) {
			$browser = new \Asgard\Http\Browser\Browser($container['httpKernel'], $container);
			if(getenv('catch') !== false)
				$browser->catchException((bool)getenv('catch'));
			return $browser;
		});
		$container->setParentClass('cookieManager', 'Asgard\Common\BagInterface');
		$container->register('cookies', function() {
			if(php_sapi_name() === 'cli')
				return new \Asgard\Common\Bag;
			else
				return new \Asgard\Http\CookieManager;
		});
		$container->setParentClass('sessionManager', 'Asgard\Common\BagInterface');
		$container->register('session', function() {
			if(php_sapi_name() === 'cli')
				return new \Asgard\Common\Bag;
			else
				return new \Asgard\Common\Session;
		});
		$container->setParentClass('html', 'Asgard\Http\Utils\HTMLInterface');
		$container->register('html', function($container) {
			return new \Asgard\Http\Utils\HTML($container['httpKernel']);
		});
		$container->setParentClass('flash', 'Asgard\Http\Utils\Flash');
		$container->register('flash', function($container) {
			return new \Asgard\Http\Utils\Flash($container);
		});
		$container->setParentClass('url', 'Asgard\Http\URLInterface');
		$container->register('url', function($container) {
			return $container['httpKernel']->getRequest()->url;
		});
		$container->setParentClass('controllersAnnotationReader', 'Asgard\Http\AnnotationReader');
		$container->register('controllersAnnotationReader', function($container) { return $container['kernel']->getControllersAnnotationReader(); } );

		#Migration
		$container->setParentClass('MigrationManager', 'Asgard\Migration\MigrationManagerInterface');
		$container->register('MigrationManager', function($container) {
			return new \Asgard\Migration\MigrationManager($container['kernel']['root'].'/migrations/', $container['db'], $container['schema'], $container);
		});

		#Common
		$container->setParentClass('intl', 'Asgard\Common\Intl');
		$container->register('intl', function($container) {
			return \Asgard\Common\Intl::singleton()->setTranslator($container['translator']);
		});
		$container->setParentClass('paginator', 'Asgard\Common\PaginatorInterface');
		$container->register('paginator', function($container, $count, $page, $per_page) {
			return new \Asgard\Common\Paginator($count, $page, $per_page, $container['httpKernel']->getRequest());
		});
		$container->setParentClass('paginator_factory', 'Asgard\Common\PaginatorFactoryInterface');
		$container->register('paginator_factory', function($container) {
			return new \Asgard\Common\PaginatorFactory($container['httpKernel']);
		});

		#Validation
		$container->setParentClass('validator', 'Asgard\Validation\ValidatorInterface');
		$container->register('validator', function($container) {
			$validator = new \Asgard\Validation\Validator;
			$validator->setRegistry($container['rulesregistry']);
			$validator->setTranslator($container['translator']);
			return $validator;
		});
		$container->setParentClass('validator_factory', 'Asgard\Validation\ValidatorFactoryInterface');
		$container->register('validator_factory', function($container) {
			return new \Asgard\Validation\ValidatorFactory($container['rulesregistry'], $container['translator']);
		});
		$container->setParentClass('rulesregistry', 'Asgard\Validation\RulesRegistryInterface');
		$container->register('rulesregistry', function() { return new \Asgard\Validation\RulesRegistry; } );

		#ORMInterface
		$container->setParentClass('orm', 'Asgard\Orm\ORMInterface');
		$container->register('orm', function($container, $entityClass, $dataMapper, $locale, $prefix) {
			return new \Asgard\Orm\ORM($entityClass, $dataMapper, $locale, $prefix, $container['paginator_factory']);
		});
		$container->register('orm_factory', function($container) {
			return new \Asgard\Orm\ORMFactory($container['paginator_factory']);
		});
		$container->setParentClass('collectionOrmInterface', 'Asgard\Orm\CollectionORMInterface');
		$container->register('collectionOrm', function($container, $entityClass, $name, $dataMapper, $locale, $prefix) {
			return new \Asgard\Orm\CollectionORM($entityClass, $name, $dataMapper, $locale, $prefix, $container['paginator_factory']);
		});
		$container->register('collectionOrm_factory', function($container) {
			return new \Asgard\Orm\CollectionORMFactory($container['paginator_factory']);
		});
		$container->setParentClass('proxygenerator', 'Asgard\Orm\Proxy\ProxyGenerator');
		$container->register('proxygenerator', function() {
			return new \Asgard\Orm\Proxy\ProxyGenerator;
		});
		$container->setParentClass('datamapper', 'Asgard\Orm\DataMapperInterface');
		$container->register('datamapper', function($container) {
			$dm = new \Asgard\Orm\DataMapper(
				$container['db'],
				$container['entityManager'],
				$container['config']['locale'],
				$container['config']['database.prefix'],
				$container['orm_factory'],
				$container['collectionOrm_factory']
			);
			$dm->setProxyGenerator($container['proxygenerator']);
			return $dm;
		});
		$container->setParentClass('ormMigrations', 'Asgard\Orm\ORMMigrations');
		$container->register('ormMigrations', function($container) {
			return new \Asgard\Orm\ORMMigrations(
				$container['dataMapper'],
				$container['MigrationManager']
			);
		});

		$container->register('translator', function($container) {
			$locale = $container['config']['locale'];
			$translator = new \Symfony\Component\Translation\Translator($locale, new \Symfony\Component\Translation\MessageSelector());
			$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
			foreach(glob($this->getPath().'/../Validation/translations/'.$translator->getLocale().'/*') as $file)
				$translator->addResource('yaml', $file, $translator->getLocale());
			foreach(glob($this->getPath().'/../Form/translations/'.$translator->getLocale().'/*') as $file)
				$translator->addResource('yaml', $file, $translator->getLocale());
			return $translator;
		});
		$container->register('translation', function($container) {
			return new \Asgard\Translation\Translation($container['translator']);
		});

		#test builder
		$container->setParentClass('testBuilder', 'Asgard\Tester\TestBuilderInterface');
		$container->register('testBuilder', function($container) {
			return new \Asgard\Tester\TestBuilder($container['kernel']['root'].'/tests');
		});

		#generator
		$container->setParentClass('generator', 'Asgard\Generator\GeneratorEngineInterface');
		$container->register('generator', function($container) {
			$generatorEngine = new \Asgard\Generator\GeneratorEngine($container, $container['kernel']['root'].'/app');
			$generatorEngine->addGenerator(new \Asgard\Generator\DefaultGenerator);
			$generatorEngine->addGenerator(new \Asgard\Tester\TestsGenerator($container['testBuilder'], $container['resolver'], $container['controllersAnnotationReader']));
			return $generatorEngine;
		});
	}
258827
public function create(Configuration $configuration): JobFactory
    {
        return new JobFactory($this->dictionaryBuilders, $this->jobBuilders, $configuration, $this->logger);
    }
957343
public function configure(array $config, ConfigurationInterface $configuration, ContainerBuilder $container)
    {
        $processor = new Processor();
        $config    = $processor->processConfiguration($configuration, $config);

        $loader = new XmlFileLoader($container, new FileLocator($this->getConfigurationDirectory()));

		foreach(WallPosterBundle::getAvailableProviders() as $service)
		{
			if(isset($config[$service]))
			{
				$this->mapParameters($service, $config[$service], $container);
				$this->loadConfigurationFile($service,$loader);
			}
		}

        return array($config, $loader);
    }
846195
public function install(Configuration $configuration)
    {
        // Register the Installation application
        \JLoader::registerPrefix('Installation', JPATH_INSTALLATION);

        $app = new InstallationApplicationWeb();
        Factory::pushApplication($app);

        $this->joomla->initialize();

        // Get the database model.
        $db = new DatabaseModel();

        $dboptions = [
            'db_type'   => $this->config->get('dbtype'),
            'db_host'   => $this->config->get('host'),
            'db_user'   => $this->config->get('user'),
            'db_pass'   => $this->config->get('password'),
            'db_name'   => $this->config->get('db'),
            'db_prefix' => $this->config->get('dbprefix'),
            'db_select' => true
        ];

        $driver = $db->initialise($dboptions);

        if ($driver instanceof AbstractDoctrineDriver) {
            $dboptions['db_name'] = $driver->getDatabaseName();
        }

        $pwd = getcwd();
        chdir(JPATH_INSTALLATION);

        $db->createTables(array_merge($dboptions, [
            'language'   => 'en-GB',
            'db_created' => true,
            'db_type'    => $driver->name
        ]));

        $configration = new ConfigurationModel();

        $configration->setup(array_merge($dboptions, [
            'site_offline'   => 0,
            'site_name'      => '',
            'site_metadesc'  => '',
            'helpurl'        => '',
            'admin_user'     => $configuration->getUsername(),
            'admin_email'    => $configuration->getEmail(),
            'admin_password' => $configuration->getPassword()
        ]));

        chdir($pwd);

        Factory::popApplication();
    }
1234141
private function _createContainer(Config $config = null)
	{
		$container = new Container();

		if ( isset($config) ) {
			$container['config'] = $config;
		}

		return $container;
	}
1304959
protected function buildContainer()
    {
        $container = $this->getContainerBuilder();
        $container->addObjectResource($this);
        $this->prepareContainer($container);
        if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
            $container->merge($cont);
        }
        return $container;
    }
607371
public function buildDictionary(Configuration $configuration, array $data): Definition
    {
        try {
            $builder = $this->dictionaryBuilders->get($data['type']);
        } catch (ServiceNotFoundException $exception) {
            throw new \RuntimeException('Unknown dictionary type "' . $data['type'] . '"', 0, $exception);
        }
        /** @var DefinitionBuilderInterface $builder */
        return $builder->build($configuration, $data);
    }
929126
final public static function setConfig(ConfigInterface $configuration) {
        $previous = self::$defaultConfig;
        self::$defaultConfig = $configuration;
        if (self::$defaultDi)
            self::$defaultDi->set('config', $configuration);
        return $previous;
    }
1361271
public function buildContainer(
        ExtensionInterface $extension = null,
        array $config = [],
        array $parameters = [],
        array $compilerPasses = []
    ) {
        $container = new ContainerBuilder();
        if ($extension !== null) {
            $extension->setConfigDirectories($this->configDirectories);
            $extension->buildContainer($container, $config);
        }
        foreach ($parameters as $key => $value) {
            $container->setParameter($key, $value);
        }
        foreach ($compilerPasses as $compilerPass) {
            $container->addCompilerPass($compilerPass);
        }
        $container->compile();

        return $container;
    }