Вход Регистрация
Файл: gapps/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php
Строк: 348
<?php

namespace IlluminateFoundationConsole;

use 
Exception;
use 
Throwable;
use 
IlluminateContractsEventsDispatcher;
use 
IlluminateConsoleSchedulingSchedule;
use 
IlluminateConsoleApplication as Artisan;
use 
IlluminateContractsFoundationApplication;
use 
IlluminateContractsConsoleKernel as KernelContract;
use 
SymfonyComponentDebugExceptionFatalThrowableError;

class 
Kernel implements KernelContract
{
    
/**
     * The application implementation.
     *
     * @var IlluminateContractsFoundationApplication
     */
    
protected $app;

    
/**
     * The event dispatcher implementation.
     *
     * @var IlluminateContractsEventsDispatcher
     */
    
protected $events;

    
/**
     * The Artisan application instance.
     *
     * @var IlluminateConsoleApplication
     */
    
protected $artisan;

    
/**
     * The Artisan commands provided by the application.
     *
     * @var array
     */
    
protected $commands = [];

    
/**
     * The bootstrap classes for the application.
     *
     * @var array
     */
    
protected $bootstrappers = [
        
'IlluminateFoundationBootstrapDetectEnvironment',
        
'IlluminateFoundationBootstrapLoadConfiguration',
        
'IlluminateFoundationBootstrapConfigureLogging',
        
'IlluminateFoundationBootstrapHandleExceptions',
        
'IlluminateFoundationBootstrapRegisterFacades',
        
'IlluminateFoundationBootstrapSetRequestForConsole',
        
'IlluminateFoundationBootstrapRegisterProviders',
        
'IlluminateFoundationBootstrapBootProviders',
    ];

    
/**
     * Create a new console kernel instance.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @param  IlluminateContractsEventsDispatcher  $events
     * @return void
     */
    
public function __construct(Application $appDispatcher $events)
    {
        if (! 
defined('ARTISAN_BINARY')) {
            
define('ARTISAN_BINARY''artisan');
        }

        
$this->app $app;
        
$this->events $events;

        
$this->app->booted(function () {
            
$this->defineConsoleSchedule();
        });
    }

    
/**
     * Define the application's command schedule.
     *
     * @return void
     */
    
protected function defineConsoleSchedule()
    {
        
$this->app->instance(
            
'IlluminateConsoleSchedulingSchedule'$schedule = new Schedule
        
);

        
$this->schedule($schedule);
    }

    
/**
     * Run the console application.
     *
     * @param  SymfonyComponentConsoleInputInputInterface  $input
     * @param  SymfonyComponentConsoleOutputOutputInterface  $output
     * @return int
     */
    
public function handle($input$output null)
    {
        try {
            
$this->bootstrap();

            return 
$this->getArtisan()->run($input$output);
        } catch (
Exception $e) {
            
$this->reportException($e);

            
$this->renderException($output$e);

            return 
1;
        } catch (
Throwable $e) {
            
$e = new FatalThrowableError($e);

            
$this->reportException($e);

            
$this->renderException($output$e);

            return 
1;
        }
    }

    
/**
     * Terminate the application.
     *
     * @param  SymfonyComponentConsoleInputInputInterface  $input
     * @param  int  $status
     * @return void
     */
    
public function terminate($input$status)
    {
        
$this->app->terminate();
    }

    
/**
     * Define the application's command schedule.
     *
     * @param  IlluminateConsoleSchedulingSchedule  $schedule
     * @return void
     */
    
protected function schedule(Schedule $schedule)
    {
        
//
    
}

    
/**
     * Register the given command with the console application.
     *
     * @param  SymfonyComponentConsoleCommandCommand  $command
     * @return void
     */
    
public function registerCommand($command)
    {
        
$this->getArtisan()->add($command);
    }

    
/**
     * Run an Artisan console command by name.
     *
     * @param  string  $command
     * @param  array  $parameters
     * @return int
     */
    
public function call($command, array $parameters = [])
    {
        
$this->bootstrap();

        return 
$this->getArtisan()->call($command$parameters);
    }

    
/**
     * Queue the given console command.
     *
     * @param  string  $command
     * @param  array   $parameters
     * @return void
     */
    
public function queue($command, array $parameters = [])
    {
        
$this->app['IlluminateContractsQueueQueue']->push(
            
'IlluminateFoundationConsoleQueuedJob'func_get_args()
        );
    }

    
/**
     * Get all of the commands registered with the console.
     *
     * @return array
     */
    
public function all()
    {
        
$this->bootstrap();

        return 
$this->getArtisan()->all();
    }

    
/**
     * Get the output for the last run command.
     *
     * @return string
     */
    
public function output()
    {
        
$this->bootstrap();

        return 
$this->getArtisan()->output();
    }

    
/**
     * Bootstrap the application for artisan commands.
     *
     * @return void
     */
    
public function bootstrap()
    {
        if (! 
$this->app->hasBeenBootstrapped()) {
            
$this->app->bootstrapWith($this->bootstrappers());
        }

        
// If we are calling an arbitrary command from within the application, we'll load
        // all of the available deferred providers which will make all of the commands
        // available to an application. Otherwise the command will not be available.
        
$this->app->loadDeferredProviders();
    }

    
/**
     * Get the Artisan application instance.
     *
     * @return IlluminateConsoleApplication
     */
    
protected function getArtisan()
    {
        if (
is_null($this->artisan)) {
            return 
$this->artisan = (new Artisan($this->app$this->events$this->app->version()))
                                ->
resolveCommands($this->commands);
        }

        return 
$this->artisan;
    }

    
/**
     * Get the bootstrap classes for the application.
     *
     * @return array
     */
    
protected function bootstrappers()
    {
        return 
$this->bootstrappers;
    }

    
/**
     * Report the exception to the exception handler.
     *
     * @param  Exception  $e
     * @return void
     */
    
protected function reportException(Exception $e)
    {
        
$this->app['IlluminateContractsDebugExceptionHandler']->report($e);
    }

    
/**
     * Report the exception to the exception handler.
     *
     * @param  SymfonyComponentConsoleOutputOutputInterface  $output
     * @param  Exception  $e
     * @return void
     */
    
protected function renderException($outputException $e)
    {
        
$this->app['IlluminateContractsDebugExceptionHandler']->renderForConsole($output$e);
    }
}
Онлайн: 1
Реклама