HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: //home/cca63905/www/nueva/vendor/sensio/framework-extra-bundle/Request/ArgumentNameConverter.php
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sensio\Bundle\FrameworkExtraBundle\Request;

use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactoryInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;

/**
 * @author Ryan Weaver <ryan@knpuniversity.com>
 */
class ArgumentNameConverter
{
    private $argumentMetadataFactory;

    public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory)
    {
        $this->argumentMetadataFactory = $argumentMetadataFactory;
    }

    /**
     * Returns an associative array of the controller arguments for the event.
     *
     * @param FilterControllerArgumentsEvent $event
     *
     * @return array
     */
    public function getControllerArguments(FilterControllerArgumentsEvent $event)
    {
        $namedArguments = $event->getRequest()->attributes->all();
        $argumentMetadatas = $this->argumentMetadataFactory->createArgumentMetadata($event->getController());
        $controllerArguments = $event->getArguments();

        foreach ($argumentMetadatas as $index => $argumentMetadata) {
            if ($argumentMetadata->isVariadic()) {
                // set the rest of the arguments as this arg's value
                $namedArguments[$argumentMetadata->getName()] = \array_slice($controllerArguments, $index);

                break;
            }

            if (!\array_key_exists($index, $controllerArguments)) {
                throw new \LogicException(sprintf('Could not find an argument value for argument %d of the controller.', $index));
            }

            $namedArguments[$argumentMetadata->getName()] = $controllerArguments[$index];
        }

        return $namedArguments;
    }
}