Override setup commands

Add Bridge\RunCommand
@param ServiceContainer $container
550420
protected function setupCommands(ServiceContainer $container)
    {
        BaseApplication::setupCommands($container);
        $container->setShared('console.commands.run',function ($c) {
            return new RunCommand();
        });
    }
1301162
public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface
    {
        $container[self::COMMAND_COLLECTION] = function () {
            return new CommandCollection(
                $this->getCommandList()
            );
        };

        return $container;
    }
520711
public function process(ContainerBuilder $container)
    {
        // Now, let's store the registry in the container (an empty version of it... it will be dynamically added at runtime):
        $this->registerRegistry($container);

        $registry = $this->registryProvider->getRegistry($container);

        // Note: in the 'boot' method of a bundle, the container is available.
        // We use that to push the lazy array in the container.
        // The lazy array can be used by the registry that is also part of the container.
        // The registry can itself be used by a factory that creates services!

        $this->registerAcclimatedContainer($container);

        foreach ($registry as $serviceProviderKey => $serviceProvider) {
            $this->registerFactories($serviceProviderKey, $serviceProvider, $container);
        }

        foreach ($registry as $serviceProviderKey => $serviceProvider) {
            $this->registerExtensions($serviceProviderKey, $serviceProvider, $container);
        }
    }
340604
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new VersionCompilerPass(new PrettyVersions()));
        $container->addCompilerPass(new EnvParametersCompilerPass());
        $container->addCompilerPass(new RouteLoaderCompilerPass());
        $container->addCompilerPass(new HttpClientOptionsCompilerPass());
    }
1134730
public function buildService(Container $container, ArrayResolver $serviceConfig, $serviceName)
    {
        return $this->serviceBuilder->buildService($container, $serviceConfig, $serviceName);
    }
564524
public function run(\Asgard\Container\ContainerInterface $container) {
		parent::run($container);

		#Files
		$container['rulesregistry']->registerNamespace('Asgard\File\Rule');

		#ORMInterface
		$container['rulesregistry']->registerNamespace('Asgard\Orm\Rule');

		#Controllers Templates
		$container['httpKernel']->addTemplatePathSolver(function($viewable, $template) {
			if(!$viewable instanceof \Asgard\Http\LambdaController) {
				$r = new \ReflectionClass($viewable);
				$viewableName = basename(str_replace('\\', DIRECTORY_SEPARATOR, get_class($viewable)));
				$viewableName = strtolower(preg_replace('/Controller$/i', '', $viewableName));

				if($viewable instanceof \Asgard\Http\Controller)
					$format = $viewable->request->format();
				else
					$format = 'html';

				$file = realpath(dirname($r->getFileName()).'/../'.$format.'/'.$viewableName.'/'.$template.'.php');
				if(!file_exists($file))
					return realpath(dirname($r->getFileName()).'/../html/'.$viewableName.'/'.$template.'.php');
				else
					return $file;
			}
		});

		if($container->has('console')) {
			$root = $container['kernel']['root'];
			$em = $container['entityManager'];

			#generator
			$generateCommand = new \Asgard\Generator\Command\GenerateCommand($container['generator']);
			$container['console']->add($generateCommand);

			#if database is available
			if($container['config']['database']) {
				$mm = $container['MigrationManager'];
				$om = $container['ormMigrations'];
				$db = $container['db'];
				$schema = $container['schema'];
				$dataMapper = $container['dataMapper'];

				$migrationList = new \Asgard\Migration\Command\ListCommand($container['kernel']['root'].'/migrations', $db);
				$container['console']->add($migrationList);

				$migrationRemove = new \Asgard\Migration\Command\RemoveCommand($container['kernel']['root'].'/migrations', $db, $schema);
				$container['console']->add($migrationRemove);

				$migrationAdd = new \Asgard\Migration\Command\AddCommand($root.'/migrations', $db, $schema);
				$container['console']->add($migrationAdd);

				$dbCreate = new \Asgard\Db\Command\CreateCommand($db);
				$container['console']->add($dbCreate);

				$ormAutomigrate = new \Asgard\Orm\Command\AutoMigrateCommand($om);
				$container['console']->add($ormAutomigrate);

				$ormGenerateMigration = new \Asgard\Orm\Command\GenerateMigrationCommand($om);
				$container['console']->add($ormGenerateMigration);

				$ormPreviewMigration = new \Asgard\Orm\Command\PreviewMigrationCommand($om);
				$container['console']->add($ormPreviewMigration);

				$dbEmpty = new \Asgard\Db\Command\EmptyCommand($db);
				$container['console']->add($dbEmpty);

				$migrationMigrate = new \Asgard\Migration\Command\MigrateCommand($container['kernel']['root'].'/migrations', $db, $schema);
				$migrationMigrateOne = new \Asgard\Migration\Command\MigrateOneCommand($container['kernel']['root'].'/migrations', $db, $schema);
				$migrationRollback = new \Asgard\Migration\Command\RollbackCommand($root.'/migrations', $db, $schema);
				$migrationUnmigrate = new \Asgard\Migration\Command\UnmigrateCommand($root.'/migrations', $db, $schema);
				$migrationRefresh = new \Asgard\Migration\Command\RefreshCommand($container['kernel']['root'].'/migrations', $db, $schema);
				$install = new \Asgard\Core\Command\InstallCommand($db, $schema);
				$publish = new \Asgard\Core\Command\PublishCommand($db, $schema);
			}
			else {
				$migrationMigrate = new \Asgard\Migration\Command\MigrateCommand($container['kernel']['root'].'/migrations');
				$migrationMigrateOne = new \Asgard\Migration\Command\MigrateOneCommand($container['kernel']['root'].'/migrations');
				$migrationRollback = new \Asgard\Migration\Command\RollbackCommand($root.'/migrations');
				$migrationUnmigrate = new \Asgard\Migration\Command\UnmigrateCommand($root.'/migrations');
				$migrationRefresh = new \Asgard\Migration\Command\RefreshCommand($container['kernel']['root'].'/migrations');
				$install = new \Asgard\Core\Command\InstallCommand;
				$publish = new \Asgard\Core\Command\PublishCommand;

				$db = null;
				$mm = null;
			}

			#tester
			$httpKernel = $container['httpKernel'];
			$resolver = $container['resolver'];

			$runCommand = new \Asgard\Tester\Command\RunCommand($httpKernel, $resolver, $db, $mm);
			$container['console']->add($runCommand);

			$curlCommand = new \Asgard\Tester\Command\CurlCommand();
			$container['console']->add($curlCommand);

			$httpTests = new \Asgard\Tester\Command\GenerateTestsCommand($container['kernel']['root'].'/tests');
			$container['console']->add($httpTests);

			$config = $container['config']['tester.coverage'];
			$coverageCommand = new \Asgard\Tester\Command\CoverageCommand($config);
			$container['console']->add($coverageCommand);

			$container['console']->add($migrationMigrate);
			$container['console']->add($migrationMigrateOne);
			$container['console']->add($migrationRollback);
			$container['console']->add($migrationUnmigrate);
			$container['console']->add($migrationRefresh);
			$container['console']->add($install);
			$container['console']->add($publish);

			$translation = $container['translation'];
			$root = $container['kernel']['root'];
			$dir = $container['config']['translation.directories'];
			if(!$dir)
				$dir = [$root.'/app'];

			$exportCsvCommand = new \Asgard\Translation\Command\ExportCsvCommand($translation, $dir);
			$container['console']->add($exportCsvCommand);

			$importCommand = new \Asgard\Translation\Command\ImportCommand();
			$container['console']->add($importCommand);

			$exportYamlCommand = new \Asgard\Translation\Command\ExportYamlCommand($translation, $dir);
			$container['console']->add($exportYamlCommand);

			$migrationCreate = new \Asgard\Migration\Command\CreateCommand($container['kernel']['root'].'/migrations');
			$container['console']->add($migrationCreate);

			$compile = new \Asgard\Core\Command\CompileCommand($container['config']['compile'], $container['kernel']->getCompiledFile());
			$container['console']->add($compile);

			$showEnv = new \Asgard\Core\Command\ShowEnvironmentCommand($container['kernel']);
			$container['console']->add($showEnv);

			$switchEnv = new \Asgard\Core\Command\SwitchEnvironmentCommand($container['kernel']);
			$container['console']->add($switchEnv);

			$httpRoutes = new \Asgard\Http\Command\RoutesCommand($container['resolver']);
			$container['console']->add($httpRoutes);

			$containerServices = new \Asgard\Container\Command\ListCommand($root);
			$container['console']->add($containerServices);

			$cacheClear = new \Asgard\Cache\Command\ClearCommand($container['systemcache']);
			$container['console']->add($cacheClear);

			$configInit = new \Asgard\Config\Command\InitCommand($container['kernel']['root'].'/config');
			$container['console']->add($configInit);

			$dbInit = new \Asgard\Db\Command\InitCommand($container['kernel']['root'].'/config');
			$container['console']->add($dbInit);

			$httpBrowser = new \Asgard\Http\Command\BrowserCommand($container['httpKernel']);
			$container['console']->add($httpBrowser);
		}
	}
1262971
public function prepend(ContainerBuilder $container): void
    {
        if (!$container->hasExtension('fos_oauth_server')) {
            throw new ServiceNotFoundException('FOSOAuthServerBundle must be registered in kernel.');
        }

        $config = $this->processConfiguration(new Configuration(), $container->getExtensionConfig($this->getAlias()));
        $resourcesConfig = $config['resources'];

        $container->prependExtensionConfig('fos_oauth_server', [
            'db_driver' => 'orm',
            'client_class' => $resourcesConfig['api_client']['classes']['model'],
            'access_token_class' => $resourcesConfig['api_access_token']['classes']['model'],
            'refresh_token_class' => $resourcesConfig['api_refresh_token']['classes']['model'],
            'auth_code_class' => $resourcesConfig['api_auth_code']['classes']['model'],
            'service' => [
                'user_provider' => 'sylius.admin_user_provider.email_or_name_based',
                'client_manager' => 'sylius.oauth_server.client_manager',
            ],
        ]);
    }
340311
private function generateServices(array $services, ContainerBuilder $container)
    {
        foreach ($services as $serviceName => $service) {
            $serviceId = 'bridge.'.$serviceName;

            $serviceDefinition = $this->createComponentDefinition($serviceName, $service['class'], $service['options']);
            $serviceDefinition->addMethodCall('setEventDispatcher', array(new Reference('bridge.event_dispatcher')));
            $serviceDefinition->addMethodCall('setRegistry', array(new Reference('bridge.registry')));

            $this->generateGroups($service['groups'], $serviceId, $serviceDefinition, $container);

            $container->setDefinition($serviceId, $serviceDefinition);

            $container
                ->getDefinition('bridge.registry')
                ->addMethodCall('addService', array(new Reference($serviceId)));
        }
    }
163704
public function process(ContainerBuilder $container)
    {
        $pool = $container->getDefinition('admin.configuration.pool');
        // get tagged services
        $configurations = array();
        foreach ($container->findTaggedServiceIds('admin.configuration') as $id => $attributes) {
            $configurations[$id] = $attributes;
        }
        $pool->addMethodCall('setConfigurations', array($configurations));
    }
1278841
public function boot(Container $container)
    {
        // register an extension
        $container['events']->on(
            'f.extension.load',
            function (Extension $extension, array $options, $safe) use ($container) {
                $extension->setup($options);
                $container['command']->registerFunctions($extension->provideFunctions(), $safe);
                $container['command']->registerFilters($extension->provideFilters());
                if ($extension instanceof TemplateAware) {
                    $extension->setStack($container['template.stack']);
                }
                if ($extension instanceof FinderAware) {
                    $extension->setFinder($container['template.finder']);
                }
                if ($extension instanceof EngineAware) {
                    $extension->setEngine($container['engine']);
                }
                $container['events']->fire('f.extension.registered', $extension);
            }
        );

        // register a function
        $container['events']->on(
            'f.function.register',
            function ($function, callable $callback, $safe) use ($container) {
                $container['command']->registerFunctions([$function => $callback], $safe);
            }
        );

        // register a filter
        $container['events']->on(
            'f.filter.register',
            function ($filter, callable $callback) use ($container) {
                $container['command']->registerFilters([$filter => $callback]);
            }
        );

        $container['events']->on('f.bootstrapped', function () use ($container) {
            $container['command']->lock();
        });
    }
378954
protected function runForegroundProcess(Container $container)
    {
       $this->exitcode = (new Process($this->buildForegroundCommand(), base_path(), null, null, null))->run();
    }
226991
public function process(ContainerBuilder $container): void
    {
        $resolver = $container->findDefinition('fivelab.resource.serializer_resolver');
        $services = $container->findTaggedServiceIds('resource.serializer');

        foreach ($services as $serviceId => $tags) {
            try {
                $attributes = $tags[0];

                if (!array_key_exists('supportable', $attributes)) {
                    throw new \RuntimeException('The resource serializer should define with supportable instance. Please add the "supportable" attribute to "resource.assembler".');
                }

                $serializerDefinition = $container->getDefinition($serviceId);
                $serializerClass = $container->getParameterBag()->resolveValue($serializerDefinition->getClass());

                if (!is_a($serializerClass, ResourceSerializerInterface::class, true)) {
                    throw new \RuntimeException(sprintf(
                        'The resource serializer should implement "%s".',
                        ResourceSerializerInterface::class
                    ));
                }

                $supportableServiceId = $attributes['supportable'];

                $resolver->addMethodCall('add', [
                    new Reference($supportableServiceId),
                    new Reference($serviceId),
                ]);
            } catch (\Exception $e) {
                throw new \RuntimeException(sprintf(
                    'Can\'t compile resource serializer with service id "%s".',
                    $serviceId
                ), 0, $e);
            }
        }
    }
677077
public function run(\Asgard\Container\ContainerInterface $container) {
		$bundleData = $container['systemcache']->fetch('asgard.bundles.'.$this->getID());
		if($bundleData !== false) {
			$hooks = $bundleData['hooks'];
			$routes = $bundleData['routes'];
		}
		else {
			$hooks = $container->has('hooks') ? $this->loadHooks():[];
			$routes = $container->has('resolver') ? $this->loadControllers():[];

			$container['systemcache']->save('asgard.bundles.'.$this->getID(), [
				'hooks' => $hooks,
				'routes' => $routes,
			]);
		}

		if($container->has('hooks'))
			$container['hooks']->hooks($hooks);

		if($container->has('resolver'))
			$container['resolver']->addRoutes($routes);

		if($container->has('translation'))
			$this->loadTranslations($container['translation']);

		if($container->has('console')) {
			$this->loadCommands($container['console']);
			$this->loadEntities($container['entityManager']);
		}
	}
760292
public function process(ContainerBuilder $container)
    {
        if (!$this->enabled($container)) {
            return;
        }

        $mappingDriverDef = $this->getDriver($container);
        $chainDriverDefService = $this->getChainDriverServiceName($container);
        // Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
        $chainDriverDef = $container->getDefinition($chainDriverDefService);
        foreach ($this->namespaces as $namespace) {
            $chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);
        }

        if (!\count($this->aliasMap)) {
            return;
        }

        $configurationServiceName = $this->getConfigurationServiceName($container);
        // Definition of the Doctrine\...\Configuration class specific to the Doctrine flavour.
        $configurationServiceDefinition = $container->getDefinition($configurationServiceName);
        foreach ($this->aliasMap as $alias => $namespace) {
            $configurationServiceDefinition->addMethodCall($this->registerAliasMethodName, [$alias, $namespace]);
        }
    }
972979
private function overrideServices(ContainerBuilder $container, array $services)
    {
        $serviceConfig = array(
            'auth_handler' => 'ma27_api_key_authentication.auth_handler',
            'key_factory'  => 'ma27_api_key_authentication.key_factory',
        );

        foreach ($serviceConfig as $configIndex => $replaceableServiceId) {
            if (!isset($services[$configIndex]) || null === $serviceId = $services[$configIndex]) {
                continue;
            }

            $container->removeDefinition($replaceableServiceId);
            $container->setAlias($replaceableServiceId, new Alias($serviceId));
        }
    }
294609
public function loadServices(ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
        $loader->load('services.xml');
        $this->imageDrivers = $this->driverLocator->findDrivers(
            $container,
            $this->imageDriverKeys,
            $this->imageDriverConfigs
        );
    }
546252
public function process(ContainerBuilder $container)
    {
        // First collect all alias targets that need to be replaced
        $seenAliasTargets = [];
        $replacements = [];
        foreach ($container->getAliases() as $definitionId => $target) {
            $targetId = (string) $target;
            // Special case: leave this target alone
            if ('service_container' === $targetId) {
                continue;
            }
            // Check if target needs to be replaces
            if (isset($replacements[$targetId])) {
                $container->setAlias($definitionId, $replacements[$targetId])->setPublic($target->isPublic())->setPrivate($target->isPrivate());
            }
            // No need to process the same target twice
            if (isset($seenAliasTargets[$targetId])) {
                continue;
            }
            // Process new target
            $seenAliasTargets[$targetId] = true;
            try {
                $definition = $container->getDefinition($targetId);
            } catch (ServiceNotFoundException $e) {
                if ('' !== $e->getId() && '@' === $e->getId()[0]) {
                    throw new ServiceNotFoundException($e->getId(), $e->getSourceId(), null, [substr($e->getId(), 1)]);
                }

                throw $e;
            }
            if ($definition->isPublic()) {
                continue;
            }
            // Remove private definition and schedule for replacement
            $definition->setPublic(!$target->isPrivate());
            $definition->setPrivate($target->isPrivate());
            $container->setDefinition($definitionId, $definition);
            $container->removeDefinition($targetId);
            $replacements[$targetId] = $definitionId;
        }
        $this->replacements = $replacements;

        parent::process($container);
        $this->replacements = [];
    }