annotate vendor/psy/psysh/src/Command/DumpCommand.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@13 1 <?php
Chris@13 2
Chris@13 3 /*
Chris@13 4 * This file is part of Psy Shell.
Chris@13 5 *
Chris@13 6 * (c) 2012-2018 Justin Hileman
Chris@13 7 *
Chris@13 8 * For the full copyright and license information, please view the LICENSE
Chris@13 9 * file that was distributed with this source code.
Chris@13 10 */
Chris@13 11
Chris@13 12 namespace Psy\Command;
Chris@13 13
Chris@13 14 use Psy\Input\CodeArgument;
Chris@13 15 use Psy\VarDumper\Presenter;
Chris@13 16 use Psy\VarDumper\PresenterAware;
Chris@13 17 use Symfony\Component\Console\Input\InputInterface;
Chris@13 18 use Symfony\Component\Console\Input\InputOption;
Chris@13 19 use Symfony\Component\Console\Output\OutputInterface;
Chris@13 20
Chris@13 21 /**
Chris@13 22 * Dump an object or primitive.
Chris@13 23 *
Chris@13 24 * This is like var_dump but *way* awesomer.
Chris@13 25 */
Chris@13 26 class DumpCommand extends ReflectingCommand implements PresenterAware
Chris@13 27 {
Chris@13 28 private $presenter;
Chris@13 29
Chris@13 30 /**
Chris@13 31 * PresenterAware interface.
Chris@13 32 *
Chris@13 33 * @param Presenter $presenter
Chris@13 34 */
Chris@13 35 public function setPresenter(Presenter $presenter)
Chris@13 36 {
Chris@13 37 $this->presenter = $presenter;
Chris@13 38 }
Chris@13 39
Chris@13 40 /**
Chris@13 41 * {@inheritdoc}
Chris@13 42 */
Chris@13 43 protected function configure()
Chris@13 44 {
Chris@13 45 $this
Chris@13 46 ->setName('dump')
Chris@13 47 ->setDefinition([
Chris@13 48 new CodeArgument('target', CodeArgument::REQUIRED, 'A target object or primitive to dump.'),
Chris@13 49 new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse.', 10),
Chris@13 50 new InputOption('all', 'a', InputOption::VALUE_NONE, 'Include private and protected methods and properties.'),
Chris@13 51 ])
Chris@13 52 ->setDescription('Dump an object or primitive.')
Chris@13 53 ->setHelp(
Chris@13 54 <<<'HELP'
Chris@13 55 Dump an object or primitive.
Chris@13 56
Chris@13 57 This is like var_dump but <strong>way</strong> awesomer.
Chris@13 58
Chris@13 59 e.g.
Chris@13 60 <return>>>> dump $_</return>
Chris@13 61 <return>>>> dump $someVar</return>
Chris@13 62 <return>>>> dump $stuff->getAll()</return>
Chris@13 63 HELP
Chris@13 64 );
Chris@13 65 }
Chris@13 66
Chris@13 67 /**
Chris@13 68 * {@inheritdoc}
Chris@13 69 */
Chris@13 70 protected function execute(InputInterface $input, OutputInterface $output)
Chris@13 71 {
Chris@13 72 $depth = $input->getOption('depth');
Chris@13 73 $target = $this->resolveCode($input->getArgument('target'));
Chris@13 74 $output->page($this->presenter->present($target, $depth, $input->getOption('all') ? Presenter::VERBOSE : 0));
Chris@13 75
Chris@17 76 if (\is_object($target)) {
Chris@13 77 $this->setCommandScopeVariables(new \ReflectionObject($target));
Chris@13 78 }
Chris@13 79 }
Chris@13 80
Chris@13 81 /**
Chris@13 82 * @deprecated Use `resolveCode` instead
Chris@13 83 *
Chris@13 84 * @param string $name
Chris@13 85 *
Chris@13 86 * @return mixed
Chris@13 87 */
Chris@13 88 protected function resolveTarget($name)
Chris@13 89 {
Chris@17 90 @\trigger_error('`resolveTarget` is deprecated; use `resolveCode` instead.', E_USER_DEPRECATED);
Chris@13 91
Chris@13 92 return $this->resolveCode($name);
Chris@13 93 }
Chris@13 94 }