Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BufferIO.php

class BufferIO

@author Jordi Boggiano <j.boggiano@seld.be>

Hierarchy

  • class \Composer\IO\BaseIO implements \Composer\IO\IOInterface
    • class \Composer\IO\ConsoleIO extends \Composer\IO\BaseIO
      • class \Composer\IO\BufferIO extends \Composer\IO\ConsoleIO

Expanded class hierarchy of BufferIO

2 files declare their use of BufferIO
DiagnoseCommand.php in vendor/composer/composer/src/Composer/Command/DiagnoseCommand.php
EventDispatcher.php in vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php

File

vendor/composer/composer/src/Composer/IO/BufferIO.php, line 28

Namespace

Composer\IO
View source
class BufferIO extends ConsoleIO {
    public function __construct(string $input = '', int $verbosity = StreamOutput::VERBOSITY_NORMAL, ?OutputFormatterInterface $formatter = null) {
        $input = new StringInput($input);
        $input->setInteractive(false);
        $stream = fopen('php://memory', 'rw');
        if ($stream === false) {
            throw new \RuntimeException('Unable to open memory output stream');
        }
        $output = new StreamOutput($stream, $verbosity, $formatter !== null ? $formatter->isDecorated() : false, $formatter);
        parent::__construct($input, $output, new HelperSet([
            new QuestionHelper(),
        ]));
    }
    
    /**
     * @return string output
     */
    public function getOutput() : string {
        assert($this->output instanceof StreamOutput);
        fseek($this->output
            ->getStream(), 0);
        $output = (string) stream_get_contents($this->output
            ->getStream());
        $output = Preg::replaceCallback("{(?<=^|\n|\x08)(.+?)(\x08+)}", static function ($matches) : string {
            $pre = strip_tags($matches[1]);
            if (strlen($pre) === strlen($matches[2])) {
                return '';
            }
            // TODO reverse parse the string, skipping span tags and \033\[([0-9;]+)m(.*?)\033\[0m style blobs
            return rtrim($matches[1]) . "\n";
        }, $output);
        return $output;
    }
    
    /**
     * @param string[] $inputs
     *
     * @see createStream
     */
    public function setUserInputs(array $inputs) : void {
        if (!$this->input instanceof StreamableInputInterface) {
            throw new \RuntimeException('Setting the user inputs requires at least the version 3.2 of the symfony/console component.');
        }
        $this->input
            ->setStream($this->createStream($inputs));
        $this->input
            ->setInteractive(true);
    }
    
    /**
     * @param string[] $inputs
     *
     * @return resource stream
     */
    private function createStream(array $inputs) {
        $stream = fopen('php://memory', 'r+');
        if ($stream === false) {
            throw new \RuntimeException('Unable to open memory output stream');
        }
        foreach ($inputs as $input) {
            fwrite($stream, $input . PHP_EOL);
        }
        rewind($stream);
        return $stream;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
BaseIO::$authentications protected property @var array&lt;string, array{username: string|null, password: string|null}&gt;
BaseIO::alert public function Overrides LoggerInterface::alert
BaseIO::checkAndSetAuthentication protected function Check for overwrite and set the authentication information for the repository.
BaseIO::critical public function Overrides LoggerInterface::critical
BaseIO::debug public function Overrides LoggerInterface::debug
BaseIO::emergency public function Overrides LoggerInterface::emergency
BaseIO::error public function Overrides LoggerInterface::error
BaseIO::getAuthentication public function @inheritDoc Overrides IOInterface::getAuthentication
BaseIO::getAuthentications public function @inheritDoc Overrides IOInterface::getAuthentications
BaseIO::hasAuthentication public function @inheritDoc Overrides IOInterface::hasAuthentication
BaseIO::info public function Overrides LoggerInterface::info
BaseIO::loadConfiguration public function @inheritDoc Overrides IOInterface::loadConfiguration
BaseIO::log public function Overrides LoggerInterface::log
BaseIO::notice public function Overrides LoggerInterface::notice
BaseIO::resetAuthentications public function
BaseIO::setAuthentication public function @inheritDoc Overrides IOInterface::setAuthentication
BaseIO::warning public function Overrides LoggerInterface::warning
BufferIO::createStream private function
BufferIO::getOutput public function
BufferIO::setUserInputs public function
BufferIO::__construct public function Constructor. Overrides ConsoleIO::__construct
ConsoleIO::$helperSet protected property @var HelperSet
ConsoleIO::$input protected property @var InputInterface
ConsoleIO::$lastMessage protected property @var string
ConsoleIO::$lastMessageErr protected property @var string
ConsoleIO::$output protected property @var OutputInterface
ConsoleIO::$startTime private property @var float
ConsoleIO::$verbosityMap private property @var array&lt;IOInterface::*, OutputInterface::VERBOSITY_*&gt;
ConsoleIO::ask public function @inheritDoc Overrides IOInterface::ask
ConsoleIO::askAndHideAnswer public function @inheritDoc Overrides IOInterface::askAndHideAnswer
ConsoleIO::askAndValidate public function @inheritDoc Overrides IOInterface::askAndValidate
ConsoleIO::askConfirmation public function @inheritDoc Overrides IOInterface::askConfirmation
ConsoleIO::doOverwrite private function
ConsoleIO::doWrite private function
ConsoleIO::enableDebugging public function
ConsoleIO::getErrorOutput private function
ConsoleIO::getProgressBar public function
ConsoleIO::getTable public function
ConsoleIO::isDebug public function @inheritDoc Overrides IOInterface::isDebug
ConsoleIO::isDecorated public function @inheritDoc Overrides IOInterface::isDecorated
ConsoleIO::isInteractive public function @inheritDoc Overrides IOInterface::isInteractive
ConsoleIO::isVerbose public function @inheritDoc Overrides IOInterface::isVerbose
ConsoleIO::isVeryVerbose public function @inheritDoc Overrides IOInterface::isVeryVerbose
ConsoleIO::overwrite public function @inheritDoc Overrides IOInterface::overwrite
ConsoleIO::overwriteError public function @inheritDoc Overrides IOInterface::overwriteError
ConsoleIO::select public function @inheritDoc Overrides IOInterface::select
ConsoleIO::write public function @inheritDoc Overrides IOInterface::write
ConsoleIO::writeError public function @inheritDoc Overrides IOInterface::writeError
ConsoleIO::writeErrorRaw public function @inheritDoc Overrides BaseIO::writeErrorRaw
ConsoleIO::writeRaw public function @inheritDoc Overrides BaseIO::writeRaw
IOInterface::DEBUG public constant
IOInterface::NORMAL public constant
IOInterface::QUIET public constant
IOInterface::VERBOSE public constant
IOInterface::VERY_VERBOSE public constant

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal