CoreFiles by mySites.guru
Interaction.php51 lines, 1,690 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
0abcc902907273bff6f58fa1ed868a1d
sha1
a329b7d6a0613e565bfc781c3ad272b8c4ad04b8
sha256
2a19638351ee890eedaa8a4a6c72385ae06eedd6820e0a84be39a336f2c07e0c
<?php

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

namespace Symfony\Component\Console\Interaction;

use Symfony\Component\Console\Attribute\InteractiveAttributeInterface;
use Symfony\Component\Console\Attribute\MapInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @internal
 */
final class Interaction
{
    public function __construct(
        private readonly object $owner,
        private readonly InteractiveAttributeInterface $attribute,
    ) {
    }

    /**
     * @param \Closure(\ReflectionFunction $function, InputInterface $input, OutputInterface $output): array $parameterResolver
     */
    public function interact(InputInterface $input, OutputInterface $output, \Closure $parameterResolver): void
    {
        if ($this->owner instanceof MapInput) {
            $function = $this->attribute->getFunction($this->owner->resolveValue($input));
            $function->invoke(...$parameterResolver($function, $input, $output));
            $this->owner->setValue($input, $function->getClosureThis());

            return;
        }

        $function = $this->attribute->getFunction($this->owner);
        $function->invoke(...$args = $parameterResolver($function, $input, $output));
        foreach ($function->getParameters() as $i => $parameter) {
            if (\is_object($args[$i]) && $spec = MapInput::tryFrom($parameter)) {
                $spec->setValue($input, $args[$i]);
            }
        }
    }
}

The same content is in 32 releases, Joomla 6.1.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.