Chris@0: presenter = $presenter; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function configure() Chris@0: { Chris@0: $this Chris@0: ->setName('dump') Chris@0: ->setDefinition(array( Chris@0: new InputArgument('target', InputArgument::REQUIRED, 'A target object or primitive to dump.', null), Chris@0: new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse', 10), Chris@0: new InputOption('all', 'a', InputOption::VALUE_NONE, 'Include private and protected methods and properties.'), Chris@0: )) Chris@0: ->setDescription('Dump an object or primitive.') Chris@0: ->setHelp( Chris@0: <<<'HELP' Chris@0: Dump an object or primitive. Chris@0: Chris@0: This is like var_dump but way awesomer. Chris@0: Chris@0: e.g. Chris@0: >>> dump $_ Chris@0: >>> dump $someVar Chris@0: HELP Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function execute(InputInterface $input, OutputInterface $output) Chris@0: { Chris@0: $depth = $input->getOption('depth'); Chris@0: $target = $this->resolveTarget($input->getArgument('target')); Chris@0: $output->page($this->presenter->present($target, $depth, $input->getOption('all') ? Presenter::VERBOSE : 0)); Chris@0: Chris@0: if (is_object($target)) { Chris@0: $this->setCommandScopeVariables(new \ReflectionObject($target)); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Resolve dump target name. Chris@0: * Chris@0: * @throws RuntimeException if target name does not exist in the current scope Chris@0: * Chris@0: * @param string $target Chris@0: * Chris@0: * @return mixed Chris@0: */ Chris@0: protected function resolveTarget($target) Chris@0: { Chris@0: $matches = array(); Chris@0: if (preg_match(self::SUPERGLOBAL, $target, $matches)) { Chris@0: if (!array_key_exists($matches[1], $GLOBALS)) { Chris@0: throw new RuntimeException('Unknown target: ' . $target); Chris@0: } Chris@0: Chris@0: return $GLOBALS[$matches[1]]; Chris@0: } elseif (preg_match(self::INSTANCE, $target, $matches)) { Chris@0: return $this->getScopeVariable($matches[1]); Chris@0: } else { Chris@0: throw new RuntimeException('Unknown target: ' . $target); Chris@0: } Chris@0: } Chris@0: }