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

namespace IlluminateConsole;

use 
IlluminateConsoleContractsNewLineAware;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleOutputOutputInterface;
use 
SymfonyComponentConsoleQuestionQuestion;
use 
SymfonyComponentConsoleStyleSymfonyStyle;

class 
OutputStyle extends SymfonyStyle implements NewLineAware
{
    
/**
     * The output instance.
     *
     * @var SymfonyComponentConsoleOutputOutputInterface
     */
    
private $output;

    
/**
     * The number of trailing new lines written by the last output.
     *
     * This is initialized as 1 to account for the new line written by the shell after executing a command.
     *
     * @var int
     */
    
protected $newLinesWritten 1;

    
/**
     * If the last output written wrote a new line.
     *
     * @var bool
     *
     * @deprecated use $newLinesWritten
     */
    
protected $newLineWritten false;

    
/**
     * Create a new Console OutputStyle instance.
     *
     * @param  SymfonyComponentConsoleInputInputInterface  $input
     * @param  SymfonyComponentConsoleOutputOutputInterface  $output
     * @return void
     */
    
public function __construct(InputInterface $inputOutputInterface $output)
    {
        
$this->output $output;

        
parent::__construct($input$output);
    }

    
/**
     * {@inheritdoc}
     */
    
public function askQuestion(Question $question): mixed
    
{
        try {
            return 
parent::askQuestion($question);
        } finally {
            
$this->newLinesWritten++;
        }
    }

    
/**
     * {@inheritdoc}
     */
    
public function write(string|iterable $messagesbool $newline falseint $options 0)
    {
        
$this->newLinesWritten $this->trailingNewLineCount($messages) + (int) $newline;
        
$this->newLineWritten $this->newLinesWritten 0;

        
parent::write($messages$newline$options);
    }

    
/**
     * {@inheritdoc}
     *
     * @return void
     */
    
public function writeln(string|iterable $messagesint $type self::OUTPUT_NORMAL)
    {
        
$this->newLinesWritten $this->trailingNewLineCount($messages) + 1;
        
$this->newLineWritten true;

        
parent::writeln($messages$type);
    }

    
/**
     * {@inheritdoc}
     *
     * @return void
     */
    
public function newLine(int $count 1)
    {
        
$this->newLinesWritten += $count;
        
$this->newLineWritten $this->newLinesWritten 0;

        
parent::newLine($count);
    }

    
/**
     * {@inheritdoc}
     */
    
public function newLinesWritten()
    {
        if (
$this->output instanceof static) {
            return 
$this->output->newLinesWritten();
        }

        return 
$this->newLinesWritten;
    }

    
/**
     * {@inheritdoc}
     *
     * @deprecated use newLinesWritten
     */
    
public function newLineWritten()
    {
        if (
$this->output instanceof static && $this->output->newLineWritten()) {
            return 
true;
        }

        return 
$this->newLineWritten;
    }

    
/*
     * Count the number of trailing new lines in a string.
     *
     * @param  string|iterable  $messages
     * @return int
     */
    
protected function trailingNewLineCount($messages)
    {
        if (
is_iterable($messages)) {
            
$string '';

            foreach (
$messages as $message) {
                
$string .= $message.PHP_EOL;
            }
        } else {
            
$string $messages;
        }

        return 
strlen($string) - strlen(rtrim($stringPHP_EOL));
    }

    
/**
     * Returns whether verbosity is quiet (-q).
     *
     * @return bool
     */
    
public function isQuiet(): bool
    
{
        return 
$this->output->isQuiet();
    }

    
/**
     * Returns whether verbosity is verbose (-v).
     *
     * @return bool
     */
    
public function isVerbose(): bool
    
{
        return 
$this->output->isVerbose();
    }

    
/**
     * Returns whether verbosity is very verbose (-vv).
     *
     * @return bool
     */
    
public function isVeryVerbose(): bool
    
{
        return 
$this->output->isVeryVerbose();
    }

    
/**
     * Returns whether verbosity is debug (-vvv).
     *
     * @return bool
     */
    
public function isDebug(): bool
    
{
        return 
$this->output->isDebug();
    }

    
/**
     * Get the underlying Symfony output implementation.
     *
     * @return SymfonyComponentConsoleOutputOutputInterface
     */
    
public function getOutput()
    {
        return 
$this->output;
    }
}
Онлайн: 2
Реклама