1 <?php
2 /**
3 * Contains all custom exceptions for Alphred
4 *
5 * PHP version 5
6 *
7 * @package Alphred
8 * @copyright Shawn Patrick Rice 2014
9 * @license http://opensource.org/licenses/MIT MIT
10 * @version 1.0.0
11 * @author Shawn Patrick Rice <rice@shawnrice.org>
12 * @link http://www.github.com/shawnrice/alphred
13 * @link http://shawnrice.github.io/alphred
14 * @since File available since Release 1.0.0
15 *
16 */
17
18 namespace Alphred;
19
20 /**
21 * This is the namespaced "Exception" class (i.e.: Alphred\Exception)
22 *
23 * Alphred's Exception interface adds in some standard logging functionality
24 * whenever any exception is thrown.
25 */
26 class Exception extends \Exception {
27
28 /**
29 * Writes a message to STDERR depending on log level
30 *
31 * @param string $message message thrown
32 * @param integer $code error code
33 * @param string|boolean $file
34 */
35 public function __construct( $message, $code = 3, $file = false ) {
36 // We are going to just include a log with a stacktrace on every exception.
37 \Alphred\Log::console( $message, $code );
38
39 // Do we need to record this to a file?
40 if ( $file ) {
41 if ( \Alphred\Globals::get('alfred_workflow_data' ) ) {
42 \Alphred\Log::file( $message, $code );
43 }
44 }
45 }
46
47 }
48
49 /**
50 * Thrown when trying to instantiate a class that is written to be used as static only.
51 */
52 class UseOnlyAsStatic extends Exception {}
53
54 /**
55 * This is thrown when trying to use functions that require variables set by Alfred
56 */
57 class RunningOutsideOfAlfred extends Exception {}
58
59 /**
60 * Thrown when trying to pass bad keys to a script filter
61 */
62 class InvalidScriptFilterArgument extends Exception {}
63
64 /**
65 * Keychain error
66 */
67 class InvalidKeychainAccount extends Exception {}
68
69 /**
70 * Exception thrown when trying to set a password in the keychain without the `update` flag
71 */
72 class PasswordExists extends Exception {}
73
74 /**
75 * Thrown when trying to get a password that has not been set
76 */
77 class PasswordNotFound extends Exception {}
78
79 /**
80 * Thrown with a bad error code.
81 *
82 * If you use the library through the wrapper, then you should never see this; but if you
83 * extend it, then you might.
84 */
85 class InvalidSecurityAction extends Exception {}
86 /**
87 * Thrown when `security` doesn't know what to do
88 *
89 * If you use the library through the wrapper, then you should never see this; but if you
90 * extend it, then you might.
91 */
92 class UnknownSecurityException extends Exception {}
93
94 /**
95 * Thrown when giving too many arguments
96 */
97 class TooManyArguments extends Exception {}
98
99 /**
100 * Thrown when trying to set an XML property that should not exist
101 */
102 class InvalidXMLProperty extends Exception {}
103
104 /**
105 * Thrown when sending something that should be a bool but isn't
106 */
107 class ShouldBeBool extends Exception {}
108
109 /**
110 * Thrown when trying to access a file that does not exist
111 */
112 class FileDoesNotExist extends Exception {}
113
114 /**
115 * Thrown when trying to load a plugin that has not been defined
116 *
117 * Usually, you can correct this by `including` or `requiring` the plugin code before either
118 * including the library or instantiating the Alphred wrapper. Otherwise, check for syntax
119 * or spelling errors.
120 */
121 class PluginFunctionNotFound extends Exception {}
122
123 /**
124 * Thrown when trying to get a config key that has not been set
125 *
126 * This exists so that there is the difference between `not set` or `undefined` and `false`
127 */
128 class ConfigKeyNotSet extends Exception {}