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

namespace IlluminateFoundationConsole;

use 
IlluminateFoundationConcernsResolvesDumpSource;
use 
SymfonyComponentConsoleOutputConsoleOutput;
use 
SymfonyComponentVarDumperCasterReflectionCaster;
use 
SymfonyComponentVarDumperClonerData;
use 
SymfonyComponentVarDumperClonerVarCloner;
use 
SymfonyComponentVarDumperDumperCliDumper as BaseCliDumper;
use 
SymfonyComponentVarDumperVarDumper;

class 
CliDumper extends BaseCliDumper
{
    use 
ResolvesDumpSource;

    
/**
     * The base path of the application.
     *
     * @var string
     */
    
protected $basePath;

    
/**
     * The output instance.
     *
     * @var SymfonyComponentConsoleOutputOutputInterface
     */
    
protected $output;

    
/**
     * The compiled view path for the application.
     *
     * @var string
     */
    
protected $compiledViewPath;

    
/**
     * If the dumper is currently dumping.
     *
     * @var bool
     */
    
protected $dumping false;

    
/**
     * Create a new CLI dumper instance.
     *
     * @param  SymfonyComponentConsoleOutputOutputInterface  $output
     * @param  string  $basePath
     * @param  string  $compiledViewPath
     * @return void
     */
    
public function __construct($output$basePath$compiledViewPath)
    {
        
parent::__construct();

        
$this->basePath $basePath;
        
$this->output $output;
        
$this->compiledViewPath $compiledViewPath;
    }

    
/**
     * Create a new CLI dumper instance and register it as the default dumper.
     *
     * @param  string  $basePath
     * @param  string  $compiledViewPath
     * @return void
     */
    
public static function register($basePath$compiledViewPath)
    {
        
$cloner tap(new VarCloner())->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);

        
$dumper = new static(new ConsoleOutput(), $basePath$compiledViewPath);

        
VarDumper::setHandler(fn ($value) => $dumper->dumpWithSource($cloner->cloneVar($value)));
    }

    
/**
     * Dump a variable with its source file / line.
     *
     * @param  SymfonyComponentVarDumperClonerData  $data
     * @return void
     */
    
public function dumpWithSource(Data $data)
    {
        if (
$this->dumping) {
            
$this->dump($data);

            return;
        }

        
$this->dumping true;

        
$output = (string) $this->dump($datatrue);
        
$lines explode("n"$output);

        
$lines[array_key_last($lines) - 1] .= $this->getDumpSourceContent();

        
$this->output->write(implode("n"$lines));

        
$this->dumping false;
    }

    
/**
     * Get the dump's source console content.
     *
     * @return string
     */
    
protected function getDumpSourceContent()
    {
        if (
is_null($dumpSource $this->resolveDumpSource())) {
            return 
'';
        }

        [
$file$relativeFile$line] = $dumpSource;

        
$href $this->resolveSourceHref($file$line);

        return 
sprintf(
            
' <fg=gray>// <fg=gray%s>%s%s</></>',
            
is_null($href) ? '' ";href=$href",
            
$relativeFile,
            
is_null($line) ? '' ":$line"
        
);
    }

    
/**
     * {@inheritDoc}
     */
    
protected function supportsColors(): bool
    
{
        return 
$this->output->isDecorated();
    }
}
Онлайн: 1
Реклама