Вход Регистрация
Файл: vendor/laravel/tinker/src/Console/TinkerCommand.php
Строк: 192
<?php

namespace LaravelTinkerConsole;

use 
IlluminateConsoleCommand;
use 
IlluminateSupportEnv;
use 
LaravelTinkerClassAliasAutoloader;
use 
PsyConfiguration;
use 
PsyShell;
use 
PsyVersionUpdaterChecker;
use 
SymfonyComponentConsoleInputInputArgument;
use 
SymfonyComponentConsoleInputInputOption;

class 
TinkerCommand extends Command
{
    
/**
     * Artisan commands to include in the tinker shell.
     *
     * @var array
     */
    
protected $commandWhitelist = [
        
'clear-compiled''down''env''inspire''migrate''migrate:install''optimize''up',
    ];

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

    
/**
     * The console command description.
     *
     * @var string
     */
    
protected $description 'Interact with your application';

    
/**
     * Execute the console command.
     *
     * @return int
     */
    
public function handle()
    {
        
$this->getApplication()->setCatchExceptions(false);

        
$config Configuration::fromInput($this->input);
        
$config->setUpdateCheck(Checker::NEVER);

        
$config->getPresenter()->addCasters(
            
$this->getCasters()
        );

        if (
$this->option('execute')) {
            
$config->setRawOutput(true);
        }

        
$shell = new Shell($config);
        
$shell->addCommands($this->getCommands());
        
$shell->setIncludes($this->argument('include'));

        
$path Env::get('COMPOSER_VENDOR_DIR'$this->getLaravel()->basePath().DIRECTORY_SEPARATOR.'vendor');

        
$path .= '/composer/autoload_classmap.php';

        
$config $this->getLaravel()->make('config');

        
$loader ClassAliasAutoloader::register(
            
$shell$path$config->get('tinker.alias', []), $config->get('tinker.dont_alias', [])
        );

        if (
$code $this->option('execute')) {
            try {
                
$shell->setOutput($this->output);
                
$shell->execute($code);
            } finally {
                
$loader->unregister();
            }

            return 
0;
        }

        try {
            return 
$shell->run();
        } finally {
            
$loader->unregister();
        }
    }

    
/**
     * Get artisan commands to pass through to PsySH.
     *
     * @return array
     */
    
protected function getCommands()
    {
        
$commands = [];

        foreach (
$this->getApplication()->all() as $name => $command) {
            if (
in_array($name$this->commandWhitelist)) {
                
$commands[] = $command;
            }
        }

        
$config $this->getLaravel()->make('config');

        foreach (
$config->get('tinker.commands', []) as $command) {
            
$commands[] = $this->getApplication()->add(
                
$this->getLaravel()->make($command)
            );
        }

        return 
$commands;
    }

    
/**
     * Get an array of Laravel tailored casters.
     *
     * @return array
     */
    
protected function getCasters()
    {
        
$casters = [
            
'IlluminateSupportCollection' => 'LaravelTinkerTinkerCaster::castCollection',
            
'IlluminateSupportHtmlString' => 'LaravelTinkerTinkerCaster::castHtmlString',
            
'IlluminateSupportStringable' => 'LaravelTinkerTinkerCaster::castStringable',
        ];

        if (
class_exists('IlluminateDatabaseEloquentModel')) {
            
$casters['IlluminateDatabaseEloquentModel'] = 'LaravelTinkerTinkerCaster::castModel';
        }

        if (
class_exists('IlluminateFoundationApplication')) {
            
$casters['IlluminateFoundationApplication'] = 'LaravelTinkerTinkerCaster::castApplication';
        }

        
$config $this->getLaravel()->make('config');

        return 
array_merge($casters, (array) $config->get('tinker.casters', []));
    }

    
/**
     * Get the console command arguments.
     *
     * @return array
     */
    
protected function getArguments()
    {
        return [
            [
'include'InputArgument::IS_ARRAY'Include file(s) before starting tinker'],
        ];
    }

    
/**
     * Get the console command options.
     *
     * @return array
     */
    
protected function getOptions()
    {
        return [
            [
'execute'nullInputOption::VALUE_OPTIONAL'Execute the given code using Tinker'],
        ];
    }
}
Онлайн: 1
Реклама