Registers the formats.
@param Container $container Container
167123
protected function registerFormats(Container $container)
    {
        foreach ($this->formats as $formatClass) {
            $container['format.'.$formatClass::getName()] = $container->factory(function() use ($formatClass) {
                return new $formatClass();
            });
        }
    }
252119
public function register(Container $container)
    {
        if (!isset($container['console'])) {
            throw new \LogicException('You must register the ConsoleServiceProvider to use the WebServerServiceProvider.');
        }

        $container['web_server.document_root'] = null;
        $container['web_server.environment'] = 'dev';

        $commands = [
            'server:run' => 'web_server.command.server_run',
            'server:start' => 'web_server.command.server_start',
            'server:stop' => 'web_server.command.server_stop',
            'server:status' => 'web_server.command.server_status',
        ];

        $container['web_server.command.server_run'] = function (Container $container) {
            if (null === $docRoot = $container['web_server.document_root']) {
                throw new \LogicException('You must set the web_server.document_root parameter to use the development web server.');
            }

            return new ServerRunCommand($docRoot, $container['web_server.environment']);
        };

        $container['web_server.command.server_start'] = function (Container $container) {
            if (null === $docRoot = $container['web_server.document_root']) {
                throw new \LogicException('You must set the web_server.document_root parameter to use the development web server.');
            }

            return new ServerStartCommand($docRoot, $container['web_server.environment']);
        };

        $container['web_server.command.server_stop'] = function () {
            return new ServerStopCommand();
        };

        $container['web_server.command.server_status'] = function () {
            return new ServerStatusCommand();
        };

        if (class_exists(ConsoleFormatter::class)) {
            $container['web_server.command.server_log'] = function () {
                return new ServerLogCommand();
            };
            $commands['server:log'] = 'web_server.command.server_log';
        }

        $container['console.command.ids'] = array_merge($container['console.command.ids'], $commands);
    }
664002
public function register(Container $container)
    {
        $container['aura.html.locatorFactory'] = function () {
            return new HelperLocatorFactory();
        };
        $container['aura.html.locator'] = function (Container $container) {
            return $container['aura.html.locatorFactory']->newInstance();
        };
        $container['aura.html.escaper'] = function (Container $container) {
            return $container['aura.html.locator']->escape();
        };
    }
1230791
public function handle(Container $container)
    {
        $this->prepareData();

        $handler = $this->setJobInstanceIfNecessary(
            $this->job, $container->make($this->class)
        );

        call_user_func_array(
            [$handler, $this->method], $this->data
        );
    }
1075691
public function register(Container $container)
    {
        $container->register(new CacheServiceProvider());
        $container->register(new DatabaseServiceProvider());
        $container->register(new FilesystemServiceProvider());
        $container->register(new LoggerServiceProvider());
        $container->register(new ScriptServiceProvider());
        $container->register(new TranslatorServiceProvider());
        $container->register(new ViewServiceProvider());

        $this->registerKernelServices($container);
        $this->registerHandlerServices($container);
        $this->registerRouteServices($container);
        $this->registerMiddlewareServices($container);
        $this->registerRequestControllerServices($container);
        $this->registerModuleServices($container);
        $this->registerViewServices($container);
    }
134522
public function register(Container $container)
    {
        $container->prepareSharedObject(CsrfGuard::class)
            ->alias('security.csrf', CsrfGuard::class);

        // Always new instance in every usage
        $container->bind(CipherInterface::class, function (Container $container) {
            $config = $container->get('config');
            $class  = $this->getCipher($config->get('crypt.cipher', 'blowfish'));

            return $container->newInstance($class);
        });

        $container->share(Crypt::class, function (Container $container) {
            $config = $container->get('config');
            $key    = md5('Windwalker-Crypt::' . $config->get('system.secret'));

            return $container->newInstance(Crypt::class, ['key' => $key]);
        })->bindShared(CryptInterface::class, Crypt::class);

        $container->prepareSharedObject(ModernPassword::class)
            ->bindShared(HasherInterface::class, ModernPassword::class)
            ->bindShared(Password::class, ModernPassword::class);
    }
941907
public function register(Container $container)
    {
        $this->container = $container;

        // Register the PHP view loader if configuration says so
        if (strtolower($container["config.service"]["view.loader"]) === "php") {
            $container->register(new PHPLoaderProvider);
        }

        // Define view class loader
        $container["loadView.service"] = $container->protect(
            function (string $view, bool $useLayout = true) use ($container) {
                $cacheName = "loadView.service-{$view}" . ($useLayout ? "1" : "0");
                if (isset($container[$cacheName]) && isset($container["view.skipCache"]) === false) {
                    return $container[$cacheName];
                }

                $class = $container["view.className"] ?? $this->getViewClass($view);
                $view = new $class(
                    $container["config.service"],
                    $container["tplLoader.service"],
                    $container["response.service"]
                );

                if (method_exists($view, "init")) {
                    $args = func_get_args();
                    $args = array_slice($args, 2);
                    $view->init(...$args);
                }

                if ($useLayout && ($layoutName = $container["config.service"]["view.defaultLayout"]) !== "") {
                    $this->setLayout($layoutName, $view);
                }

                return $container[$cacheName] = $view;
            }
        );

        $container["loadTemplate.service"] = $container->protect(
            function (string $template, bool $useLayout = true) use ($container) {
                $cacheName = "loadTemplate.service-{$template}" . ($useLayout ? "1" : "0");
                if (isset($container[$cacheName])) {
                    return $container[$cacheName];
                }

                $container["view.skipCache"] = true;
                $container["view.className"] = \SlaxWeb\View\Base::class;
                $view = $container["loadView.service"]("", false);
                $view->template = $template;
                unset($container["view.skipCache"], $container["view.className"]);

                if ($useLayout && ($layoutName = $container["config.service"]["view.defaultLayout"]) !== "") {
                    $this->setLayout($layoutName, $view);
                }

                return $container[$cacheName] = $view;
            }
        );
    }
437076
protected function registerResources(ContainerBuilder $container)
    {
        $templatingEngines = $container->getParameter('templating.engines');

        if (in_array('twig', $templatingEngines)) {
            $container->setParameter('twig.form.resources', array_merge(
                array('FenrizbesColorPickerTypeBundle:Form:fields.html.twig'),
                $container->getParameter('twig.form.resources')
            ));
        }
    }
837678
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ValidatorPass());
        $container->addCompilerPass(new FormPass());
        $container->addCompilerPass(new TwigLoaderPass());
    }
715435
public function registerProviders(Container $container)
    {
        $sysProvider = new PackageProvider($this);
        $container->registerServiceProvider($sysProvider);

        $sysProvider->boot();

        $providers = (array) $this->get('providers');

        foreach ($providers as $interface => &$provider) {
            if ($provider === false) {
                continue;
            }

            if (is_subclass_of($provider, ServiceProviderInterface::class)) {
                // Handle provider
                if ($provider instanceof ClassMeta || (is_string($provider) && class_exists($provider))) {
                    $provider = $container->newInstance($provider);
                }

                if ($provider === false) {
                    continue;
                }

                $container->registerServiceProvider($provider);

                if ($provider instanceof BootableProviderInterface || method_exists($provider, 'boot')) {
                    $provider->boot($container);
                }
            } else {
                // Handle Service
                if (is_numeric($interface)) {
                    $container->prepareSharedObject($provider);
                } else {
                    $container->bindShared($interface, $provider);
                }
            }
        }

        foreach ($providers as $provider) {
            if ($provider === false) {
                continue;
            }

            if (is_subclass_of($provider, ServiceProviderInterface::class) && (
                $provider instanceof BootableDeferredProviderInterface
                || method_exists($provider, 'bootDeferred')
            )) {
                $provider->bootDeferred($container);
            }
        }
    }
653638
public function register(Container $container)
    {
        $dir = app()->getPath().'/config';
        $config = $container->get('config');
        $config->load($dir.'/config.php');
        $config->merge([
            'database' => load($dir.'/database.php'),
            'cache' => load($dir.'/cache.php'),
        ]);
        if (file_exists(app()->getPath().'/.env.yml')) {
            $config->merge(load(app()->getPath().'/.env.yml'));
        }
    }
416587
public function register(Container $container)
    {
        $container = $container->getParent();

        // System profiler
        $closure = function (Container $container) {
            $config = $container->get('config');

            if ($config->get('system.debug')) {
                $profiler = new Profiler('windwalker');

                $profiler->setPoint(new Point(
                    'start',
                    $config['execution.start'] ?: microtime(true),
                    $config['execution.memory'] ?: memory_get_usage(true),
                    ['tag' => 'system.process']
                ));

                return $profiler;
            }

            return new NullProfiler();
        };

        $container->share('profiler', $closure);

        // System collector
        $closure = function (Container $container) {
            $config = $container->get('config');

            if ($config->get('system.debug')) {
                return new Structure();
            } else {
                return new NullObject();
            }
        };

        $container->share('debugger.collector', $closure);

        if ($container->get('config')->get('system.debug')) {
            $this->registerProfilerListener($container, $container->get('config'));
            $this->registerDatabaseProfiler($container, $container->get('config'));
            $this->registerEmailProfiler($container, $container->get('config'));
            $this->registerLogsProfiler($container, $container->get('config'));
        }
    }
1066607
public function register(Container $container)
    {
        /**
         * @param  Container $container A container instance.
         * @return LoggerConfig
         */
        $container['logger/config'] = function (Container $container) {
            $appConfig    = isset($container['config']) ? $container['config'] : [];
            $loggerConfig = isset($appConfig['logger']) ? $appConfig['logger'] : null;
            return new LoggerConfig($loggerConfig);
        };

        /**
         * @return FactoryInterface
         */
        $container['logger/processor/factory'] = function () {
            return new Factory([
                'map' => [
                    'memory-usage' => MemoryUsageProcessor::class,
                    'uid'          => UidProcessor::class
                ]
            ]);
        };

        /**
         * @param  Container $container A container instance.
         * @return StreamHandler|null
         */
        $container['logger/handler/stream'] = function (Container $container) {
            $loggerConfig  = $container['logger/config'];
            $handlerConfig = $loggerConfig['handlers.stream'];

            if ($handlerConfig['active'] !== true) {
                return null;
            }

            $level = $handlerConfig['level'] ?: $loggerConfig['level'];
            return new StreamHandler($handlerConfig['stream'], $level);
        };

        /**
         * @param  Container $container A container instance.
         * @return BrowserConsoleHandler|null
         */
        $container['logger/handler/browser-console'] = function (Container $container) {
            $loggerConfig  = $container['logger/config'];
            $handlerConfig = $loggerConfig['handlers.console'];

            if ($handlerConfig['active'] !== true) {
                return null;
            }

            $level = $handlerConfig['level'] ?: $loggerConfig['level'];
            return new BrowserConsoleHandler($level);
        };

        /**
         * @param  Container $container A container instance.
         * @return Container Collection of defined record handlers, in a service container.
         */
        $container['logger/handlers'] = function (Container $container) {
            $loggerConfig   = $container['logger/config'];
            $handlersConfig = $loggerConfig['handlers'];
            $handlerFactory = $container['logger/handler/factory'];

            $handlers = new Container();
            foreach ($handlersConfig as $handler) {
                $handlers[$handler['type']] = function () use ($handler, $handlerFactory) {
                    $type    = $handler['type'];
                    $handler = $handlerFactory->create($type);
                    return $handler;
                };
            }

            return $handlers;
        };

        /**
         * Fulfills the PSR-3 dependency with a Monolog logger.
         *
         * @param  Container $container A container instance.
         * @return LoggerInterface
         */
        $container['logger'] = function (Container $container) {
            $loggerConfig = $container['logger/config'];

            if ($loggerConfig['active'] !== true) {
                return new NullLogger();
            }

            $logger = new Logger($loggerConfig['channel']);

            $memProcessor = new MemoryUsageProcessor();
            $logger->pushProcessor($memProcessor);

            $uidProcessor = new UidProcessor();
            $logger->pushProcessor($uidProcessor);

            $consoleHandler = $container['logger/handler/browser-console'];
            if ($consoleHandler) {
                $logger->pushHandler($consoleHandler);
            }

            $streamHandler = $container['logger/handler/stream'];
            if ($streamHandler) {
                $logger->pushHandler($streamHandler);
            }

            return $logger;
        };
    }
690980
public function register(Container $container)
    {
        $this->registerViewConfig($container);
        $this->registerLoaderServices($container);
        $this->registerEngineServices($container);
        $this->registerMustacheTemplatingServices($container);
        $this->registerTwigTemplatingServices($container);
        $this->registerViewServices($container);
    }
563114
protected function setupContainer(Container $container=null)
    {
        $this->container = $container ?? $this->container ?? new Container;

        $prefix= $this->getAbstractPrefix();

        if (! $this->container->bound( $prefix.'config')) {
            $this->container->instance( $prefix .'config', new Repository);
        }

        $this->config=$this->container->make( $prefix . 'config');
    }
149778
protected function registerAssetsManager(Container $container)
    {
        $container['assets/config'] = function (Container $container) {
            $config = $container['view/config']->get('assets');

            return new AssetsConfig($config);
        };

        $container['assets/builder'] = function () {
            return new AssetsBuilder();
        };

        /**
         * @param Container $container Pimple DI container.
         * @return AssetManager
         */
        $container['assets'] = function (Container $container) {
            $assetsBuilder = $container['assets/builder'];
            $assetsConfig = $container['assets/config'];

            return $assetsBuilder($assetsConfig);
        };
    }
374300
private function registerImageFilters(ContainerBuilder $container)
    {
        $medias = [
            'lg' => 1140,
            'md' => 940,
            'sm' => 720,
            'xs' => 480,
        ];

        $filterSets = [];

        foreach ($medias as $size => $width) {
            for ($column = 1; $column <= 12; $column++) {
                $number = 12 / $column;

                $filterSets[sprintf('col_%s_%d', $size, $column)] = [
                    'cache'           => 'local_media',
                    'data_loader'     => 'local_media',
                    'filters'         => [
                        'relative_resize' => ['widen' => round(($width - ($number - 1) * 30) / $number)],
                    ],
                    'post_processors' => [
                        'jpegoptim' => ['strip_all' => true, 'max' => "%image.jpeg_quality%", 'progressive' => true],
                        'pngquant'  => ['quality' => "%image.png_quality%"],
                    ],
                ];
            }
        }

        $container->prependExtensionConfig('liip_imagine', [
            'filter_sets' => $filterSets,
        ]);
    }