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