@param array $paths
@param bool $resolveEnvironment

@return ContainerBuilder
331289
public static function buildDI(array $paths, bool $resolveEnvironment = false): ContainerBuilder
    {
        $container = new ContainerBuilder;

        $loader = static::buildConfigLoader($container, $paths);

        if (class_exists(Configuration::class) && class_exists(RuntimeInstantiator::class)) {
            $container->setProxyInstantiator(new RuntimeInstantiator);
        }

        $extensions = [];
        foreach (static::DI_EXTENSIONS as $extClass) {
            if (!class_exists($extClass)) {
                throw new RuntimeException("Symfony DI Extension not found: \"${extClass}\"");
            }

            $extensions[] = new $extClass;
        }

        foreach ($extensions as $ext) {
            $container->registerExtension($ext);
        }

        $loader->load(static::PRIMARY_CONFIGURATION_FILE);

        foreach ($extensions as $ext) {
            $container->loadFromExtension($ext->getAlias());
        }

        $container->compile($resolveEnvironment);

        return $container;
    }
553614
public function load(array $paths)
    {
        $finder = new Finder();
        $finder->in($paths);
        $finder->name('*Fixture.php');

        foreach ($finder as $file) {
            $declaredClasses = get_declared_classes();
            require_once $file;
            $declaredClassesDiff = array_diff(get_declared_classes(), $declaredClasses);
            $fixtureClass = array_pop($declaredClassesDiff);

            if (!$fixtureClass) {
                throw new \InvalidArgumentException(sprintf(
                    'Could not determine class from included file "%s". Class detection will only work once per request.',
                    $file
                ));
            }

            $refl = new \ReflectionClass($fixtureClass);

            if ($refl->isAbstract()) {
                continue;
            }

            if (false === $refl->isSubclassOf(DocumentFixtureInterface::class)) {
                continue;
            }

            $fixture = new $fixtureClass();

            if ($fixture instanceof ContainerAwareInterface) {
                $fixture->setContainer($this->container);
            }

            $fixtures[] = $fixture;
        }

        usort($fixtures, function(DocumentFixtureInterface $fixture1, DocumentFixtureInterface $fixture2) {
            return $fixture1->getOrder() > $fixture2->getOrder();
        });

        return $fixtures;
    }
945538
public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

        $loader->load('converter.xml');
        $loader->load('event.xml');
        $loader->load('event_listeners.xml');
        $loader->load('command.xml');
        $loader->load('indexer.xml');
        $loader->load('queue.xml');
        $loader->load('solarium.xml');
        $loader->load('task.xml');
        $loader->load('types.xml');
        $loader->load('worker.xml');

        if ($container->getParameter('kernel.debug')) {
            $loader->load('collector.xml');
        }

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $endpoints = [];

        foreach ($config['endpoints'] as $name => $options) {
            $options['key'] = $name;
            $container->setDefinition(
                'solarium.client.endpoint.' . $name,
                new Definition(Endpoint::class, [$options])
            );

            $endpoints[] = new Reference('solarium.client.endpoint.' . $name);
        }

        $container->setDefinition(
            'solarium.client',
            new Definition(
                Client::class,
                [
                    ['endpoint' => $endpoints],
                    new Reference('integrated_solr.event.dispatcher')
                ]
            )
        );

        if ($container->getParameter('kernel.debug')) {
            $container->getDefinition('solarium.client')->addMethodCall(
                'registerPlugin',
                ['solarium.client.logger', new Reference('integrated_solr.solarium.data_collector')]
            );
        }
    }
1317000
public function createInstance(Container $container, ArrayResolver $serviceConfig, $serviceName)
    {
        if (! $this->initialized) {
            $this->initialize($container);
        }

        $sequence = $serviceConfig
            ->resolveStrict($this->activatorKey . '.sequence')
            ->extract();

        for ($i = 0; $i < count($sequence); $i++) {
            $sequence[$i] = array_merge(
                [
                    $sequence[$i]
                ],
                $serviceConfig->resolve($this->activatorKey . '.' . $sequence[$i], [], true)->extract()
            );
        }

        $nextLayerConfig = $serviceConfig->resolve($this->activatorKey . '.handler', null);
        $nextLayer = null;

        if ($nextLayerConfig !== null) {
            $nextLayer = $container->resolve($nextLayerConfig);
        }

        return $this->layerBuilder->build($nextLayer, $sequence);
    }
1359761
public function sharedFilesAndDirs(array $paths = []): self
    {
        $this->sharedDirs = [];
        $this->sharedFiles = [];

        foreach ($paths as $path) {
            $this->validatePathIsRelativeToProject($path, __METHOD__);
            if (is_dir($this->localProjectDir.DIRECTORY_SEPARATOR.$path)) {
                $this->sharedDirs[] = rtrim($path, DIRECTORY_SEPARATOR);
            } else {
                $this->sharedFiles[] = $path;
            }
        }

        return $this;
    }
1226690
private function createContainer(array $files)
    {
        $containerBuilder = new Container();
        $loader = $this->createLoader($containerBuilder);
        foreach ($files as $file) {
            $loader->load($file);
        }

        return $containerBuilder;
    }
22020
protected function getContainerLoader(ContainerInterface $container)
    {
        $locator = new FileLocator($this);
        $resolver = new LoaderResolver([
            new XmlFileLoader($container, $locator),
            new YamlFileLoader($container, $locator),
            new IniFileLoader($container, $locator),
            new PhpFileLoader($container, $locator),
            new DirectoryLoader($container, $locator),
            new ClosureLoader($container),
        ]);

        return new DelegatingLoader($resolver);
    }
172436
protected function bindPathsInContainer(array $otherPaths)
    {
        $defaultPaths = [
            'base'    => $this->basePath,
            'env'     => $this->basePath,
            'app'     => $this->basePath . DIRECTORY_SEPARATOR . 'app',
            'config'  => $this->basePath . DIRECTORY_SEPARATOR . 'config',
            'storage' => $this->basePath . DIRECTORY_SEPARATOR . 'storage',
            'logs'    => $this->basePath . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'logs',
        ];

        $paths = array_merge($defaultPaths, $otherPaths);
        $this->instance('path', rtrim(array_pull($paths, 'app'), '\/'));

        foreach ($paths as $key => $path) {
            $this->instance("path.{$key}", rtrim($path, '\/'));
        }
    }
107919
public static function collectServices(ContainerBuilder $container, \Traversable $namespaces) {
    $service_directories = [];
    foreach ($namespaces as $directory) {
      // $directory will correspond to the src dir, so up one level.
      $service_directories[] = $directory . DIRECTORY_SEPARATOR . '..';
    }
    $loader = new PhpFileLoader($container, new FileLocator($service_directories));
    $loader->load('services.php');
  }
1136405
public function resolveAndCreate($namespace, ContainerInterface $container)
    {
        $class = new \ReflectionClass($namespace);
        $arguments = $this->resolveReflectionArguments($class, $container);

        return $class->newInstanceArgs($arguments);
    }
165729
public function createInstance(Container $container, ArrayResolver $serviceConfig, $serviceName)
    {
        if ($serviceConfig->resolve('lazy', false) == false) {
            return $this->serviceBuilder->buildService($container, $serviceConfig, $serviceName);
        }

        if ($serviceConfig->resolve('class', false) == false) {
            throw new UnbuildableServiceException($serviceName . ' : "class" keyword is mandatory for lazy objects (interface or class name).');
        }

        $serviceBuilder = $this->serviceBuilder;
        $factory = new LazyLoadingValueHolderFactory();
        $invoker = new LazyActivationInvoker($container, $serviceBuilder, $serviceConfig, $serviceName);

        return $factory->createProxy($serviceConfig->resolve('class'), $invoker->createClosure());
    }
1289645
public static function buildContainer(array $definitions)
    {
        /** @var ContainerBuilder $builder */
        $builder = new static();
        $container = Container::getContainer();
        $manager = $builder->_createManager($definitions);
        if (!$container) {
            $container = new Container($manager);
        } else {
            $builder->_merge($container->getDefinitionManager(), $manager);
        }
        return $container;
    }
377186
private function mergeWith(string $namespaceToRegex, array $autoload, array $paths, string $rootProjectDir, bool $loadSrc)
    {
        $regex = "#{$namespaceToRegex}#";
        $resolvedPathToSrc = realpath($rootProjectDir) . '/src';
        foreach ($autoload as $namespace => $namespacePath) {
            if ($loadSrc && (in_array($resolvedPathToSrc, $namespacePath)) || preg_match($regex, $namespace)) {
                foreach ($namespacePath as $pathForNamespace) {
                    $paths[] = $pathForNamespace;
                }
            }
        }

        return $paths;
    }
1189455
public function load(array $configs, ContainerBuilder $container)
    {
        // Load DoctrineRiakBundle/Resources/config/riak.xml
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('riak.xml');

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        if (empty($config['default_connection'])) {
            $keys = array_keys($config['connections']);
            $config['default_connection'] = reset($keys);
        }
        $container->setParameter('doctrine_riak.odm.default_connection', $config['default_connection']);

        if (empty($config['default_document_manager'])) {
            $keys = array_keys($config['document_managers']);
            $config['default_document_manager'] = reset($keys);
        }
        $container->setParameter('doctrine_riak.odm.default_document_manager', $config['default_document_manager']);

        // set some options as parameters and unset them
        $config = $this->overrideParameters($config, $container);

        // load the connections
        $this->loadConnections($config['connections'], $container);

        // load the document managers
        $this->loadDocumentManagers(
            $config['document_managers'],
            $config['default_document_manager'],
            $config['default_database'],
            $container
        );

        if ($config['resolve_target_documents']) {
            $def = $container->findDefinition('doctrine_riak.odm.listeners.resolve_target_document');
            foreach ($config['resolve_target_documents'] as $name => $implementation) {
                $def->addMethodCall('addResolveTargetDocument', array($name, $implementation, array()));
            }
            $def->addTag('doctrine_riak.odm.event_listener', array('event' => 'loadClassMetadata'));
        }

        // BC Aliases for Document Manager
        //$container->setAlias('doctrine.odm.riak.document_manager', new Alias('doctrine_riak.odm.document_manager'));
    }
819238
public function configureFilesystemAdapter(ContainerBuilder $container, array $config)
    {
        // add the default configuration for the local filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.local') && isset($config['filesystem']['local'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.local')
                ->addArgument($config['filesystem']['local']['directory'])
                ->addArgument($config['filesystem']['local']['create'])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.local');
        }

        // add the default configuration for the FTP filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.ftp') && isset($config['filesystem']['ftp'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.ftp')
                ->addArgument($config['filesystem']['ftp']['directory'])
                ->addArgument($config['filesystem']['ftp']['host'])
                ->addArgument([
                    'port' => $config['filesystem']['ftp']['port'],
                    'username' => $config['filesystem']['ftp']['username'],
                    'password' => $config['filesystem']['ftp']['password'],
                    'passive' => $config['filesystem']['ftp']['passive'],
                    'create' => $config['filesystem']['ftp']['create'],
                    'mode' => $config['filesystem']['ftp']['mode'],
                ])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.ftp');
            $container->removeDefinition('sonata.media.filesystem.ftp');
        }

        // add the default configuration for the S3 filesystem
        if ($container->hasDefinition('sonata.media.adapter.filesystem.s3') && isset($config['filesystem']['s3'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.s3')
                ->replaceArgument(0, new Reference('sonata.media.adapter.service.s3'))
                ->replaceArgument(1, $config['filesystem']['s3']['bucket'])
                ->replaceArgument(2, ['create' => $config['filesystem']['s3']['create'], 'region' => $config['filesystem']['s3']['region'], 'directory' => $config['filesystem']['s3']['directory'], 'ACL' => $config['filesystem']['s3']['acl']])
            ;

            $container->getDefinition('sonata.media.metadata.amazon')
                ->addArgument([
                        'acl' => $config['filesystem']['s3']['acl'],
                        'storage' => $config['filesystem']['s3']['storage'],
                        'encryption' => $config['filesystem']['s3']['encryption'],
                        'meta' => $config['filesystem']['s3']['meta'],
                        'cache_control' => $config['filesystem']['s3']['cache_control'],
                ])
            ;

            if (3 === $config['filesystem']['s3']['sdk_version']) {
                $arguments = [
                    'region' => $config['filesystem']['s3']['region'],
                    'version' => $config['filesystem']['s3']['version'],
                ];

                if (isset($config['filesystem']['s3']['secretKey'], $config['filesystem']['s3']['accessKey'])) {
                    $arguments['credentials'] = [
                        'secret' => $config['filesystem']['s3']['secretKey'],
                        'key' => $config['filesystem']['s3']['accessKey'],
                    ];
                }

                $container->getDefinition('sonata.media.adapter.service.s3')
                    ->replaceArgument(0, $arguments)
                ;
            } else {
                $container->getDefinition('sonata.media.adapter.service.s3')
                    ->replaceArgument(0, [
                        'secret' => $config['filesystem']['s3']['secretKey'],
                        'key' => $config['filesystem']['s3']['accessKey'],
                    ])
                ;
            }
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.s3');
            $container->removeDefinition('sonata.media.filesystem.s3');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.replicate') && isset($config['filesystem']['replicate'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.replicate')
                ->replaceArgument(0, new Reference($config['filesystem']['replicate']['master']))
                ->replaceArgument(1, new Reference($config['filesystem']['replicate']['slave']))
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.replicate');
            $container->removeDefinition('sonata.media.filesystem.replicate');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.mogilefs') && isset($config['filesystem']['mogilefs'])) {
            $container->getDefinition('sonata.media.adapter.filesystem.mogilefs')
                ->replaceArgument(0, $config['filesystem']['mogilefs']['domain'])
                ->replaceArgument(1, $config['filesystem']['mogilefs']['hosts'])
            ;
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.mogilefs');
            $container->removeDefinition('sonata.media.filesystem.mogilefs');
        }

        if ($container->hasDefinition('sonata.media.adapter.filesystem.opencloud') &&
            (isset($config['filesystem']['openstack']) || isset($config['filesystem']['rackspace']))) {
            if (isset($config['filesystem']['openstack'])) {
                $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\OpenStack');
                $settings = 'openstack';
            } else {
                $container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\Rackspace');
                $settings = 'rackspace';
            }
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud.connection')
                ->replaceArgument(0, $config['filesystem'][$settings]['url'])
                ->replaceArgument(1, $config['filesystem'][$settings]['secret'])
                ;
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud')
                ->replaceArgument(1, $config['filesystem'][$settings]['containerName'])
                ->replaceArgument(2, $config['filesystem'][$settings]['create_container']);
            $container->getDefinition('sonata.media.adapter.filesystem.opencloud.objectstore')
                ->replaceArgument(1, $config['filesystem'][$settings]['region']);
        } else {
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud');
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.connection');
            $container->removeDefinition('sonata.media.adapter.filesystem.opencloud.objectstore');
            $container->removeDefinition('sonata.media.filesystem.opencloud');
        }
    }
1109513
public static function fromEnvironment(
        EnvironmentInterface $environment,
        string $directory = './config'
    ): ConfigInterface
    {
        $name = $environment->name();
        $projectRoot = $environment->projectRoot();

        // get the config directory
        $directory = (strpos($directory, '/') === 0 ? $directory : $projectRoot . substr($directory, 1));

        $config = [];
        foreach (new \DirectoryIterator($directory) as $file) {
            if ($file->isDot() || $file->getExtension() !== 'php') {
                continue;
            }

            // get the file parts
            $parts = explode('.', $file->getFilename());

            $namespace = $parts[0];
            $fileEnvironment = (count($parts) === 3 ? $parts[1] : EnvironmentInterface::ENV_PRODUCTION);

            if ($fileEnvironment === EnvironmentInterface::ENV_PRODUCTION && ! array_key_exists($namespace, $config)) {
                // use the production configs by default
                $config[$namespace] = new File($file->getPathname());
            }

            if ($fileEnvironment === $name) {
                // create the file resolver so we can resolve the
                $config[$namespace] = new File($file->getPathname());
            }
        }

        // add the environment variables to the config
        $config['environment'] = [
            'name' => $name,
            'projectRoot' => $projectRoot,
        ];

        return new static($config);
    }
880769
public function processParameters(array $parameters, ContainerBuilder $container)
    {
        foreach ($parameters as $parameterKey => &$parameterValue) {
            if (\is_array($parameterValue)) {
                $parameterValue = $this->processParameters($parameterValue, $container);
                continue;
            }

            $resolvedValue = $this->environmentPlaceholderResolver
                ->resolveEnvironmentPlaceholders($parameterValue, $container);

            $replacementValue = $this->replacementFetcher->getReplacedValueForParameter($parameterKey, $resolvedValue);

            if (null !== $replacementValue) {
                $parameterValue = $replacementValue;
            }
        }

        return $parameters;
    }