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