ClosureLoader example

private function buildConfig(ContainerBuilder $container, string $environment): void
    {
        $locator = new FileLocator('Resources/config');

        $resolver = new LoaderResolver([
            new XmlFileLoader($container$locator),
            new YamlFileLoader($container$locator),
            new IniFileLoader($container$locator),
            new PhpFileLoader($container$locator),
            new GlobFileLoader($container$locator),
            new DirectoryLoader($container$locator),
            new ClosureLoader($container),
        ]);

        $configLoader = new DelegatingLoader($resolver);

        $confDir = $this->getPath() . '/Resources/config';

        $configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob');
        $configLoader->load($confDir . '/{packages}/' . $environment . '/*' . Kernel::CONFIG_EXTS, 'glob');
    }
}
private function buildConfig(ContainerBuilder $container): void
    {
        $locator = new FileLocator('Resources/config');

        $resolver = new LoaderResolver([
            new XmlFileLoader($container$locator),
            new YamlFileLoader($container$locator),
            new IniFileLoader($container$locator),
            new PhpFileLoader($container$locator),
            new GlobFileLoader($container$locator),
            new DirectoryLoader($container$locator),
            new ClosureLoader($container),
        ]);

        $configLoader = new DelegatingLoader($resolver);

        $confDir = $this->getPath() . '/Resources/config';

        $configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob');

        $env = $container->getParameter('kernel.environment');
        if (!\is_string($env)) {
            throw new \RuntimeException('Container parameter "kernel.environment" needs to be a string');
        }


        $locator = new FileLocator('Resources/config');

        $resolver = new LoaderResolver([
            new XmlFileLoader($container$locator),
            new YamlFileLoader($container$locator),
            new IniFileLoader($container$locator),
            new PhpFileLoader($container$locator),
            new GlobFileLoader($container$locator),
            new DirectoryLoader($container$locator),
            new ClosureLoader($container),
        ]);

        $configLoader = new DelegatingLoader($resolver);

        $confDir = $this->getPath() . '/Resources/config';

        $configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob');
        $configLoader->load($confDir . '/{packages}/' . $environment . '/*' . Kernel::CONFIG_EXTS, 'glob');
        if ($environment === 'e2e') {
            $configLoader->load($confDir . '/{packages}/prod/*' . Kernel::CONFIG_EXTS, 'glob');
        }
    }
Home | Imprint | This part of the site doesn't use cookies.