Ready the application container.

@param  ContainerBuilder $builder
@return void
552252
protected function configureContainer(ContainerBuilder $builder)
    {
        $this->default_definitions = array_merge($this->default_definitions, [
            "XhrMiddleware" => function(ContainerInterface $c)
            {
                return new XhrMiddleware($c);
            }
        ]);

        if (is_api_request())
        {
            $this->default_definitions = array_merge($this->default_definitions, [
                # override not found handler
                'notFoundHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response)
                    {
                        return $response->withStatus(404)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "It seems you are in the wrong place.",
                                    'status_code' => 404
                                ]));
                    };
                },

                # override not allowed handler
                'notAllowedHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $methods)
                    {
                        return $response->withStatus(405)
                                ->withHeader('Allow', implode(', ', $methods))
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "It seems you are in the wrong place.",
                                    'status_code' => 405
                                ]));
                    };
                },

                # override error handler
                'errorHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $exception)
                    {
                        \Log::debug(print_r($exception->getMessage(), true));

                        return $response->withStatus(500)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "Looks like something went wrong!. We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.",
                                    'status_code' => 500
                                ]));
                    };
                },

                # override php error handler
                'phpErrorHandler' => function(ContainerInterface $view)
                {
                    return function($request, $response, $exception)
                    {
                        \Log::debug(print_r($exception->getMessage(), true));

                        return $response->withStatus(500)
                                ->withHeader('Content-Type', "text/json")
                                ->write(json_encode([
                                    'success' => false,
                                    'message' => "Looks like something went wrong!. We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.",
                                    'status_code' => 500
                                ]));
                    };
                }
            ]);
        }
        else
        {
            $this->default_definitions = array_merge($this->default_definitions, [
                # override not found handler
                'notFoundHandler' => function(Twig $view)
                {
                    return new NotFoundHandler($view);
                },

                # override not allowed handler
                'notAllowedHandler' => function(Twig $view)
                {
                    return new NotAllowedHandler($view);
                },

                # override error handler
                'errorHandler' => function(Twig $view)
                {
                    return new ErrorHandler($view);
                },

                # override php error handler
                'phpErrorHandler' => function(Twig $view)
                {
                    return new PhpErrorHandler($view);
                },

                # tracy debug bar need this
                'twig_profile' => function()
                {
                    return new \Twig_Profiler_Profile;
                },

                # twig view
                'view' => function(ContainerInterface $c)
                {
                    $view_path = resources_path(config('app.use_dist') ? 'dist-views' : "views");

                    $view = new Twig($view_path, ['cache' => config('twig-view.cache')]);

                    $view->addExtension(new TwigExtension($c->get('router'), $c->get('request')->getUri()));

                    if (is_dev())
                    {
                        $view->addExtension(new \Twig_Extension_Profiler($c->get('twig_profile')));
                        $view->addExtension(new \Twig_Extension_Debug());
                    }

                    $system_functions = ["config", "in_array", "img", "str_title"];
                    $custom_functions = include_once system_path("registered-twig-functions.php");
                    $functions = array_merge($system_functions, $custom_functions);

                    foreach ($functions as $function) {
                        $view->getEnvironment()->addFunction(new \Twig_SimpleFunction($function, $function));
                    }

                    $view->getEnvironment()->addFunction(new \Twig_SimpleFunction('ClassStaticMethod', function() {
                        $args = func_get_args();

                        $class = array_shift($args);
                        $method = array_shift($args);

                        return $class::$method($args);
                    }));

                    # Make 'flash' global
                    $view->getEnvironment()->addGlobal('flash', $c->get('flash'));

                    return $view;
                },

                # slim/flash
                'flash' => function()
                {
                    return new Messages;
                },

                # slim/csrf
                'csrf' => function(Twig $view)
                {
                    $guard = new Guard;
                    $guard->setFailureCallable(function($request, $response, $next) use($view) {
                        if (is_prod())
                        {
                            return $view->render(
                                $response->withStatus(403)->withHeader('Content-Type', "text/html"),
                                config('twig-view.error_pages.403')
                            );
                        }

                        return $response->withStatus(403)
                                        ->withHeader('Content-Type', "text/html")
                                        ->write("Failed CSRF check!");
                    });
                    return $guard;
                },

                # Service injection
                Twig::class => function(ContainerInterface $c)
                {
                    return $c->get('view');
                }
            ]);
        }

        // Use default error handler on development mode
        if (is_dev())
        {
            unset($this->default_definitions['errorHandler']);
            unset($this->default_definitions['phpErrorHandler']);
        }

        # push default controllers in default definitions
        $this->pushControllersInDefinition("\\", app_path("Controllers"), $this->default_definitions);

        if (file_exists(app_path("Middlewares")))
        {
            # push default middlewares in default definitions
            $this->pushMiddlewaresInDefinition("\\", app_path("Middlewares"), $this->default_definitions);
        }

        if (file_exists(app_path("Requests")))
        {
            # push default requests in default definitions
            $this->pushRequestsInDefinition("\\", app_path("Requests"), $this->default_definitions);
        }

        $config_app = config('app');

        if (array_key_exists('modules', $config_app))
        {
            $modules = $config_app['modules'];

            foreach ($modules as $module) {
                if (!empty($module))
                {
                    $module = trim($module, "/");
                    $alias_namespace = str_replace("/", "\\", $module) . "App\\";

                    // controllers
                    if (file_exists($directory = app_path("{$module}/Controllers")))
                    {
                        $this->pushControllersInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // middlewares
                    if (file_exists($directory = app_path("{$module}/Middlewares")))
                    {
                        $this->pushmiddlewaresInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // requests
                    if (file_exists($directory = app_path("{$module}/Requests")))
                    {
                        $this->pushRequestsInDefinition($alias_namespace, $directory, $this->default_definitions);
                    }

                    // validation
                    if (file_exists(app_path("{$module}/Validation")))
                    {
                        $rule_prefix = "{$alias_namespace}Validation\\Rules\\";
                        Validator::with($rule_prefix);
                    }

                    // debug bar
                    if (file_exists(app_path("{$module}/Debugbar.php")))
                    {
                        $classPanel = "{$alias_namespace}Debugbar";
                        Debugger::getBar()->addPanel(new $classPanel);
                    }
                }
            }
        }

        // override default settings if the key of it existed in custom definition
        if (!empty($this->custom_definitions))
        {
            $custom_def_keys = array_keys($this->custom_definitions);
            foreach ($custom_def_keys as $key)
            {
                if (array_key_exists($key, $this->default_definitions))
                {
                    unset($this->default_definitions[$key]);
                }
            }
        }

        $builder->addDefinitions(array_merge($this->default_definitions, $this->custom_definitions));
    }
1321203
public function process(ContainerBuilder $container)
    {
        $parameterBag = $container->getParameterBag();

        $parameterReplacer = $container->get(ServiceNames::PARAMETER_REPLACER);

        $parameterReplacer->processParameterBag($parameterBag, $container);
    }
564014
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new MetaTagHandlersCompilerPass());
        $container->addCompilerPass(new TwigRuntimePass());
    }
837678
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ValidatorPass());
        $container->addCompilerPass(new FormPass());
        $container->addCompilerPass(new TwigLoaderPass());
    }
578733
protected function prepareContainer(ContainerBuilder $container)
    {
        parent::prepareContainer($container);
        $container->setParameter('smart_core_cms.modules', $this->modules);
        $container->setParameter('smart_core_cms.site_name', $this->siteName);
    }
165439
public function process(ContainerBuilder $container)
    {
        if (class_exists(BaseTranslator::class) && $container->hasDefinition('translator.default')
            && $container->hasParameter('translator.class')) {
            $class = $container->getParameter('translator.class');
            $definition = $container->getDefinition('translator.default');
            $definition->setClass($class);
        }
    }
1052498
public function prepend(ContainerBuilder $container)
    {
        $prependConfig = $this->getExtendedConfig($container);

        if (!empty($prependConfig)) {
            $container->prependExtensionConfig($this->getAlias(), $prependConfig);
        }
    }
609216
public function prepend(ContainerBuilder $container)
    {
        $this->declareReportAsCustomizable($container);
        $this->declareRouting($container);
        $this->prependRoleHierarchy($container);
    }
258163
public function process(ContainerBuilder $container)
    {
        $taggedServiceIds = $container->findTaggedServiceIds('p2_ratchet.application');
        $events = array();

        foreach ($taggedServiceIds as $serviceId => $attributes) {
            $service = $container->getDefinition($serviceId);

            /** @var \P2\Bundle\RatchetBundle\WebSocket\ApplicationInterface $classname */
            $classname = $container->getParameterBag()->resolveValue($service->getClass());

            $eventList = array_keys($classname::getSubscribedEvents());
            $events = array_merge($events, $eventList);
        }

        $container
            ->getDefinition('p2_ratchet.websocket.server_bridge')
            ->addMethodCall('setAllowedEvents', array($events));
    }
33750
public function process(ContainerBuilder $container)
    {
        $this->container = $container;
        $this->graph = $container->getCompiler()->getServiceReferenceGraph();
        $this->graph->clear();
        $this->lazy = false;

        foreach ($container->getAliases() as $id => $alias) {
            $targetId = $this->getDefinitionId((string) $alias);
            $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null);
        }

        parent::process($container);
    }
1055870
public function process(ContainerBuilder $container)
    {
        $taggedServices = $container->findTaggedServiceIds($this->tagName);
        foreach ($taggedServices as $id => $tags) {

            $reference = new Reference($id);
            foreach ($tags as $attr) {

                $tag = $this->getAttribute($id, $attr, 'tag');
                $method = $this->getAttribute($id, $attr, 'method');

                $this->injectInto($reference, $container, $tag, $method);
            }
        }
    }
942645
public function process(ContainerBuilder $container)
    {
        if ($container->hasDefinition('umenu.manager') || $container->hasAlias('umenu.manager')) {
            $eventListener = $container->getDefinition('ucms_tree.site_event_subscriber');

            $eventListener->addMethodCall(
                'setTreeManager',
                [new Reference('umenu.manager')]
            );
        }
    }
1024838
public function autoWireServices(ContainerBuilder $containerBuilder): void
    {
        $services = $this->getServices();
        foreach ($services as $class) {
            $containerBuilder->autowire($class, $class)->setPublic(true);
        }
    }
712938
public function load(array $configs, ContainerBuilder $builder)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yaml');
        $loader->load('services/factories.yaml');
        $loader->load('services/fields.yaml');
        $loader->load('services/resources.yaml');
        $loader->load('services/subscribers.yaml');
        $loader->load('services/twig.yaml');

        if ('dev' === $builder->getParameter('kernel.environment')) {
            $loader->load('services_dev.yaml');
        }
        $applicationConfig = [];
        $adminsConfig = [];
        $menusConfig = [];
        $enableExtraConfig = true;

        if (key_exists('application', $config)) {
            if (key_exists('enable_extra_configuration', $config['application'])) {
                $enableExtraConfig = $config['application']['enable_extra_configuration'];
            }
            $applicationConfig = $config['application'];
        }

        if (key_exists('admins', $config)) {
            $adminsConfig = $config['admins'];
        }

        if (key_exists('menus', $config)) {
            $menusConfig = $config['menus'];

            foreach ($menusConfig as $name => $menu) {
                if (null === $menu) {
                    $menusConfig[$name] = [];
                }
            }
        }
        $builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig);
        $builder->setParameter('lag.admin.application_configuration', $applicationConfig);
        $builder->setParameter('lag.admins', $adminsConfig);
        $builder->setParameter('lag.menus', $menusConfig);
    }
297857
public function process(ContainerBuilder $container)
    {
        if (
            !$container->hasDefinition(self::VIEW_BUILDER_REGISTRY)
            || !$container->hasDefinition(self::VIEW_BUILDER_CONTENT_TRANSLATE)
        ) {
            return;
        }

        $registry = $container->findDefinition(self::VIEW_BUILDER_REGISTRY);

        $viewBuilders = [
            $container->getDefinition(self::VIEW_BUILDER_CONTENT_TRANSLATE),
        ];

        $registry->addMethodCall('addToRegistry', [$viewBuilders]);
    }
246536
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(
            new DependencyInjection\Compiler\EventPropagationPass(),
            PassConfig::TYPE_BEFORE_OPTIMIZATION
        );
    }
417500
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ViewReferenceBuilderCompilerPass());
        $container->addCompilerPass(new ViewReferenceTransformerCompilerPass());
        $container->addCompilerPass(new ViewReferenceConnectorCompilerPass());
    }