master

laravel/framework

Last updated at: 29/12/2023 09:24

ParallelConsoleOutput.php

TLDR

The file ParallelConsoleOutput.php defines a class called ParallelConsoleOutput that extends the ConsoleOutput class from the Symfony Console component. This class adds functionality to filter and ignore specific output messages when writing to the console.

Classes

ParallelConsoleOutput

The ParallelConsoleOutput class extends the ConsoleOutput class and provides a mechanism to filter and ignore specific output messages. It has the following properties and methods:

Properties

  • $output: Holds the original output instance of type \Symfony\Component\Console\Output\OutputInterface.
  • $ignore: An array of output messages that should be ignored.

Methods

  • __construct($output): Constructor method that creates a new ParallelConsoleOutput instance. It accepts an instance of OutputInterface and calls the parent constructor while also storing the original output instance.
  • write($messages, bool $newline = false, int $options = 0): Writes a message or a collection of messages to the output. It filters the messages to exclude any that contain the strings specified in the $ignore property and then calls the write method of the original output instance with the filtered messages.
<?php

namespace Illuminate\Testing;

use Illuminate\Support\Str;
use Symfony\Component\Console\Output\ConsoleOutput;

class ParallelConsoleOutput extends ConsoleOutput
{
    /**
     * The original output instance.
     *
     * @var \Symfony\Component\Console\Output\OutputInterface
     */
    protected $output;

    /**
     * The output that should be ignored.
     *
     * @var array
     */
    protected $ignore = [
        'Running phpunit in',
        'Configuration read from',
    ];

    /**
     * Create a new Parallel ConsoleOutput instance.
     *
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @return void
     */
    public function __construct($output)
    {
        parent::__construct(
            $output->getVerbosity(),
            $output->isDecorated(),
            $output->getFormatter(),
        );

        $this->output = $output;
    }

    /**
     * Writes a message to the output.
     *
     * @param  string|iterable  $messages
     * @param  bool  $newline
     * @param  int  $options
     * @return void
     */
    public function write($messages, bool $newline = false, int $options = 0): void
    {
        $messages = collect($messages)->filter(function ($message) {
            return ! Str::contains($message, $this->ignore);
        });

        $this->output->write($messages->toArray(), $newline, $options);
    }
}