Файл: gapps/vendor/laravel/framework/src/Illuminate/Console/Application.php
Строк: 307
<?php
namespace IlluminateConsole;
use IlluminateContractsEventsDispatcher;
use IlluminateContractsContainerContainer;
use SymfonyComponentConsoleInputArrayInput;
use SymfonyComponentConsoleInputInputOption;
use SymfonyComponentConsoleOutputBufferedOutput;
use SymfonyComponentConsoleApplication as SymfonyApplication;
use SymfonyComponentConsoleCommandCommand as SymfonyCommand;
use IlluminateContractsConsoleApplication as ApplicationContract;
class Application extends SymfonyApplication implements ApplicationContract
{
/**
* The Laravel application instance.
*
* @var IlluminateContractsContainerContainer
*/
protected $laravel;
/**
* The output from the previous command.
*
* @var SymfonyComponentConsoleOutputBufferedOutput
*/
protected $lastOutput;
/**
* Create a new Artisan console application.
*
* @param IlluminateContractsContainerContainer $laravel
* @param IlluminateContractsEventsDispatcher $events
* @param string $version
* @return void
*/
public function __construct(Container $laravel, Dispatcher $events, $version)
{
parent::__construct('Laravel Framework', $version);
$this->laravel = $laravel;
$this->setAutoExit(false);
$this->setCatchExceptions(false);
$events->fire(new EventsArtisanStarting($this));
}
/**
* Run an Artisan console command by name.
*
* @param string $command
* @param array $parameters
* @return int
*/
public function call($command, array $parameters = [])
{
$parameters = collect($parameters)->prepend($command);
$this->lastOutput = new BufferedOutput;
$this->setCatchExceptions(false);
$result = $this->run(new ArrayInput($parameters->toArray()), $this->lastOutput);
$this->setCatchExceptions(true);
return $result;
}
/**
* Get the output for the last run command.
*
* @return string
*/
public function output()
{
return $this->lastOutput ? $this->lastOutput->fetch() : '';
}
/**
* Add a command to the console.
*
* @param SymfonyComponentConsoleCommandCommand $command
* @return SymfonyComponentConsoleCommandCommand
*/
public function add(SymfonyCommand $command)
{
if ($command instanceof Command) {
$command->setLaravel($this->laravel);
}
return $this->addToParent($command);
}
/**
* Add the command to the parent instance.
*
* @param SymfonyComponentConsoleCommandCommand $command
* @return SymfonyComponentConsoleCommandCommand
*/
protected function addToParent(SymfonyCommand $command)
{
return parent::add($command);
}
/**
* Add a command, resolving through the application.
*
* @param string $command
* @return SymfonyComponentConsoleCommandCommand
*/
public function resolve($command)
{
return $this->add($this->laravel->make($command));
}
/**
* Resolve an array of commands through the application.
*
* @param array|mixed $commands
* @return $this
*/
public function resolveCommands($commands)
{
$commands = is_array($commands) ? $commands : func_get_args();
foreach ($commands as $command) {
$this->resolve($command);
}
return $this;
}
/**
* Get the default input definitions for the applications.
*
* This is used to add the --env option to every available command.
*
* @return SymfonyComponentConsoleInputInputDefinition
*/
protected function getDefaultInputDefinition()
{
$definition = parent::getDefaultInputDefinition();
$definition->addOption($this->getEnvironmentOption());
return $definition;
}
/**
* Get the global environment option for the definition.
*
* @return SymfonyComponentConsoleInputInputOption
*/
protected function getEnvironmentOption()
{
$message = 'The environment the command should run under.';
return new InputOption('--env', null, InputOption::VALUE_OPTIONAL, $message);
}
/**
* Get the Laravel application instance.
*
* @return IlluminateContractsFoundationApplication
*/
public function getLaravel()
{
return $this->laravel;
}
}