Compiles configuration processing %foobar% placeholders

@param ContainerInterface $container
@throws \LogicException
482198
protected function buildConfiguration(ContainerInterface $container)
	{
		$config = array();

		$processor = new Processor();

		$configurationOverride = $this->getConfigurationOverrides();

		foreach ($this->configurationSections as $key => $definition) {
			$package = $definition['package'];
			$data = $definition['data'];

			$configuration = $package->getConfiguration();

			$configs = array();

			$configs[] = $data;

			if (array_key_exists($key, $configurationOverride)) {
				$configs[] = $configurationOverride[$key];
				unset($configurationOverride[$key]);
			}
			
			$packageConfiguration = $processor->processConfiguration($configuration, $configs);

			foreach ($packageConfiguration as $confKey => $value) {
				$config[$key.'.'.$confKey] = $value;
			}
		}

		if (count($configurationOverride) != 0) {
			throw new \LogicException(
				sprintf('Extra keys are found in Supra\'s config.yml that do not belong to any package: %s.',
					implode(', ', array_keys($configurationOverride)))
			);
		}

		array_walk_recursive($config, function (&$value) use (&$config) {
			if (!is_string($value)) {
				return;
			}

			$count = preg_match_all('/%[a-z\\._]+%/i', $value, $matches);

			if (!$count) {
				return;
			}

			$replacements = array();

			foreach ($matches as $expression) {
				$parameter = trim($expression[0], '%');
				$chunks = explode('.', $parameter);

				$name = $chunks[0].'.'.$chunks[1];

				if (!isset($config[$name])) {
					throw new ReferenceException(sprintf('Parameter "%s" can not be resolved', $name));
				}

				$val = $config[$name];

				if (count($chunks) > 2) {
					$path = array_slice($chunks, 2);

					while ($key = array_shift($path)) {
						if (!array_key_exists($key, $val)) {
							throw new ReferenceException(sprintf('Lost at sub-key "%s" for parameter "%s"', $key, $parameter));
						}

						$val = $val[$key];
					}
				}

				$replacements[$expression[0]] = $val;
			}

			$value = strtr($value, $replacements);
		});

		foreach ($config as $key => $value) {
			$container->setParameter($key, $value);
		}

		//create services defined by 'services:' section
		foreach ($this->configurationSections as $key => $definition) {
			if (isset($config[$key.'.services'])) {
				foreach ($config[$key.'.services'] as $id => $serviceDefinition) {
					$container[$id] = function ($container) use ($serviceDefinition) {
						//this is where the magic happens
						$className = $serviceDefinition['class'];
						$parameters = $serviceDefinition['parameters'];

						$reflection = new \ReflectionClass($className);

						foreach ($parameters as $key => $parameter) {
							if (is_string($parameter) && isset($parameter[0]) && $parameter[0] == '@') {
								$parameters[$key] = $container[ltrim($parameter, '@')];
							}
						}

						$instance = $reflection->newInstanceArgs($parameters);

						return $instance;
					};
				}
			}
		}
	}
181388
public function migrate(ContainerInterface $container): void
    {
        foreach ($this->getMigrations($container) as $class) {
            assert(is_string($class));
            $this->getIO()->writeInfo("Starting migration for `$class`..." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
            if (($migration = $this->createMigration($class, $container)) !== null) {
                $migration->init($container)->migrate();
                $this->getIO()->writeInfo("Migration finished for `$class`." . PHP_EOL, IoInterface::VERBOSITY_NORMAL);
            }
        }
    }
539426
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ConfigurationCompilerPass());
        $container->addCompilerPass(new VendorCompilerPass());
    }
724701
public function process(ContainerBuilder $container)
    {
        $repositoryConfigurations = $container->getParameter('apisearch.repository_configuration');
        foreach ($repositoryConfigurations as $name => $repositoryConfiguration) {
            $this->createAppRepositories(
                $container,
                $name,
                $repositoryConfiguration
            );

            foreach ($repositoryConfiguration['indices'] as $indexName => $indexId) {
                $indexId = (string) $indexId;
                $this->createIndexRepositories(
                    $container,
                    $name,
                    $repositoryConfiguration,
                    $indexId,
                    $indexName
                );
            }
        }
    }
1228344
public function process(ContainerBuilder $container)
    {
        if (!$container->has($this->helperCollectionId)) {
            throw new \LogicException(
                sprintf(
                    'Helper collection service "%s" is not defined',
                    $this->helperCollectionId
                )
            );
        }

        $helperCollection = $container->findDefinition($this->helperCollectionId);

        foreach ($container->findTaggedServiceIds($this->tagName) as $helperServiceId => $tags) {
            $helperCollection->addMethodCall('set', [new Reference($helperServiceId)]);
        }
    }
1251746
public function setContainer(ContainerInterface $container = null)
    {
        $this->abortIf(is_null($container), 'Requires DI container');

        $this->fs = $container->get('filesystem');
        $this->em = $container->get('doctrine.orm.entity_manager');
        $this->target = $container->getParameter('kernel.root_dir').'/../web/media/example/';
        $this->source = $container->get('kernel')->locateResource('@AnimeDbDevBundle/Resource/private/images/');
    }
435560
public static function configureContainer(LimoncelloContainerInterface $container): void
    {
        static::baseConfigureContainer($container);

        $container[PassportServerIntegrationInterface::class] = function (
            PsrContainerInterface $container
        ): PassportServerIntegrationInterface {
            return new PassportServerIntegration($container);
        };

        $container[TokenRepositoryInterface::class] = function (
            PsrContainerInterface $container
        ): TokenRepositoryInterface {
            $connection = $container->get(Connection::class);
            $schema     = $container->get(DatabaseSchemaInterface::class);

            return new TokenRepository($connection, $schema);
        };
    }
1141418
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition(TabRegistry::class)) {
            return;
        }

        $tabRegistry = $container->getDefinition(TabRegistry::class);
        $tabGroupDefinition = new Definition(TabGroup::class, ['systeminfo']);
        $tabRegistry->addMethodCall('addTabGroup', [$tabGroupDefinition]);
    }
1267863
public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
        $this->application = null !== $container ? $this->container->get('bbapp') : null;
    }
848346
protected function injectPackages(ContainerInterface $container)
	{
		foreach ($this->getPackages() as $package) {
			$package->inject($container);
		}
	}
524817
protected function parseDataProvider(ContainerInterface $container)
    {
        if ($container->hasDataProviderDefinition()) {
            $config = $container->getDataProviderDefinition();
        } else {
            $config = new DefaultDataProviderDefinition();
            $container->setDataProviderDefinition($config);
        }

        // If mode is 5, we need to define tree view.
        if ((5 === $this->getFromDca('list/sorting/mode'))
            && !$container->getBasicDefinition()->getRootDataProvider()
        ) {
            $container->getBasicDefinition()->setRootDataProvider($container->getName());
        }

        if (null !== ($parentTable = $this->getFromDca('config/ptable'))) {
            // Check config if it already exists, if not, add it.
            if (!$config->hasInformation($parentTable)) {
                $providerInformation = new ContaoDataProviderInformation();
                $providerInformation->setName($parentTable);
                $config->addInformation($providerInformation);
            } else {
                $providerInformation = $config->getInformation($parentTable);
            }

            if ($providerInformation instanceof ContaoDataProviderInformation) {
                $initializationData = (array) $providerInformation->getInitializationData();

                $providerInformation
                    ->setTableName($parentTable)
                    ->setInitializationData(
                        \array_merge(
                            [
                                'source' => $parentTable,
                                'name'   => $parentTable,
                            ],
                            $initializationData
                        )
                    );

                if (!$container->getBasicDefinition()->getRootDataProvider()) {
                    $container->getBasicDefinition()->setRootDataProvider($parentTable);
                }
                if (!$container->getBasicDefinition()->getParentDataProvider()) {
                    $container->getBasicDefinition()->setParentDataProvider($parentTable);
                }
            }
        }

        $providerName = $container->getBasicDefinition()->getDataProvider() ?: $container->getName();

        // Check config if it already exists, if not, add it.
        if (!$config->hasInformation($providerName)) {
            $providerInformation = new ContaoDataProviderInformation();
            $providerInformation->setName($providerName);
            $config->addInformation($providerInformation);
        } else {
            $providerInformation = $config->getInformation($providerName);
        }

        if ($providerInformation instanceof ContaoDataProviderInformation) {
            $initializationData = (array) $providerInformation->getInitializationData();

            if (!isset($initializationData['source'])) {
                $providerInformation
                    ->setTableName($providerName)
                    ->setInitializationData(
                        \array_merge(
                            [
                                'source' => $providerName,
                                'name'   => $providerName
                            ],
                            $initializationData
                        )
                    );
            }
            $providerInformation
                ->setVersioningEnabled((bool) $this->getFromDca('config/enableVersioning'));

            if (!$container->getBasicDefinition()->getDataProvider()) {
                $container->getBasicDefinition()->setDataProvider($providerName);
            }
        }
    }
739713
public function process(ContainerBuilder $container)
    {
        $this->setFactoryAndServerClasses($container);
        parent::process($container);
        $this->setCasServerConfig($container);
    }
674945
public function process(ContainerBuilder $container)
    {
        $tagged_services = $container->findTaggedServiceIds('asf_core.manager');

        foreach ($tagged_services as $id => $tags) {
            foreach ($tags as $attributes) {
                if (!isset($attributes['entity'])) {
                    throw new \LogicException(sprintf('Attribute "entity" missing for service tagged "asf_core.manager" for service id "%s"', $id));
                }

                $class = false !== strpos($container->getDefinition($id)->getClass(), '%') ? $container->getParameter($this->translateParameter($container->getDefinition($id)->getClass())) : $container->getDefinition($id)->getClass();
                $entity = false !== strpos($attributes['entity'], '%') ? $container->getParameter($this->translateParameter($attributes['entity'])) : $attributes['entity'];

                if (!class_exists($class)) {
                    $container->getDefinition($id)->setClass('ASF\CoreBundle\Utils\Manager\ASFManager');
                }

                $arguments = $container->getDefinition($id)->getArguments();
                $injected_args = array(
                    new Reference('doctrine.orm.entity_manager'),
                    $entity,
                );

                $container->getDefinition($id)->setArguments(array_merge($injected_args, $arguments));
            }
        }
    }
345437
public function process(ContainerBuilder $container)
    {
        $this->container = $container;

        foreach ($container->getDefinitions() as $definition) {
            if ($definition->isSynthetic() || $definition->isAbstract()) {
                continue;
            }

            $definition->setArguments($this->processArguments($definition->getArguments()));
            $definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
            $definition->setProperties($this->processArguments($definition->getProperties()));
            $definition->setFactory($this->processFactory($definition->getFactory()));
        }

        foreach ($container->getAliases() as $id => $alias) {
            $aliasId = (string) $alias;
            if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) {
                $container->setAlias($id, new Alias($defId, $alias->isPublic()));
            }
        }
    }
1176466
protected function executeCache(IoInterface $inOut, ContainerInterface $container): void
    {
        /** @var TemplatesCacheInterface $cache */
        $cache = $container->get(TemplatesCacheInterface::class);

        $settings  = $this->getTemplatesSettings($container);
        $templates = $settings[TemplatesSettings::KEY_TEMPLATES_LIST];

        foreach ($templates as $templateName) {
            // it will write template to cache
            $inOut->writeInfo(
                "Starting template caching for `$templateName`..." . PHP_EOL,
                IoInterface::VERBOSITY_VERBOSE
            );

            $cache->cache($templateName);

            $inOut->writeInfo(
                "Template caching finished for `$templateName`." . PHP_EOL,
                IoInterface::VERBOSITY_NORMAL
            );
        }
    }
752608
protected function run(ContainerInterface $container, IoInterface $inOut): void
    {
        $item     = $inOut->getArguments()[static::ARG_ITEM];
        $singular = $inOut->getArguments()[static::ARG_SINGULAR];
        $plural   = $inOut->getArguments()[static::ARG_PLURAL];

        if ($this->isValidShortClassName($singular) === false) {
            throw new InvalidArgumentException("`$singular` is not a valid class name.");
        }
        if ($this->isValidShortClassName($plural) === false) {
            throw new InvalidArgumentException("`$plural` is not a valid class name.");
        }

        /** @var FileSystemInterface $fileSystem */
        $fileSystem = $container->get(FileSystemInterface::class);
        /** @var SettingsProviderInterface $settingsProvider */
        $settingsProvider = $container->get(SettingsProviderInterface::class);

        $dataTemplates = function () use ($settingsProvider, $fileSystem, $singular, $plural) : array {
            return [
                $this->composeMigration($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeSeed($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeModel($settingsProvider, $fileSystem, $singular, $plural),
            ];
        };

        $basicTemplates = function () use ($settingsProvider, $fileSystem, $singular, $plural) : array {
            return [
                $this->composeSchema($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeAuthorization($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeApi($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeValidationRules($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeQueryValidationOnReadRules($settingsProvider, $fileSystem, $singular, $plural),
            ];
        };

        $webTemplates = function () use ($settingsProvider, $fileSystem, $singular, $plural) : array {
            return [
                $this->composeWebValidationOnCreateRules($settingsProvider, $fileSystem, $singular),
                $this->composeWebValidationOnUpdateRules($settingsProvider, $fileSystem, $singular),
                $this->composeWebController($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeWebRoute($settingsProvider, $fileSystem, $singular, $plural),
            ];
        };

        $jsonTemplates = function () use ($settingsProvider, $fileSystem, $singular, $plural) : array {
            return [
                $this->composeJsonValidationOnCreateRules($settingsProvider, $fileSystem, $singular),
                $this->composeJsonValidationOnUpdateRules($settingsProvider, $fileSystem, $singular),
                $this->composeJsonController($settingsProvider, $fileSystem, $singular, $plural),
                $this->composeJsonRoute($settingsProvider, $fileSystem, $singular, $plural),
            ];
        };

        switch ($item) {
            case static::ITEM_DATA_RESOURCE:
                $this->createTemplates($fileSystem, array_merge(
                    $dataTemplates()
                ));
                break;
            case static::ITEM_WEB_RESOURCE:
                $this->createTemplates($fileSystem, array_merge(
                    $dataTemplates(),
                    $basicTemplates(),
                    $webTemplates()
                ));
                break;
            case static::ITEM_JSON_API_RESOURCE:
                $this->createTemplates($fileSystem, array_merge(
                    $dataTemplates(),
                    $basicTemplates(),
                    $jsonTemplates()
                ));
                break;
            case static::ITEM_FULL_RESOURCE:
                $this->createTemplates($fileSystem, array_merge(
                    $dataTemplates(),
                    $basicTemplates(),
                    $webTemplates(),
                    $jsonTemplates()
                ));
                break;
            default:
                $inOut->writeError("Unsupported item type `$item`." . PHP_EOL);
                break;
        }
    }
1186006
public function process(ContainerBuilder $container)
    {
        $taggedServices = $container->findTaggedServiceIds('chameleon_system_shop.payment_config_provider');

        $loaderDefinition = $container->getDefinition('chameleon_system_shop.payment.config_loader');

        foreach ($taggedServices as $serviceId => $attributes) {
            $systemName = null;
            foreach ($attributes as $tag) {
                foreach ($tag as $key => $value) {
                    if ('system_name' === $key) {
                        $systemName = $value;
                    }
                }
            }
            if (null === $systemName) {
                throw new LogicException(
                    "Services tagged with chameleon_system_shop.payment_config_provider need to provide a system_name attribute. This service doesn't have such an attribute: ".$serviceId
                );
            }

            $loaderDefinition->addMethodCall('addConfigProvider', array($systemName, new Reference($serviceId)));
        }
    }