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

namespace IlluminateFoundationConsole;

use 
Closure;
use 
IlluminateConsoleCommand;
use 
IlluminateConsoleManuallyFailedException;
use 
IlluminateSupportFacadesSchedule;
use 
IlluminateSupportTraitsForwardsCalls;
use 
ReflectionFunction;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleOutputOutputInterface;

/**
 * @mixin IlluminateConsoleSchedulingEvent
 */
class ClosureCommand extends Command
{
    use 
ForwardsCalls;

    
/**
     * The command callback.
     *
     * @var Closure
     */
    
protected $callback;

    
/**
     * The console command description.
     *
     * @var string
     */
    
protected $description '';

    
/**
     * Create a new command instance.
     *
     * @param  string  $signature
     * @param  Closure  $callback
     */
    
public function __construct($signatureClosure $callback)
    {
        
$this->callback $callback;
        
$this->signature $signature;

        
parent::__construct();
    }

    
/**
     * Execute the console command.
     *
     * @param  SymfonyComponentConsoleInputInputInterface  $input
     * @param  SymfonyComponentConsoleOutputOutputInterface  $output
     * @return int
     */
    
protected function execute(InputInterface $inputOutputInterface $output): int
    
{
        
$inputs array_merge($input->getArguments(), $input->getOptions());

        
$parameters = [];

        foreach ((new 
ReflectionFunction($this->callback))->getParameters() as $parameter) {
            if (isset(
$inputs[$parameter->getName()])) {
                
$parameters[$parameter->getName()] = $inputs[$parameter->getName()];
            }
        }

        try {
            return (int) 
$this->laravel->call(
                
$this->callback->bindTo($this$this), $parameters
            
);
        } catch (
ManuallyFailedException $e) {
            
$this->components->error($e->getMessage());

            return static::
FAILURE;
        }
    }

    
/**
     * Set the description for the command.
     *
     * @param  string  $description
     * @return $this
     */
    
public function purpose($description)
    {
        return 
$this->describe($description);
    }

    
/**
     * Set the description for the command.
     *
     * @param  string  $description
     * @return $this
     */
    
public function describe($description)
    {
        
$this->setDescription($description);

        return 
$this;
    }

    
/**
     * Create a new scheduled event for the command.
     *
     * @param  array  $parameters
     * @return IlluminateConsoleSchedulingEvent
     */
    
public function schedule($parameters = [])
    {
        return 
Schedule::command($this->name$parameters);
    }

    
/**
     * Dynamically proxy calls to a new scheduled event.
     *
     * @param  string  $method
     * @param  array  $parameters
     * @return mixed
     *
     * @throws BadMethodCallException
     */
    
public function __call($method$parameters)
    {
        return 
$this->forwardCallTo($this->schedule(), $method$parameters);
    }
}
Онлайн: 2
Реклама