context = $context; } /** * {@inheritdoc} */ protected function configure() { $this ->setName('throw-up') ->setDefinition(array( new InputArgument('exception', InputArgument::OPTIONAL, 'Exception to throw'), )) ->setDescription('Throw an exception out of the Psy Shell.') ->setHelp( <<<'HELP' Throws an exception out of the current the Psy Shell instance. By default it throws the most recent exception. e.g. >>> throw-up >>> throw-up $e HELP ); } /** * {@inheritdoc} * * @throws InvalidArgumentException if there is no exception to throw * @throws ThrowUpException because what else do you expect it to do? */ protected function execute(InputInterface $input, OutputInterface $output) { if ($name = $input->getArgument('exception')) { $orig = $this->context->get(preg_replace('/^\$/', '', $name)); } else { $orig = $this->context->getLastException(); } if (!$orig instanceof \Exception) { throw new \InvalidArgumentException('throw-up can only throw Exceptions'); } throw new ThrowUpException($orig); } }