Process the Container to replace aliases with service definitions.

@throws InvalidArgumentException if the service definition does not exist
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 = [];
    }
245400
public function alias(string $locator, string ...$aliases): Aliased
    {
        if (\count($aliases) === 0) {
            $error = 'The number of aliases should be greater than zero';
            throw new InvalidArgumentException($error);
        }

        if (! $this->has($locator)) {
            $error = 'Could not to define an alias, because service %s is not defined in the container';
            throw new ContainerResolutionException(\sprintf($error, $locator));
        }

        foreach ($aliases as $alias) {
            $this->aliases[$alias] = $locator;
        }

        return $this;
    }
560262
public function moveAll()
    {
        try {
            if (!$this->hasRequestParameter('ids')) {
                throw new InvalidArgumentException('Resource ids must be specified.');
            }
            $ids = [];

            foreach ($this->getRequestParameter('ids') as $id) {
                $ids[] = $id['id'];
            }

            $this->validateInstancesRoot($ids);

            if (empty($ids)) {
                throw new InvalidArgumentException('No instances specified.');
            }

            $this->signatureValidator->checkSignatures(
                $this->getRequestParameter('ids')
            );

            $this->validateMoveRequest();

            $response = $this->moveAllInstances($ids);
            $this->returnJson($response);
        } catch (\InvalidArgumentException $e) {
            $this->returnJsonError($e->getMessage());
        }
    }
717822
public function process(ContainerBuilder $container)
    {
        $graph = $container->getCompiler()->getServiceReferenceGraph();

        $hasChanged = false;
        foreach ($container->getDefinitions() as $id => $definition) {
            if ($definition->isPublic() || $definition->isPrivate()) {
                continue;
            }

            if ($graph->hasNode($id)) {
                $edges = $graph->getNode($id)->getInEdges();
                $referencingAliases = array();
                $sourceIds = array();
                foreach ($edges as $edge) {
                    if ($edge->isWeak()) {
                        continue;
                    }
                    $node = $edge->getSourceNode();
                    $sourceIds[] = $node->getId();

                    if ($node->isAlias()) {
                        $referencingAliases[] = $node->getValue();
                    }
                }
                $isReferenced = (count(array_unique($sourceIds)) - count($referencingAliases)) > 0;
            } else {
                $referencingAliases = array();
                $isReferenced = false;
            }

            if (1 === count($referencingAliases) && false === $isReferenced) {
                $container->setDefinition((string) reset($referencingAliases), $definition);
                $definition->setPublic(!$definition->isPrivate());
                $definition->setPrivate(reset($referencingAliases)->isPrivate());
                $container->removeDefinition($id);
                $container->log($this, sprintf('Removed service "%s"; reason: replaces alias %s.', $id, reset($referencingAliases)));
            } elseif (0 === count($referencingAliases) && false === $isReferenced) {
                $container->removeDefinition($id);
                $container->resolveEnvPlaceholders(serialize($definition));
                $container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
                $hasChanged = true;
            }
        }

        if ($hasChanged) {
            $this->repeatedPass->setRepeat();
        }
    }
1352972
public function process(ContainerBuilder $container)
    {
        $services = [];
        $finder = Finder::create()
                        ->files()
                        ->in(Graviton::getBundleScanDir())
                        ->path('/\/analytics\//i')
                        ->name('*.json')
                        ->notName('_*')
                        ->notName('*.pipeline.*')
                        ->sortByName();

        foreach ($finder as $file) {
            $key = $file->getFilename();
            $data = json_decode($file->getContents(), true);
            if (json_last_error()) {
                throw new InvalidConfigurationException(
                    sprintf('Analytics file: %s could not be loaded due to error: %s', $key, json_last_error_msg())
                );
            }

            if (isset($data['route']) && !empty($data['route'])) {
                $services[$data['route']] = $data;
            } else {
                $services[] = $data;
            }
        }

        $container->setParameter('analytics.services', $services);
    }
921931
public function process(ContainerBuilder $container)
    {
        try {
            $this->enableExpressionProcessing();
            $this->container = $container;
            $connectedIds = [];
            $aliases = $container->getAliases();

            foreach ($aliases as $id => $alias) {
                if ($alias->isPublic()) {
                    $this->connectedIds[] = (string) $aliases[$id];
                }
            }

            foreach ($container->getDefinitions() as $id => $definition) {
                if ($definition->isPublic()) {
                    $connectedIds[$id] = true;
                    $this->processValue($definition);
                }
            }

            while ($this->connectedIds) {
                $ids = $this->connectedIds;
                $this->connectedIds = [];
                foreach ($ids as $id) {
                    if (!isset($connectedIds[$id]) && $container->hasDefinition($id)) {
                        $connectedIds[$id] = true;
                        $this->processValue($container->getDefinition($id));
                    }
                }
            }

            foreach ($container->getDefinitions() as $id => $definition) {
                if (!isset($connectedIds[$id])) {
                    $container->removeDefinition($id);
                    $container->resolveEnvPlaceholders(!$definition->hasErrors() ? serialize($definition) : $definition);
                    $container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
                }
            }
        } finally {
            $this->container = null;
            $this->connectedIds = [];
        }
    }
680361
public function process(ContainerBuilder $container)
    {
        foreach ($container->getDefinitions() as $id => $definition) {
            if ($definition->isAbstract()) {
                $container->removeDefinition($id);
                $container->log($this, sprintf('Removed service "%s"; reason: abstract.', $id));
            }
        }
    }
17091
@SuppressWarnings("unchecked")
    protected void processInitialCollectorManagerServices() throws InvalidSyntaxException {
        ServiceReference<CollectorManager>[] servRefs = (ServiceReference<CollectorManager>[])
                        bundleContext.getServiceReferences(CollectorManager.class.getName(), null);

        if (servRefs != null) {
            for (ServiceReference<CollectorManager> servRef : servRefs) {
            	setCollectorManagerPipeline(servRef);
            }
        }
    }
596920
public function process(ContainerBuilder $container)
    {
        foreach ($container->findTaggedServiceIds($this->baseTag) as $id => $services) {
            foreach ((array) $services as $service) {
                $this->findAndReplaceTaggedServices($id, $service, $container);
            }
        }
    }
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]);
    }
1236917
public function handleChangeDir(string $dir = null): void
	{
		if ($dir !== null) {
			if (
				strpos($dir, '..' . DIRECTORY_SEPARATOR) !== false
				|| !is_dir($this->getBasePath() . $dir)
			) {
				throw new InvalidArgumentException;
			}
		}
		$this->path = $dir;
		$this->redrawControl('fileManagerContainer');
	}
422473
public function process(ContainerBuilder $container)
    {
        // 1. Register custom repositories with Aggregate repository
        $aggregateRepositoryDefinition = $container->findDefinition(static::$aggregateRepositoryId);
        $customRepositoryTags = $container->findTaggedServiceIds(static::$customRepositoryTag);
        $customRepositoryReferences = [];

        foreach (array_keys($customRepositoryTags) as $id) {
            $customRepositoryReferences[] = new Reference($id);
        }

        $aggregateRepositoryDefinition->replaceArgument(1, $customRepositoryReferences);

        $topEzRepositoryAlias = $container->getAlias(static::$topEzRepositoryAliasId);

        // 2. Re-link eZ Platform's public top Repository alias
        $container->setAlias(static::$renamedTopEzRepositoryAliasId, (string)$topEzRepositoryAlias);

        // 3. Overwrite eZ Platform's public top Repository alias
        // to aggregate Repository implementation
        $container->setAlias(static::$topEzRepositoryAliasId, static::$aggregateRepositoryId);
    }
1216573
private function addServices()
    {
        if (!$this->container->getDefinitions()) {
            return '';
        }

        $code = "services:\n";
        foreach ($this->container->getDefinitions() as $id => $definition) {
            $code .= $this->addService($id, $definition);
        }

        $aliases = $this->container->getAliases();
        foreach ($aliases as $alias => $id) {
            while (isset($aliases[(string) $id])) {
                $id = $aliases[(string) $id];
            }
            $code .= $this->addServiceAlias($alias, $id);
        }

        return $code;
    }
663406
public function process(ContainerBuilder $container)
    {
        foreach ($container->getDefinitions() as $definition) {
            $interfaces = class_implements($definition->getClass());
            foreach ($interfaces as $interface) {
                if (substr($interface, -14) === 'AwareInterface') {
                    $camelCasedServiceId = substr($interface, strrpos($interface, '\\') + 1, -14);
                    $serviceId = Container::underscore($camelCasedServiceId);

                    if ($container->has($serviceId)) {
                        $setterMethod = 'set'.$camelCasedServiceId;

                        $definition->addMethodCall($setterMethod, array(new Reference($serviceId)));
                    }
                }
            }
        }
    }
1267569
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition($this->pathReducerService)) {
            return;
        }

        if (!$pathReducers = $this->findTaggedServices($container, $this->pathReducerTag, PluginInterface::class, 'getName')) {
            throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->pathReducerTag, $this->pathReducerService));
        }

        $pathReducerDefinition = $container->getDefinition($this->pathReducerService);
        $pathReducerDefinition->replaceArgument(0, $pathReducers);
    }
1233659
@Override
    public void preprocess(ServiceModel serviceModel) {

        if (renameShapes == null || renameShapes.isEmpty()) return;
        // sanity check
        for (Entry<String, String> entry : renameShapes.entrySet()) {

            String originalName = entry.getKey();
            String newName = entry.getValue();
            Shape originalShape = serviceModel.getShapes().get(originalName);

            if (originalShape == null) {
                throw new IllegalStateException(
                        String.format("Cannot find shape [%s] in the model when processing "
                                + "customization config renameShapes.%s", originalName, originalName));
            }
            if (serviceModel.getShapes().containsKey(newName)) {
                throw new IllegalStateException(
                        String.format("The shape [%s] for the new name is already in the model when processing "
                                + "customization config renameShapes.%s", newName, originalName));
            }
        }

        for (Entry<String, Shape> entry : serviceModel.getShapes().entrySet()) {
            String shapeName = entry.getKey();
            Shape shape = entry.getValue();

            preprocess_RenameMemberShapes(shapeName, shape);
        }
        for (Operation operation : serviceModel.getOperations().values()) {

            if (operation.getInput() != null) {
                preprocess_RenameInputShape(operation.getInput());
            }
            if (operation.getOutput() != null) {
                preprocess_RenameOutputShape(operation.getOutput());
            }
            if (operation.getErrors() != null) {
                for (ErrorMap error : operation.getErrors()) {
                    preprocess_RenameErrorShape(error);
                }
            }
        }
        for (Entry<String, String> entry : renameShapes.entrySet()) {
            String originalName = entry.getKey();
            String newName = entry.getValue();

            Shape shape = serviceModel.getShapes().remove(originalName);
            serviceModel.getShapes().put(newName, shape);
        }
    }
1277211
public function process(ContainerBuilder $container)
    {
        $taggedServices = $container->findTaggedServiceIds(
            self::TAG_NAME
        );

        foreach ($taggedServices as $id => $tag) {
            $definition = $container->findDefinition($id);

            $this->processTag($tag, $definition);
        }
    }