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