Chris@0: setName('buffer') Chris@0: ->setAliases(['buf']) Chris@0: ->setDefinition([ Chris@0: new InputOption('clear', '', InputOption::VALUE_NONE, 'Clear the current buffer.'), Chris@0: ]) Chris@0: ->setDescription('Show (or clear) the contents of the code input buffer.') Chris@0: ->setHelp( Chris@0: <<<'HELP' Chris@0: Show the contents of the code buffer for the current multi-line expression. Chris@0: Chris@0: Optionally, clear the buffer by passing the --clear option. Chris@0: HELP Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function execute(InputInterface $input, OutputInterface $output) Chris@0: { Chris@0: $buf = $this->getApplication()->getCodeBuffer(); Chris@0: if ($input->getOption('clear')) { Chris@0: $this->getApplication()->resetCodeBuffer(); Chris@0: $output->writeln($this->formatLines($buf, 'urgent'), ShellOutput::NUMBER_LINES); Chris@0: } else { Chris@0: $output->writeln($this->formatLines($buf), ShellOutput::NUMBER_LINES); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * A helper method for wrapping buffer lines in `` and `` formatter strings. Chris@0: * Chris@0: * @param array $lines Chris@0: * @param string $type (default: 'return') Chris@0: * Chris@0: * @return array Formatted strings Chris@0: */ Chris@0: protected function formatLines(array $lines, $type = 'return') Chris@0: { Chris@4: $template = \sprintf('<%s>%%s', $type, $type); Chris@0: Chris@4: return \array_map(function ($line) use ($template) { Chris@4: return \sprintf($template, $line); Chris@0: }, $lines); Chris@0: } Chris@0: }