CoreFiles by mySites.guru
SingleCommandApplication.php72 lines, 1,798 bytes, from Joomla_6.1.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 6.1.0-alpha1
md5
909276c83e86bcf1644e08f719681019
sha1
9a52be52391b4094679db2c1abda653bb9dbf9aa
sha256
dd6e681bd1365856e290b413c78ab31fbee5d0487e0ee6b358fe870e50a9cde4
<?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;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author GrĂ©goire Pineau <[email protected]>
 */
class SingleCommandApplication extends Command
{
    private string $version = 'UNKNOWN';
    private bool $autoExit = true;
    private bool $running = false;

    /**
     * @return $this
     */
    public function setVersion(string $version): static
    {
        $this->version = $version;

        return $this;
    }

    /**
     * @final
     *
     * @return $this
     */
    public function setAutoExit(bool $autoExit): static
    {
        $this->autoExit = $autoExit;

        return $this;
    }

    public function run(?InputInterface $input = null, ?OutputInterface $output = null): int
    {
        if ($this->running) {
            return parent::run($input, $output);
        }

        // We use the command name as the application name
        $application = new Application($this->getName() ?: 'UNKNOWN', $this->version);
        $application->setAutoExit($this->autoExit);
        // Fix the usage of the command displayed with "--help"
        $this->setName($_SERVER['argv'][0]);
        $application->addCommand($this);
        $application->setDefaultCommand($this->getName(), true);

        $this->running = true;
        try {
            $ret = $application->run($input, $output);
        } finally {
            $this->running = false;
        }

        return $ret;
    }
}

The same content is in 30 releases, Joomla 6.1.0-alpha2 to 6.2.1-rc1. See them all, or every version of this file.