1 <?php
2 
3 namespace splitbrain\phpcli;
4 
5 /**
6  * Class Exception
7  *
8  * The code is used as exit code for the CLI tool. This should probably be extended. Many cases just fall back to the
9  * E_ANY code.
10  *
11  * @author Andreas Gohr <andi@splitbrain.org>
12  * @license MIT
13  */
14 class Exception extends \RuntimeException
15 {
16     const E_ANY = -1; // no error code specified
17     const E_UNKNOWN_OPT = 1; //Unrecognized option
18     const E_OPT_ARG_REQUIRED = 2; //Option requires argument
19     const E_OPT_ARG_DENIED = 3; //Option not allowed argument
20     const E_OPT_ABIGUOUS = 4; //Option abiguous
21     const E_ARG_READ = 5; //Could not read argv
22 
23     /**
24      * @param string $message The Exception message to throw.
25      * @param int $code The Exception code
26      * @param \Exception $previous The previous exception used for the exception chaining.
27      */
28     public function __construct($message = "", $code = 0, \Exception $previous = null)
29     {
30         if (!$code) {
31             $code = self::E_ANY;
32         }
33         parent::__construct($message, $code, $previous);
34     }
35 }
36