SplPriorityQueue example

/** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (false === $container->hasDefinition('profiler')) {
            return;
        }

        $definition = $container->getDefinition('profiler');

        $collectors = new \SplPriorityQueue();
        $order = \PHP_INT_MAX;
        foreach ($container->findTaggedServiceIds('data_collector', true) as $id => $attributes) {
            $priority = $attributes[0]['priority'] ?? 0;
            $template = null;

            $collectorClass = $container->findDefinition($id)->getClass();
            if (isset($attributes[0]['template']) || is_subclass_of($collectorClass, TemplateAwareDataCollectorInterface::class)) {
                $idForTemplate = $attributes[0]['id'] ?? $collectorClass;
                if (!$idForTemplate) {
                    throw new InvalidArgumentException(sprintf('Data collector service "%s" must have an id attribute in order to specify a template.', $id));
                }
                
/** * Finds all services with the given tag name and order them by their priority. * * @param string $tagName * * @return Reference[] */
    private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
    {
        $services = $container->findTaggedServiceIds($tagName);

        $queue = new SplPriorityQueue();

        foreach ($services as $serviceId => $tags) {
            foreach ($tags as $attributes) {
                $priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
                $queue->insert(new Reference($serviceId)$priority);
            }
        }

        return iterator_to_array($queue, false);
    }
}

class DecoratorServicePass extends AbstractRecursivePass
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $definitions = new \SplPriorityQueue();
        $order = \PHP_INT_MAX;

        foreach ($container->getDefinitions() as $id => $definition) {
            if (!$decorated = $definition->getDecoratedService()) {
                continue;
            }
            $definitions->insert([$id$definition][$decorated[2], --$order]);
        }
        $decoratingDefinitions = [];
        $decoratedIds = [];

        

class DecoratorServicePass extends AbstractRecursivePass
{
    protected bool $skipScalars = true;

    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $definitions = new \SplPriorityQueue();
        $order = \PHP_INT_MAX;

        foreach ($container->getDefinitions() as $id => $definition) {
            if (!$decorated = $definition->getDecoratedService()) {
                continue;
            }
            $definitions->insert([$id$definition][$decorated[2], --$order]);
        }
        $decoratingDefinitions = [];
        $decoratedIds = [];

        
Home | Imprint | This part of the site doesn't use cookies.