annotate vendor/psy/psysh/src/Command/DumpCommand.php @ 0:c75dbcec494b

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