4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Command;
14 use Psy\Configuration;
15 use Psy\Exception\RuntimeException;
16 use Psy\Formatter\CodeFormatter;
17 use Psy\Formatter\SignatureFormatter;
18 use Psy\Output\ShellOutput;
19 use Symfony\Component\Console\Input\InputArgument;
20 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Output\OutputInterface;
24 * Show the code for an object, class, constant, method or property.
26 class ShowCommand extends ReflectingCommand
31 * @param null|string $colorMode (default: null)
33 public function __construct($colorMode = null)
35 $this->colorMode = $colorMode ?: Configuration::COLOR_MODE_AUTO;
37 return parent::__construct();
43 protected function configure()
47 ->setDefinition(array(
48 new InputArgument('value', InputArgument::REQUIRED, 'Function, class, instance, constant, method or property to show.'),
50 ->setDescription('Show the code for an object, class, constant, method or property.')
53 Show the code for an object, class, constant, method or property.
56 <return>>>> show \$myObject</return>
57 <return>>>> show Psy\Shell::debug</return>
65 protected function execute(InputInterface $input, OutputInterface $output)
67 list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));
69 // Set some magic local variables
70 $this->setCommandScopeVariables($reflector);
73 $output->page(CodeFormatter::format($reflector, $this->colorMode), ShellOutput::OUTPUT_RAW);
74 } catch (RuntimeException $e) {
75 $output->writeln(SignatureFormatter::format($reflector));