X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fconsolidation%2Fannotated-command%2Fsrc%2FCommandProcessor.php;h=ab4ce45d1ca272ad1619926ca8f294ed7f79c545;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=9610b4a449a97cb591591c79877fc3a3bfa0448c;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/consolidation/annotated-command/src/CommandProcessor.php b/vendor/consolidation/annotated-command/src/CommandProcessor.php index 9610b4a44..ab4ce45d1 100644 --- a/vendor/consolidation/annotated-command/src/CommandProcessor.php +++ b/vendor/consolidation/annotated-command/src/CommandProcessor.php @@ -39,6 +39,8 @@ class CommandProcessor implements LoggerAwareInterface protected $displayErrorFunction; /** var PrepareFormatterOptions[] */ protected $prepareOptionsList = []; + /** var boolean */ + protected $passExceptions; public function __construct(HookManager $hookManager) { @@ -71,6 +73,32 @@ class CommandProcessor implements LoggerAwareInterface return $this; } + /** + * Set a mode to make the annotated command library re-throw + * any exception that it catches while processing a command. + * + * The default behavior in the current (2.x) branch is to catch + * the exception and replace it with a CommandError object that + * may be processed by the normal output processing passthrough. + * + * In the 3.x branch, exceptions will never be caught; they will + * be passed through, as if setPassExceptions(true) were called. + * This is the recommended behavior. + */ + public function setPassExceptions($passExceptions) + { + $this->passExceptions = $passExceptions; + return $this; + } + + public function commandErrorForException(\Exception $e) + { + if ($this->passExceptions) { + throw $e; + } + return new CommandError($e->getMessage(), $e->getCode()); + } + /** * Return the formatter manager * @return FormatterManager @@ -123,7 +151,7 @@ class CommandProcessor implements LoggerAwareInterface ); return $this->handleResults($output, $names, $result, $commandData); } catch (\Exception $e) { - $result = new CommandError($e->getMessage(), $e->getCode()); + $result = $this->commandErrorForException($e); return $this->handleResults($output, $names, $result, $commandData); } } @@ -206,7 +234,7 @@ class CommandProcessor implements LoggerAwareInterface $args = $commandData->getArgsAndOptions(); $result = call_user_func_array($commandCallback, $args); } catch (\Exception $e) { - $result = new CommandError($e->getMessage(), $e->getCode()); + $result = $this->commandErrorForException($e); } return $result; }