Completed
Push — master ( e0623f...313c90 )
by Flavio
02:57
created
classes/CLI.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
     /**
117 117
      * Dispatch the router
118 118
      * @param  string[] $args The arguments array.
119
-     * @return boolean  True if route was correctly dispatched.
119
+     * @return null|boolean  True if route was correctly dispatched.
120 120
      */
121 121
     public static function run($args=null){
122 122
       if($args) {
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
      * @return array   The commands and their description.
103 103
      */
104 104
     public static function commands(){
105
-       $results = [];
106
-       foreach(static::$commands as $name => $cmd){
105
+        $results = [];
106
+        foreach(static::$commands as $name => $cmd){
107 107
           $results[] = [
108 108
             'name'        => $name,
109 109
             'params'      => preg_replace('/:(\w+)/','[$1]',implode(' ',$cmd[0])),
110 110
             'description' => $cmd[2],
111 111
           ];
112
-       }
113
-       return $results;
112
+        }
113
+        return $results;
114 114
     }
115 115
 
116 116
     /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
       if($args) {
123 123
         $_args = $args;
124 124
         static::$file = basename(isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:__FILE__);
125
-       } else {
125
+        } else {
126 126
         $_args = $_SERVER['argv'];
127 127
         static::$file = basename(array_shift($_args));
128 128
       }
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
           if ($segment[0]==':'){
144 144
             // Extract paramenter
145 145
             if (isset(static::$arguments[$_idx])){
146
-               $pars_vector[] = static::$arguments[$_idx];
146
+                $pars_vector[] = static::$arguments[$_idx];
147 147
             } else return static::triggerError("Command [".$command."] needs more parameters");
148 148
           } else {
149 149
             // Match command
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
       }
160 160
     }
161 161
 
162
-   /**
163
-    * Prints a message to the console with color formatting.
164
-    * @param  string $message The html-like encoded message
165
-    * @return void
166
-    */
167
-   public static function write($message){
162
+    /**
163
+     * Prints a message to the console with color formatting.
164
+     * @param  string $message The html-like encoded message
165
+     * @return void
166
+     */
167
+    public static function write($message){
168 168
       if( preg_match('~<[^>]+>~',$message)) {
169
-         // Use preg_replace_callback for fast regex matches navigation
170
-         preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
169
+          // Use preg_replace_callback for fast regex matches navigation
170
+          preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
171 171
             static::write($m[1]);
172 172
             $color = strtoupper(trim($m[2]));
173 173
             if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
@@ -177,37 +177,37 @@  discard block
 block discarded – undo
177 177
             $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL';
178 178
             if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color];
179 179
             static::write($m[4]);
180
-         },$message);
180
+          },$message);
181 181
       } else {
182
-         echo $message;
182
+          echo $message;
183 183
       }
184
-   }
184
+    }
185 185
    
186
-   /**
187
-    * Like CLI::write, but appends a newline at the end.
188
-    * @param  string $message The html-like encoded message
189
-    * @return void
190
-    */
191
-   public static function writeln($message){
192
-       static::write($message . PHP_EOL);
193
-   }
194
-
195
-   /**
196
-    * Set output ANSI color
197
-    * @param string $color The color name constant.
198
-    * @return void
199
-    */   
200
-   public static function color($color){
201
-       if ( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
202
-   }
203
-
204
-   /**
205
-    * Edit a temporary block of text with $EDITOR (or nano as fallback)
206
-    * @param string $text The initial text of the document.
207
-    * @param string $filename The (fake) filename passed to the editor (for syntax highlighting hint).
208
-    * @return string The edited contents
209
-    */
210
-   public static function edit($text,$filename=''){
186
+    /**
187
+     * Like CLI::write, but appends a newline at the end.
188
+     * @param  string $message The html-like encoded message
189
+     * @return void
190
+     */
191
+    public static function writeln($message){
192
+        static::write($message . PHP_EOL);
193
+    }
194
+
195
+    /**
196
+     * Set output ANSI color
197
+     * @param string $color The color name constant.
198
+     * @return void
199
+     */   
200
+    public static function color($color){
201
+        if ( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
202
+    }
203
+
204
+    /**
205
+     * Edit a temporary block of text with $EDITOR (or nano as fallback)
206
+     * @param string $text The initial text of the document.
207
+     * @param string $filename The (fake) filename passed to the editor (for syntax highlighting hint).
208
+     * @return string The edited contents
209
+     */
210
+    public static function edit($text,$filename=''){
211 211
       $EDITOR = getenv('EDITOR')?:'nano';
212 212
       $tmp = tempnam(sys_get_temp_dir(), "E-").strtr($filename,'/','_');
213 213
       file_put_contents($tmp, $text);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 // Standard Help Message
225 225
 CLI::help(function(){
226 226
   echo 'Usage: ', CLI::name(),' [commands]', PHP_EOL,
227
-       'Commands:',PHP_EOL;
227
+        'Commands:',PHP_EOL;
228 228
   foreach( CLI::commands() as $cmd ){
229 229
     echo "\t", $cmd['name'], ' ' ,$cmd['params'], PHP_EOL;    
230 230
     if($cmd['description'])
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
     protected static $error        = null;
22 22
     
23 23
     protected static $shell_colors = [
24
-      'BLACK'     =>"\033[0;30m",      'DARKGRAY'     =>"\033[1;30m",
25
-      'BLUE'      =>"\033[0;34m",      'LIGHTBLUE'    =>"\033[1;34m",
26
-      'GREEN'     =>"\033[0;32m",      'LIGHTGREEN'   =>"\033[1;32m",
27
-      'CYAN'      =>"\033[0;36m",      'LIGHTCYAN'    =>"\033[1;36m",
28
-      'RED'       =>"\033[0;31m",      'LIGHTRED'     =>"\033[1;31m",
29
-      'PURPLE'    =>"\033[0;35m",      'LIGHTPURPLE'  =>"\033[1;35m",
30
-      'BROWN'     =>"\033[0;33m",      'YELLOW'       =>"\033[1;33m",
31
-      'LIGHTGRAY' =>"\033[0;37m",      'WHITE'        =>"\033[1;37m",
32
-      'NORMAL'    =>"\033[0;37m",      'B'            =>"\033[1m",
33
-      'ERROR'     =>"\033[1;31m",      'INFO'         =>"\033[0;36m",
34
-      'I'         =>"\033[0;30;104m",  'IB'           =>"\033[1;30;104m",
35
-      'U'         =>"\033[4m",         'D'            =>"\033[2m",
24
+      'BLACK'     =>"\033[0;30m", 'DARKGRAY'     =>"\033[1;30m",
25
+      'BLUE'      =>"\033[0;34m", 'LIGHTBLUE'    =>"\033[1;34m",
26
+      'GREEN'     =>"\033[0;32m", 'LIGHTGREEN'   =>"\033[1;32m",
27
+      'CYAN'      =>"\033[0;36m", 'LIGHTCYAN'    =>"\033[1;36m",
28
+      'RED'       =>"\033[0;31m", 'LIGHTRED'     =>"\033[1;31m",
29
+      'PURPLE'    =>"\033[0;35m", 'LIGHTPURPLE'  =>"\033[1;35m",
30
+      'BROWN'     =>"\033[0;33m", 'YELLOW'       =>"\033[1;33m",
31
+      'LIGHTGRAY' =>"\033[0;37m", 'WHITE'        =>"\033[1;37m",
32
+      'NORMAL'    =>"\033[0;37m", 'B'            =>"\033[1m",
33
+      'ERROR'     =>"\033[1;31m", 'INFO'         =>"\033[0;36m",
34
+      'I'         =>"\033[0;30;104m", 'IB'           =>"\033[1;30;104m",
35
+      'U'         =>"\033[4m", 'D'            =>"\033[2m",
36 36
     ];
37 37
     protected static $color_stack = ['NORMAL'];
38 38
     
@@ -42,16 +42,16 @@  discard block
 block discarded – undo
42 42
      * @param  string   $command  The command route, use ":" before a parameter for extraction. 
43 43
      * @param  callable $callback The callback to be binded to the route.
44 44
      */
45
-    public static function on($command,callable $callback,$description=''){
46
-      $parts = preg_split('/\s+/',$command);
47
-      static::$commands[array_shift($parts)] = [$parts,$callback,$description];
45
+    public static function on($command, callable $callback, $description = '') {
46
+      $parts = preg_split('/\s+/', $command);
47
+      static::$commands[array_shift($parts)] = [$parts, $callback, $description];
48 48
     }
49 49
 
50 50
     /**
51 51
      * Bind a callback to the "help" route.
52 52
      * @param  callable $callback The callback to be binded to the route. If omitted triggers the callback.
53 53
      */
54
-    public static function help(callable $callback = null){
54
+    public static function help(callable $callback = null) {
55 55
         $callback
56 56
           ? is_callable($callback) && static::$help = $callback
57 57
           : static::$help && call_user_func(static::$help);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * Bind a callback when an error occurs.
62 62
      * @param  callable $callback The callback to be binded to the route. If omitted triggers the callback.
63 63
      */
64
-    public static function error(callable $callback = null){
64
+    public static function error(callable $callback = null) {
65 65
         $callback
66 66
           ? is_callable($callback) && static::$error = $callback
67 67
           : static::$error && call_user_func(static::$error);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * Returns the script name.
72 72
      * @return string
73 73
      */
74
-    public static function name(){
74
+    public static function name() {
75 75
         return static::$file;
76 76
     }
77 77
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
      * Triggers an error and exit
80 80
      * @param string $message 
81 81
      */
82
-    protected static function triggerError($message){
83
-        is_callable(static::$error) && call_user_func(static::$error,$message);
82
+    protected static function triggerError($message) {
83
+        is_callable(static::$error) && call_user_func(static::$error, $message);
84 84
         exit -1;
85 85
     }
86 86
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
      * @param mixed $default The default value if parameter is omitted. (if a callable it will be evaluated) 
91 91
      * @return mixed
92 92
      */
93
-    public static function input($key=null,$default=null){
94
-      return $key ? (isset(static::$options[$key]) ? static::$options[$key] : (is_callable($default)?call_user_func($default):$default)) : static::$options;
93
+    public static function input($key = null, $default = null) {
94
+      return $key ? (isset(static::$options[$key]) ? static::$options[$key] : (is_callable($default) ? call_user_func($default) : $default)) : static::$options;
95 95
     }
96 96
 
97 97
     /**
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return array   The commands and their description.
103 103
      */
104
-    public static function commands(){
104
+    public static function commands() {
105 105
        $results = [];
106
-       foreach(static::$commands as $name => $cmd){
106
+       foreach (static::$commands as $name => $cmd) {
107 107
           $results[] = [
108 108
             'name'        => $name,
109
-            'params'      => preg_replace('/:(\w+)/','[$1]',implode(' ',$cmd[0])),
109
+            'params'      => preg_replace('/:(\w+)/', '[$1]', implode(' ', $cmd[0])),
110 110
             'description' => $cmd[2],
111 111
           ];
112 112
        }
@@ -118,40 +118,40 @@  discard block
 block discarded – undo
118 118
      * @param  string[] $args The arguments array.
119 119
      * @return boolean  True if route was correctly dispatched.
120 120
      */
121
-    public static function run($args=null){
122
-      if($args) {
121
+    public static function run($args = null) {
122
+      if ($args) {
123 123
         $_args = $args;
124
-        static::$file = basename(isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:__FILE__);
124
+        static::$file = basename(isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : __FILE__);
125 125
        } else {
126 126
         $_args = $_SERVER['argv'];
127 127
         static::$file = basename(array_shift($_args));
128 128
       }
129
-      foreach($_args as $e) if(strpos($e,'-')===0) {
130
-        $h = explode('=',$e);
131
-        static::$options[ltrim(current($h),'-')] = isset($h[1])?$h[1]:true; 
129
+      foreach ($_args as $e) if (strpos($e, '-') === 0) {
130
+        $h = explode('=', $e);
131
+        static::$options[ltrim(current($h), '-')] = isset($h[1]) ? $h[1] : true; 
132 132
       } else {
133 133
         static::$arguments[] = $e;
134 134
       }
135 135
       
136
-      if(isset(static::$arguments[0])){
136
+      if (isset(static::$arguments[0])) {
137 137
         $command = array_shift(static::$arguments);
138 138
         if (empty(static::$commands[$command])) 
139 139
           return static::triggerError("Unknown command [".$command."].");
140 140
         $cmd = static::$commands[$command];
141 141
         $pars_vector = [];
142 142
         foreach ($cmd[0] as $_idx => $segment) {
143
-          if ($segment[0]==':'){
143
+          if ($segment[0] == ':') {
144 144
             // Extract paramenter
145
-            if (isset(static::$arguments[$_idx])){
145
+            if (isset(static::$arguments[$_idx])) {
146 146
                $pars_vector[] = static::$arguments[$_idx];
147 147
             } else return static::triggerError("Command [".$command."] needs more parameters");
148 148
           } else {
149 149
             // Match command
150
-            if (empty(static::$arguments[$_idx]) || $segment!=static::$arguments[$_idx]) 
150
+            if (empty(static::$arguments[$_idx]) || $segment != static::$arguments[$_idx]) 
151 151
               return static::triggerError("Command [".$command."] is incomplete.");
152 152
           }
153 153
         }
154
-        call_user_func_array($cmd[1],$pars_vector);
154
+        call_user_func_array($cmd[1], $pars_vector);
155 155
         return true;
156 156
       } else {
157 157
         static::help();
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
     * @param  string $message The html-like encoded message
165 165
     * @return void
166 166
     */
167
-   public static function write($message){
168
-      if( preg_match('~<[^>]+>~',$message)) {
167
+   public static function write($message) {
168
+      if (preg_match('~<[^>]+>~', $message)) {
169 169
          // Use preg_replace_callback for fast regex matches navigation
170
-         preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
170
+         preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm', function($m) {
171 171
             static::write($m[1]);
172 172
             $color = strtoupper(trim($m[2]));
173
-            if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
173
+            if (isset(static::$shell_colors[$color])) echo static::$shell_colors[$color];
174 174
             static::$color_stack[] = $color;
175 175
             static::write($m[3]);
176 176
             array_pop(static::$color_stack);
177
-            $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL';
178
-            if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color];
177
+            $back_color = array_pop(static::$color_stack) ?: static::$color_stack[] = 'NORMAL';
178
+            if (isset(static::$shell_colors[$back_color])) echo static::$shell_colors[$back_color];
179 179
             static::write($m[4]);
180 180
          },$message);
181 181
       } else {
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
     * @param  string $message The html-like encoded message
189 189
     * @return void
190 190
     */
191
-   public static function writeln($message){
192
-       static::write($message . PHP_EOL);
191
+   public static function writeln($message) {
192
+       static::write($message.PHP_EOL);
193 193
    }
194 194
 
195 195
    /**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
     * @param string $color The color name constant.
198 198
     * @return void
199 199
     */   
200
-   public static function color($color){
201
-       if ( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
200
+   public static function color($color) {
201
+       if (isset(static::$shell_colors[$color])) echo static::$shell_colors[$color];
202 202
    }
203 203
 
204 204
    /**
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
     * @param string $filename The (fake) filename passed to the editor (for syntax highlighting hint).
208 208
     * @return string The edited contents
209 209
     */
210
-   public static function edit($text,$filename=''){
211
-      $EDITOR = getenv('EDITOR')?:'nano';
212
-      $tmp = tempnam(sys_get_temp_dir(), "E-").strtr($filename,'/','_');
210
+   public static function edit($text, $filename = '') {
211
+      $EDITOR = getenv('EDITOR') ?: 'nano';
212
+      $tmp = tempnam(sys_get_temp_dir(), "E-").strtr($filename, '/', '_');
213 213
       file_put_contents($tmp, $text);
214 214
       passthru("$EDITOR $tmp");
215 215
       $result = file_get_contents($tmp);
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
 
223 223
 
224 224
 // Standard Help Message
225
-CLI::help(function(){
226
-  echo 'Usage: ', CLI::name(),' [commands]', PHP_EOL,
227
-       'Commands:',PHP_EOL;
228
-  foreach( CLI::commands() as $cmd ){
229
-    echo "\t", $cmd['name'], ' ' ,$cmd['params'], PHP_EOL;    
230
-    if($cmd['description'])
231
-      echo "\t\t- ", str_replace("\n","\n\t\t  ",$cmd['description']), PHP_EOL, PHP_EOL;    
225
+CLI::help(function() {
226
+  echo 'Usage: ', CLI::name(), ' [commands]', PHP_EOL,
227
+       'Commands:', PHP_EOL;
228
+  foreach (CLI::commands() as $cmd) {
229
+    echo "\t", $cmd['name'], ' ', $cmd['params'], PHP_EOL;    
230
+    if ($cmd['description'])
231
+      echo "\t\t- ", str_replace("\n", "\n\t\t  ", $cmd['description']), PHP_EOL, PHP_EOL;    
232 232
   }
233 233
 });
234 234
 
235 235
 // Standard Error Message
236
-CLI::error(function($message){
237
-  echo 'Error: ',$message,PHP_EOL;
236
+CLI::error(function($message) {
237
+  echo 'Error: ', $message, PHP_EOL;
238 238
 });
Please login to merge, or discard this patch.
Braces   +41 added lines, -30 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      * @param  string   $command  The command route, use ":" before a parameter for extraction. 
43 43
      * @param  callable $callback The callback to be binded to the route.
44 44
      */
45
-    public static function on($command,callable $callback,$description=''){
45
+    public static function on($command,callable $callback,$description='') {
46 46
       $parts = preg_split('/\s+/',$command);
47 47
       static::$commands[array_shift($parts)] = [$parts,$callback,$description];
48 48
     }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * Bind a callback to the "help" route.
52 52
      * @param  callable $callback The callback to be binded to the route. If omitted triggers the callback.
53 53
      */
54
-    public static function help(callable $callback = null){
54
+    public static function help(callable $callback = null) {
55 55
         $callback
56 56
           ? is_callable($callback) && static::$help = $callback
57 57
           : static::$help && call_user_func(static::$help);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * Bind a callback when an error occurs.
62 62
      * @param  callable $callback The callback to be binded to the route. If omitted triggers the callback.
63 63
      */
64
-    public static function error(callable $callback = null){
64
+    public static function error(callable $callback = null) {
65 65
         $callback
66 66
           ? is_callable($callback) && static::$error = $callback
67 67
           : static::$error && call_user_func(static::$error);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * Returns the script name.
72 72
      * @return string
73 73
      */
74
-    public static function name(){
74
+    public static function name() {
75 75
         return static::$file;
76 76
     }
77 77
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * Triggers an error and exit
80 80
      * @param string $message 
81 81
      */
82
-    protected static function triggerError($message){
82
+    protected static function triggerError($message) {
83 83
         is_callable(static::$error) && call_user_func(static::$error,$message);
84 84
         exit -1;
85 85
     }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param mixed $default The default value if parameter is omitted. (if a callable it will be evaluated) 
91 91
      * @return mixed
92 92
      */
93
-    public static function input($key=null,$default=null){
93
+    public static function input($key=null,$default=null) {
94 94
       return $key ? (isset(static::$options[$key]) ? static::$options[$key] : (is_callable($default)?call_user_func($default):$default)) : static::$options;
95 95
     }
96 96
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return array   The commands and their description.
103 103
      */
104
-    public static function commands(){
104
+    public static function commands() {
105 105
        $results = [];
106
-       foreach(static::$commands as $name => $cmd){
106
+       foreach(static::$commands as $name => $cmd) {
107 107
           $results[] = [
108 108
             'name'        => $name,
109 109
             'params'      => preg_replace('/:(\w+)/','[$1]',implode(' ',$cmd[0])),
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param  string[] $args The arguments array.
119 119
      * @return boolean  True if route was correctly dispatched.
120 120
      */
121
-    public static function run($args=null){
121
+    public static function run($args=null) {
122 122
       if($args) {
123 123
         $_args = $args;
124 124
         static::$file = basename(isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:__FILE__);
@@ -133,22 +133,26 @@  discard block
 block discarded – undo
133 133
         static::$arguments[] = $e;
134 134
       }
135 135
       
136
-      if(isset(static::$arguments[0])){
136
+      if(isset(static::$arguments[0])) {
137 137
         $command = array_shift(static::$arguments);
138
-        if (empty(static::$commands[$command])) 
139
-          return static::triggerError("Unknown command [".$command."].");
138
+        if (empty(static::$commands[$command])) {
139
+                  return static::triggerError("Unknown command [".$command."].");
140
+        }
140 141
         $cmd = static::$commands[$command];
141 142
         $pars_vector = [];
142 143
         foreach ($cmd[0] as $_idx => $segment) {
143
-          if ($segment[0]==':'){
144
+          if ($segment[0]==':') {
144 145
             // Extract paramenter
145
-            if (isset(static::$arguments[$_idx])){
146
+            if (isset(static::$arguments[$_idx])) {
146 147
                $pars_vector[] = static::$arguments[$_idx];
147
-            } else return static::triggerError("Command [".$command."] needs more parameters");
148
+            } else {
149
+              return static::triggerError("Command [".$command."] needs more parameters");
150
+            }
148 151
           } else {
149 152
             // Match command
150
-            if (empty(static::$arguments[$_idx]) || $segment!=static::$arguments[$_idx]) 
151
-              return static::triggerError("Command [".$command."] is incomplete.");
153
+            if (empty(static::$arguments[$_idx]) || $segment!=static::$arguments[$_idx]) {
154
+                          return static::triggerError("Command [".$command."] is incomplete.");
155
+            }
152 156
           }
153 157
         }
154 158
         call_user_func_array($cmd[1],$pars_vector);
@@ -164,18 +168,22 @@  discard block
 block discarded – undo
164 168
     * @param  string $message The html-like encoded message
165 169
     * @return void
166 170
     */
167
-   public static function write($message){
171
+   public static function write($message) {
168 172
       if( preg_match('~<[^>]+>~',$message)) {
169 173
          // Use preg_replace_callback for fast regex matches navigation
170
-         preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
174
+         preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m) {
171 175
             static::write($m[1]);
172 176
             $color = strtoupper(trim($m[2]));
173
-            if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
177
+            if( isset(static::$shell_colors[$color]) ) {
178
+              echo static::$shell_colors[$color];
179
+            }
174 180
             static::$color_stack[] = $color;
175 181
             static::write($m[3]);
176 182
             array_pop(static::$color_stack);
177 183
             $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL';
178
-            if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color];
184
+            if( isset(static::$shell_colors[$back_color]) ) {
185
+              echo static::$shell_colors[$back_color];
186
+            }
179 187
             static::write($m[4]);
180 188
          },$message);
181 189
       } else {
@@ -188,7 +196,7 @@  discard block
 block discarded – undo
188 196
     * @param  string $message The html-like encoded message
189 197
     * @return void
190 198
     */
191
-   public static function writeln($message){
199
+   public static function writeln($message) {
192 200
        static::write($message . PHP_EOL);
193 201
    }
194 202
 
@@ -197,8 +205,10 @@  discard block
 block discarded – undo
197 205
     * @param string $color The color name constant.
198 206
     * @return void
199 207
     */   
200
-   public static function color($color){
201
-       if ( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color];
208
+   public static function color($color) {
209
+       if ( isset(static::$shell_colors[$color]) ) {
210
+         echo static::$shell_colors[$color];
211
+       }
202 212
    }
203 213
 
204 214
    /**
@@ -207,7 +217,7 @@  discard block
 block discarded – undo
207 217
     * @param string $filename The (fake) filename passed to the editor (for syntax highlighting hint).
208 218
     * @return string The edited contents
209 219
     */
210
-   public static function edit($text,$filename=''){
220
+   public static function edit($text,$filename='') {
211 221
       $EDITOR = getenv('EDITOR')?:'nano';
212 222
       $tmp = tempnam(sys_get_temp_dir(), "E-").strtr($filename,'/','_');
213 223
       file_put_contents($tmp, $text);
@@ -222,17 +232,18 @@  discard block
 block discarded – undo
222 232
 
223 233
 
224 234
 // Standard Help Message
225
-CLI::help(function(){
235
+CLI::help(function() {
226 236
   echo 'Usage: ', CLI::name(),' [commands]', PHP_EOL,
227 237
        'Commands:',PHP_EOL;
228
-  foreach( CLI::commands() as $cmd ){
238
+  foreach( CLI::commands() as $cmd ) {
229 239
     echo "\t", $cmd['name'], ' ' ,$cmd['params'], PHP_EOL;    
230
-    if($cmd['description'])
231
-      echo "\t\t- ", str_replace("\n","\n\t\t  ",$cmd['description']), PHP_EOL, PHP_EOL;    
240
+    if($cmd['description']) {
241
+          echo "\t\t- ", str_replace("\n","\n\t\t  ",$cmd['description']), PHP_EOL, PHP_EOL;
242
+    }
232 243
   }
233 244
 });
234 245
 
235 246
 // Standard Error Message
236
-CLI::error(function($message){
247
+CLI::error(function($message) {
237 248
   echo 'Error: ',$message,PHP_EOL;
238 249
 });
Please login to merge, or discard this patch.
classes/Errors.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -57,6 +57,9 @@
 block discarded – undo
57 57
       return true;
58 58
     }
59 59
 
60
+    /**
61
+     * @param ErrorException $e
62
+     */
60 63
     public static function traceException($e){
61 64
       switch(self::$mode){
62 65
           case self::HTML :
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
 
21 21
     static $mode = self::SILENT;
22 22
 
23
-    public static function capture($tracing_level=null){
24
-      if($tracing_level!==null) error_reporting($tracing_level);
23
+    public static function capture($tracing_level = null) {
24
+      if ($tracing_level !== null) error_reporting($tracing_level);
25 25
       set_error_handler(__CLASS__.'::traceError');
26 26
       set_exception_handler(__CLASS__.'::traceException');
27 27
     }
28 28
 
29
-    public static function mode($mode=null){
30
-      return $mode ? self::$mode=$mode : self::$mode;
29
+    public static function mode($mode = null) {
30
+      return $mode ? self::$mode = $mode : self::$mode;
31 31
     }
32 32
 
33
-    public static function traceError($errno,$errstr,$errfile=null,$errline=null){
33
+    public static function traceError($errno, $errstr, $errfile = null, $errline = null) {
34 34
       // This error code is not included in error_reporting
35 35
       if (!(error_reporting() & $errno)) return;
36
-      switch ( $errno ) {
36
+      switch ($errno) {
37 37
         case E_USER_ERROR:
38 38
             $type = 'Fatal';
39 39
         break;
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
         break;
52 52
       }
53 53
       $e = new \ErrorException($type.': '.$errstr, 0, $errno, $errfile, $errline);
54
-      $chk_specific = array_filter((array)Event::trigger('core.error.'.strtolower($type),$e));
55
-      $chk_general  = array_filter((array)Event::trigger('core.error',$e));
56
-      if (! ($chk_specific || $chk_general) ) static::traceException($e);
54
+      $chk_specific = array_filter((array) Event::trigger('core.error.'.strtolower($type), $e));
55
+      $chk_general  = array_filter((array) Event::trigger('core.error', $e));
56
+      if (!($chk_specific || $chk_general)) static::traceException($e);
57 57
       return true;
58 58
     }
59 59
 
60
-    public static function traceException($e){
61
-      switch(self::$mode){
60
+    public static function traceException($e) {
61
+      switch (self::$mode) {
62 62
           case self::HTML :
63
-              echo '<pre class="app error"><code>',$e->getMessage(),'</code></pre>',PHP_EOL;
63
+              echo '<pre class="app error"><code>', $e->getMessage(), '</code></pre>', PHP_EOL;
64 64
               break;
65 65
           case self::JSON :
66 66
               echo json_encode(['error' => $e->getMessage()]);
@@ -70,26 +70,26 @@  discard block
 block discarded – undo
70 70
               break;
71 71
           case self::SIMPLE :
72 72
           default:
73
-              echo $e->getMessage(),PHP_EOL;
73
+              echo $e->getMessage(), PHP_EOL;
74 74
               break;
75 75
       }
76 76
       return true;
77 77
     }
78 78
 
79
-    public static function onFatal(callable $listener){
80
-      Event::on('core.error.fatal',$listener);
79
+    public static function onFatal(callable $listener) {
80
+      Event::on('core.error.fatal', $listener);
81 81
     }
82 82
 
83
-    public static function onWarning(callable $listener){
84
-      Event::on('core.error.warning',$listener);
83
+    public static function onWarning(callable $listener) {
84
+      Event::on('core.error.warning', $listener);
85 85
     }
86 86
 
87
-    public static function onNotice(callable $listener){
88
-      Event::on('core.error.notice',$listener);
87
+    public static function onNotice(callable $listener) {
88
+      Event::on('core.error.notice', $listener);
89 89
     }
90 90
 
91
-    public static function onAny(callable $listener){
92
-      Event::on('core.error',$listener);
91
+    public static function onAny(callable $listener) {
92
+      Event::on('core.error', $listener);
93 93
     }
94 94
 
95 95
 }
Please login to merge, or discard this patch.
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,19 +20,23 @@  discard block
 block discarded – undo
20 20
 
21 21
     static $mode = self::SILENT;
22 22
 
23
-    public static function capture($tracing_level=null){
24
-      if($tracing_level!==null) error_reporting($tracing_level);
23
+    public static function capture($tracing_level=null) {
24
+      if($tracing_level!==null) {
25
+        error_reporting($tracing_level);
26
+      }
25 27
       set_error_handler(__CLASS__.'::traceError');
26 28
       set_exception_handler(__CLASS__.'::traceException');
27 29
     }
28 30
 
29
-    public static function mode($mode=null){
31
+    public static function mode($mode=null) {
30 32
       return $mode ? self::$mode=$mode : self::$mode;
31 33
     }
32 34
 
33
-    public static function traceError($errno,$errstr,$errfile=null,$errline=null){
35
+    public static function traceError($errno,$errstr,$errfile=null,$errline=null) {
34 36
       // This error code is not included in error_reporting
35
-      if (!(error_reporting() & $errno)) return;
37
+      if (!(error_reporting() & $errno)) {
38
+        return;
39
+      }
36 40
       switch ( $errno ) {
37 41
         case E_USER_ERROR:
38 42
             $type = 'Fatal';
@@ -53,12 +57,14 @@  discard block
 block discarded – undo
53 57
       $e = new \ErrorException($type.': '.$errstr, 0, $errno, $errfile, $errline);
54 58
       $chk_specific = array_filter((array)Event::trigger('core.error.'.strtolower($type),$e));
55 59
       $chk_general  = array_filter((array)Event::trigger('core.error',$e));
56
-      if (! ($chk_specific || $chk_general) ) static::traceException($e);
60
+      if (! ($chk_specific || $chk_general) ) {
61
+        static::traceException($e);
62
+      }
57 63
       return true;
58 64
     }
59 65
 
60
-    public static function traceException($e){
61
-      switch(self::$mode){
66
+    public static function traceException($e) {
67
+      switch(self::$mode) {
62 68
           case self::HTML :
63 69
               echo '<pre class="app error"><code>',$e->getMessage(),'</code></pre>',PHP_EOL;
64 70
               break;
@@ -76,19 +82,19 @@  discard block
 block discarded – undo
76 82
       return true;
77 83
     }
78 84
 
79
-    public static function onFatal(callable $listener){
85
+    public static function onFatal(callable $listener) {
80 86
       Event::on('core.error.fatal',$listener);
81 87
     }
82 88
 
83
-    public static function onWarning(callable $listener){
89
+    public static function onWarning(callable $listener) {
84 90
       Event::on('core.error.warning',$listener);
85 91
     }
86 92
 
87
-    public static function onNotice(callable $listener){
93
+    public static function onNotice(callable $listener) {
88 94
       Event::on('core.error.notice',$listener);
89 95
     }
90 96
 
91
-    public static function onAny(callable $listener){
97
+    public static function onAny(callable $listener) {
92 98
       Event::on('core.error',$listener);
93 99
     }
94 100
 
Please login to merge, or discard this patch.
classes/Route.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -198,7 +198,6 @@  discard block
 block discarded – undo
198 198
 
199 199
     /**
200 200
      * Bind a middleware callback to invoked before the route definition
201
-     * @param  callable $before The callback to be invoked ($this is binded to the route object).
202 201
      * @return Route
203 202
      */
204 203
     public function & before($callback){
@@ -318,7 +317,7 @@  discard block
 block discarded – undo
318 317
      * @param  string  $pattern The URL schema with the named parameters
319 318
      * @param  string  $URL The URL to process, if omitted the current request URI will be used.
320 319
      * @param  boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
321
-     * @return array The extracted variables
320
+     * @return callable The extracted variables
322 321
      */
323 322
     protected static function extractVariablesFromURL($pattern,$URL=null,$cut=false){
324 323
         $URL     = $URL ?: Request::URI();
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
     use Module;
15 15
 
16 16
     protected static $routes,
17
-                     $base    = '',
18
-                     $prefix  = [],
19
-                     $group   = [];
17
+                      $base    = '',
18
+                      $prefix  = [],
19
+                      $group   = [];
20 20
 
21 21
     protected $URLPattern     = '',
22 22
               $pattern        = '',
@@ -85,20 +85,20 @@  discard block
 block discarded – undo
85 85
         $method = strtolower($method);
86 86
         $this->response 			 		= '';
87 87
         $this->response_object 		= null;
88
-       	$this->response_is_object = false;
88
+          $this->response_is_object = false;
89 89
 
90 90
         // Call direct befores
91 91
         if ( $this->befores ) {
92 92
           // Reverse befores order
93 93
           foreach (array_reverse($this->befores) as $mw) {
94
-	        	ob_start();
94
+            ob_start();
95 95
             $mw_result = call_user_func($mw->bindTo($this));
96
-          	$this->response .= ob_get_clean();
96
+            $this->response .= ob_get_clean();
97 97
             if ( false  === $mw_result ) {
98
-            	return [''];
98
+              return [''];
99 99
             } else if (is_a($mw_result,'View') || is_string($mw_result)) {
100 100
               $this->response .= (string)$mw_result;
101
-          	}
101
+            }
102 102
           }
103 103
         }
104 104
 
@@ -109,51 +109,51 @@  discard block
 block discarded – undo
109 109
 
110 110
         if (is_callable($callback)) {
111 111
           // Capure callback output
112
-					Response::type(Response::TYPE_HTML);
113
-	        ob_start();
114
-	        // Silence "Cannot bind an instance to a static closure" warnings
115
-	        $view_results 	 = call_user_func_array(@$callback->bindTo($this), $args);
116
-	        $this->response .= ob_get_clean();
117
-
118
-	        // Render View if returned, else echo string or encode json response
119
-	        if ( null !== $view_results ) {
120
-	          if (is_a($view_results,'View') || is_string($view_results)) {
121
-	              $this->response .= (string)$view_results;
122
-	          } else {
123
-			        	$this->response_is_object = true;
124
-	              $this->response_object 		= $view_results;
125
-	          }
126
-	        }
112
+          Response::type(Response::TYPE_HTML);
113
+          ob_start();
114
+          // Silence "Cannot bind an instance to a static closure" warnings
115
+          $view_results 	 = call_user_func_array(@$callback->bindTo($this), $args);
116
+          $this->response .= ob_get_clean();
117
+
118
+          // Render View if returned, else echo string or encode json response
119
+          if ( null !== $view_results ) {
120
+            if (is_a($view_results,'View') || is_string($view_results)) {
121
+                $this->response .= (string)$view_results;
122
+            } else {
123
+                $this->response_is_object = true;
124
+                $this->response_object 		= $view_results;
125
+            }
126
+          }
127 127
 
128 128
         } else if (is_a($callback,'View') || is_string($callback)) {
129 129
           // return rendered View or direct string
130
-        	$this->response .= (string)$callback;
130
+          $this->response .= (string)$callback;
131 131
         } else {
132 132
           // JSON encode returned value
133
-        	$this->response_is_object = true;
134
-        	$this->response_object 		= $callback;
133
+          $this->response_is_object = true;
134
+          $this->response_object 		= $callback;
135 135
         }
136 136
 
137 137
         // Apply afters
138 138
         if ( $this->afters ) {
139 139
           foreach ($this->afters as $mw) {
140
-	        	ob_start();
140
+            ob_start();
141 141
             $mw_result = call_user_func($mw->bindTo($this));
142
-          	$this->response .= ob_get_clean();
142
+            $this->response .= ob_get_clean();
143 143
             if ( false  === $mw_result ) {
144
-            	return [''];
144
+              return [''];
145 145
             } else if (is_a($mw_result,'View') || is_string($mw_result)) {
146 146
               $this->response .= (string)$mw_result;
147
-          	}
147
+            }
148 148
           }
149 149
         }
150 150
 
151 151
         Event::trigger('core.route.after', $this);
152 152
 
153 153
         if ( $this->response_is_object ){
154
-					$this->response = Response::json($this->response_object);
154
+          $this->response = Response::json($this->response_object);
155 155
         } else {
156
-					Response::add($this->response);
156
+          Response::add($this->response);
157 157
         }
158 158
 
159 159
         return [$this->response];
@@ -281,10 +281,10 @@  discard block
 block discarded – undo
281 281
         $route           = new static($URLPattern);
282 282
         $route->callback = [];
283 283
         foreach ($callbacks as $method => $callback) {
284
-           $method = strtolower($method);
285
-           if (Request::method() !== $method) continue;
286
-           $route->callback[$method] = $callback;
287
-           $route->methods[$method]  = 1;
284
+            $method = strtolower($method);
285
+            if (Request::method() !== $method) continue;
286
+            $route->callback[$method] = $callback;
287
+            $route->methods[$method]  = 1;
288 288
         }
289 289
         return $route;
290 290
     }
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
     }
387 387
 
388 388
     public static function exitWithError($code,$message="Application Error"){
389
-    	Response::error($code,$message);
390
-    	Response::send();
391
-    	exit;
389
+      Response::error($code,$message);
390
+      Response::send();
391
+      exit;
392 392
     }
393 393
 
394 394
     /**
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
      * @param string $method The HTTP method for which the route must respond.
39 39
      * @return Route
40 40
      */
41
-    public function __construct($URLPattern, $callback = null, $method='get'){
42
-        $this->URLPattern = rtrim(implode('',static::$prefix),'/') . '/' . trim($URLPattern,'/')?:'/';
43
-        $this->URLPattern = $this->URLPattern != '/' ? rtrim($this->URLPattern,'/') : $this->URLPattern;
41
+    public function __construct($URLPattern, $callback = null, $method = 'get') {
42
+        $this->URLPattern = rtrim(implode('', static::$prefix), '/').'/'.trim($URLPattern, '/') ?: '/';
43
+        $this->URLPattern = $this->URLPattern != '/' ? rtrim($this->URLPattern, '/') : $this->URLPattern;
44 44
         $this->dynamic    = $this->isDynamic($this->URLPattern);
45 45
         $this->pattern    = $this->dynamic ? $this->compilePatternAsRegex($this->URLPattern, $this->rules) : $this->URLPattern;
46 46
         $this->callback   = $callback;
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
      * @param  string $method The HTTP Method to check against.
57 57
      * @return boolean
58 58
      */
59
-    public function match($URL,$method='get'){
59
+    public function match($URL, $method = 'get') {
60 60
         $method = strtolower($method);
61 61
 
62 62
         // * is an http method wildcard
63 63
         if (empty($this->methods[$method]) && empty($this->methods['*'])) return false;
64
-        $URL = rtrim($URL,'/');
64
+        $URL = rtrim($URL, '/');
65 65
         $args = [];
66
-        if ( $this->dynamic
67
-               ? preg_match($this->pattern,$URL,$args)
68
-               : $URL == rtrim($this->pattern,'/')
69
-        ){
66
+        if ($this->dynamic
67
+               ? preg_match($this->pattern, $URL, $args)
68
+               : $URL == rtrim($this->pattern, '/')
69
+        ) {
70 70
             foreach ($args as $key => $value) {
71
-              if ( false === is_string($key) ) unset($args[$key]);
71
+              if (false === is_string($key)) unset($args[$key]);
72 72
             }
73 73
             return $args;
74 74
         }
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
      * @param  string $method The HTTP Method requested.
82 82
      * @return array The callback response.
83 83
      */
84
-    public function run(array $args, $method='get'){
84
+    public function run(array $args, $method = 'get') {
85 85
         $method = strtolower($method);
86
-        $this->response 			 		= '';
87
-        $this->response_object 		= null;
86
+        $this->response = '';
87
+        $this->response_object = null;
88 88
        	$this->response_is_object = false;
89 89
 
90 90
         // Call direct befores
91
-        if ( $this->befores ) {
91
+        if ($this->befores) {
92 92
           // Reverse befores order
93 93
           foreach (array_reverse($this->befores) as $mw) {
94 94
 	        	ob_start();
95 95
             $mw_result = call_user_func($mw->bindTo($this));
96 96
           	$this->response .= ob_get_clean();
97
-            if ( false  === $mw_result ) {
97
+            if (false === $mw_result) {
98 98
             	return [''];
99
-            } else if (is_a($mw_result,'View') || is_string($mw_result)) {
100
-              $this->response .= (string)$mw_result;
99
+            } else if (is_a($mw_result, 'View') || is_string($mw_result)) {
100
+              $this->response .= (string) $mw_result;
101 101
           	}
102 102
           }
103 103
         }
@@ -112,45 +112,45 @@  discard block
 block discarded – undo
112 112
 					Response::type(Response::TYPE_HTML);
113 113
 	        ob_start();
114 114
 	        // Silence "Cannot bind an instance to a static closure" warnings
115
-	        $view_results 	 = call_user_func_array(@$callback->bindTo($this), $args);
115
+	        $view_results = call_user_func_array(@$callback->bindTo($this), $args);
116 116
 	        $this->response .= ob_get_clean();
117 117
 
118 118
 	        // Render View if returned, else echo string or encode json response
119
-	        if ( null !== $view_results ) {
120
-	          if (is_a($view_results,'View') || is_string($view_results)) {
121
-	              $this->response .= (string)$view_results;
119
+	        if (null !== $view_results) {
120
+	          if (is_a($view_results, 'View') || is_string($view_results)) {
121
+	              $this->response .= (string) $view_results;
122 122
 	          } else {
123 123
 			        	$this->response_is_object = true;
124
-	              $this->response_object 		= $view_results;
124
+	              $this->response_object = $view_results;
125 125
 	          }
126 126
 	        }
127 127
 
128
-        } else if (is_a($callback,'View') || is_string($callback)) {
128
+        } else if (is_a($callback, 'View') || is_string($callback)) {
129 129
           // return rendered View or direct string
130
-        	$this->response .= (string)$callback;
130
+        	$this->response .= (string) $callback;
131 131
         } else {
132 132
           // JSON encode returned value
133 133
         	$this->response_is_object = true;
134
-        	$this->response_object 		= $callback;
134
+        	$this->response_object = $callback;
135 135
         }
136 136
 
137 137
         // Apply afters
138
-        if ( $this->afters ) {
138
+        if ($this->afters) {
139 139
           foreach ($this->afters as $mw) {
140 140
 	        	ob_start();
141 141
             $mw_result = call_user_func($mw->bindTo($this));
142 142
           	$this->response .= ob_get_clean();
143
-            if ( false  === $mw_result ) {
143
+            if (false === $mw_result) {
144 144
             	return [''];
145
-            } else if (is_a($mw_result,'View') || is_string($mw_result)) {
146
-              $this->response .= (string)$mw_result;
145
+            } else if (is_a($mw_result, 'View') || is_string($mw_result)) {
146
+              $this->response .= (string) $mw_result;
147 147
           	}
148 148
           }
149 149
         }
150 150
 
151 151
         Event::trigger('core.route.after', $this);
152 152
 
153
-        if ( $this->response_is_object ){
153
+        if ($this->response_is_object) {
154 154
 					$this->response = Response::json($this->response_object);
155 155
         } else {
156 156
 					Response::add($this->response);
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
      * @param  string $method The HTTP Method to check against.
168 168
      * @return array The callback response.
169 169
      */
170
-    public function runIfMatch($URL, $method='get'){
171
-        return ($args = $this->match($URL,$method)) ? $this->run($args,$method) : null;
170
+    public function runIfMatch($URL, $method = 'get') {
171
+        return ($args = $this->match($URL, $method)) ? $this->run($args, $method) : null;
172 172
     }
173 173
 
174 174
     /**
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
178 178
      * @return Route
179 179
      */
180
-    public static function on($URLPattern, $callback = null){
181
-        return new Route($URLPattern,$callback);
180
+    public static function on($URLPattern, $callback = null) {
181
+        return new Route($URLPattern, $callback);
182 182
     }
183 183
 
184 184
     /**
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
188 188
      * @return Route
189 189
      */
190
-    public static function any($URLPattern, $callback = null){
191
-        return (new Route($URLPattern,$callback))->via('*');
190
+    public static function any($URLPattern, $callback = null) {
191
+        return (new Route($URLPattern, $callback))->via('*');
192 192
     }
193 193
 
194 194
     /**
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function & via(){
235 235
         $this->methods = [];
236
-        foreach (func_get_args() as $method){
236
+        foreach (func_get_args() as $method) {
237 237
             $this->methods[strtolower($method)] = true;
238 238
         }
239 239
         return $this;
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
      * @return Route
256 256
      */
257 257
     public function & rules(array $rules){
258
-        foreach ((array)$rules as $varname => $rule){
258
+        foreach ((array) $rules as $varname => $rule) {
259 259
             $this->rules[$varname] = $rule;
260 260
         }
261
-        $this->pattern = $this->compilePatternAsRegex($this->URLPattern,$this->rules);
261
+        $this->pattern = $this->compilePatternAsRegex($this->URLPattern, $this->rules);
262 262
         return $this;
263 263
     }
264 264
 
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
      * @param  string $pattern The URL schema.
297 297
      * @return string The compiled PREG RegEx.
298 298
      */
299
-    protected static function compilePatternAsRegex($pattern, $rules=[]){
300
-        return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules){
301
-            return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
302
-        },str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
299
+    protected static function compilePatternAsRegex($pattern, $rules = []) {
300
+        return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S', function($g) use (&$rules){
301
+            return '(?<'.$g[1].'>'.(isset($rules[$g[1]]) ? $rules[$g[1]] : '[^/]+').')';
302
+        },str_replace(['.', ')', '*'], ['\.', ')?', '.+'], $pattern)).'$#';
303 303
     }
304 304
 
305 305
     /**
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
      * @param  boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
310 310
      * @return array The extracted variables
311 311
      */
312
-    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
312
+    protected static function extractVariablesFromURL($pattern, $URL = null, $cut = false) {
313 313
         $URL     = $URL ?: Request::URI();
314
-        $pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
315
-        if ( !preg_match($pattern,$URL,$args) ) return false;
314
+        $pattern = $cut ? str_replace('$#', '', $pattern).'#' : $pattern;
315
+        if (!preg_match($pattern, $URL, $args)) return false;
316 316
         foreach ($args as $key => $value) {
317 317
             if (false === is_string($key)) unset($args[$key]);
318 318
         }
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
      * @param  string  $pattern The URL schema.
325 325
      * @return boolean
326 326
      */
327
-    protected static function isDynamic($pattern){
328
-      return strlen($pattern) != strcspn($pattern,':(?[*+');
327
+    protected static function isDynamic($pattern) {
328
+      return strlen($pattern) != strcspn($pattern, ':(?[*+');
329 329
     }
330 330
 
331 331
     /**
@@ -333,9 +333,9 @@  discard block
 block discarded – undo
333 333
      * @param Route $r
334 334
      * @return Route
335 335
      */
336
-    public static function add($r){
337
-        if ( isset(static::$group[0]) ) static::$group[0]->add($r);
338
-        return static::$routes[implode('',static::$prefix)][] = $r;
336
+    public static function add($r) {
337
+        if (isset(static::$group[0])) static::$group[0]->add($r);
338
+        return static::$routes[implode('', static::$prefix)][] = $r;
339 339
     }
340 340
 
341 341
     /**
@@ -343,16 +343,16 @@  discard block
 block discarded – undo
343 343
      * @param  string $prefix The url prefix for the internal route definitions.
344 344
      * @param  string $callback This callback is invoked on $prefix match of the current request URI.
345 345
      */
346
-    public static function group($prefix,$callback=null){
346
+    public static function group($prefix, $callback = null) {
347 347
 
348 348
         // Skip definition if current request doesn't match group.
349 349
 
350
-        $prefix_complete = rtrim(implode('',static::$prefix),'/') . $prefix;
350
+        $prefix_complete = rtrim(implode('', static::$prefix), '/').$prefix;
351 351
 
352
-        if ( static::isDynamic($prefix) ){
352
+        if (static::isDynamic($prefix)) {
353 353
 
354 354
             // Dynamic group, capture vars
355
-            $vars = static::extractVariablesFromURL(static::compilePatternAsRegex($prefix_complete),null,true);
355
+            $vars = static::extractVariablesFromURL(static::compilePatternAsRegex($prefix_complete), null, true);
356 356
 
357 357
             // Errors in compile pattern or variable extraction, aborting.
358 358
             if (false === $vars) return;
@@ -360,14 +360,14 @@  discard block
 block discarded – undo
360 360
             static::$prefix[] = $prefix;
361 361
             if (empty(static::$group)) static::$group = [];
362 362
             array_unshift(static::$group, new RouteGroup());
363
-            if ($callback) call_user_func_array($callback,$vars);
363
+            if ($callback) call_user_func_array($callback, $vars);
364 364
             $group = static::$group[0];
365 365
             array_shift(static::$group);
366 366
             array_pop(static::$prefix);
367
-            if (empty(static::$prefix)) static::$prefix=[''];
367
+            if (empty(static::$prefix)) static::$prefix = [''];
368 368
             return $group;
369 369
 
370
-        } else if ( 0 === strpos(Request::URI(), $prefix_complete) ){
370
+        } else if (0 === strpos(Request::URI(), $prefix_complete)) {
371 371
 
372 372
             // Static group
373 373
             static::$prefix[] = $prefix;
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
             $group = static::$group[0];
378 378
             array_shift(static::$group);
379 379
             array_pop(static::$prefix);
380
-            if (empty(static::$prefix)) static::$prefix=[''];
380
+            if (empty(static::$prefix)) static::$prefix = [''];
381 381
             return $group;
382 382
         } else {
383 383
 
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 
388 388
     }
389 389
 
390
-    public static function exitWithError($code,$message="Application Error"){
391
-    	Response::error($code,$message);
390
+    public static function exitWithError($code, $message = "Application Error") {
391
+    	Response::error($code, $message);
392 392
     	Response::send();
393 393
     	exit;
394 394
     }
@@ -398,20 +398,20 @@  discard block
 block discarded – undo
398 398
      * @param  string $URL The URL to match onto.
399 399
      * @return boolean true if a route callback was executed.
400 400
      */
401
-    public static function dispatch($URL=null,$method=null){
401
+    public static function dispatch($URL = null, $method = null) {
402 402
         if (!$URL)     $URL     = Request::URI();
403 403
         if (!$method)  $method  = Request::method();
404 404
 
405
-        $__deferred_send = new Deferred(function(){
406
-          if (Options::get('core.response.autosend',false)){
405
+        $__deferred_send = new Deferred(function() {
406
+          if (Options::get('core.response.autosend', false)) {
407 407
             Response::send();
408 408
           }
409 409
         });
410 410
 
411
-        foreach ((array)static::$routes as $group => $routes){
411
+        foreach ((array) static::$routes as $group => $routes) {
412 412
             foreach ($routes as $route) {
413
-                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))){
414
-                    $route->run($args,$method);
413
+                if (is_a($route, 'Route') && false !== ($args = $route->match($URL, $method))) {
414
+                    $route->run($args, $method);
415 415
                     return true;
416 416
                 }
417 417
             }
@@ -426,34 +426,34 @@  discard block
 block discarded – undo
426 426
 class RouteGroup {
427 427
   protected $routes;
428 428
 
429
-  public function __construct(){
429
+  public function __construct() {
430 430
     $this->routes = new SplObjectStorage;
431 431
     return Route::add($this);
432 432
   }
433 433
 
434
-  public function has($r){
434
+  public function has($r) {
435 435
     return $this->routes->contains($r);
436 436
   }
437 437
 
438
-  public function add($r){
438
+  public function add($r) {
439 439
     $this->routes->attach($r);
440 440
     return $this;
441 441
   }
442 442
 
443
-  public function remove($r){
443
+  public function remove($r) {
444 444
     if ($this->routes->contains($r)) $this->routes->detach($r);
445 445
     return $this;
446 446
   }
447 447
 
448
-  public function before($callbacks){
449
-    foreach ($this->routes as $route){
448
+  public function before($callbacks) {
449
+    foreach ($this->routes as $route) {
450 450
       $route->before($callbacks);
451 451
     }
452 452
     return $this;
453 453
   }
454 454
 
455
-  public function after($callbacks){
456
-    foreach ($this->routes as $route){
455
+  public function after($callbacks) {
456
+    foreach ($this->routes as $route) {
457 457
       $route->after($callbacks);
458 458
     }
459 459
     return $this;
Please login to merge, or discard this patch.
Braces   +80 added lines, -48 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @param string $method The HTTP method for which the route must respond.
39 39
      * @return Route
40 40
      */
41
-    public function __construct($URLPattern, $callback = null, $method='get'){
41
+    public function __construct($URLPattern, $callback = null, $method='get') {
42 42
         $this->URLPattern = rtrim(implode('',static::$prefix),'/') . '/' . trim($URLPattern,'/')?:'/';
43 43
         $this->URLPattern = $this->URLPattern != '/' ? rtrim($this->URLPattern,'/') : $this->URLPattern;
44 44
         $this->dynamic    = $this->isDynamic($this->URLPattern);
@@ -56,19 +56,23 @@  discard block
 block discarded – undo
56 56
      * @param  string $method The HTTP Method to check against.
57 57
      * @return boolean
58 58
      */
59
-    public function match($URL,$method='get'){
59
+    public function match($URL,$method='get') {
60 60
         $method = strtolower($method);
61 61
 
62 62
         // * is an http method wildcard
63
-        if (empty($this->methods[$method]) && empty($this->methods['*'])) return false;
63
+        if (empty($this->methods[$method]) && empty($this->methods['*'])) {
64
+          return false;
65
+        }
64 66
         $URL = rtrim($URL,'/');
65 67
         $args = [];
66 68
         if ( $this->dynamic
67 69
                ? preg_match($this->pattern,$URL,$args)
68 70
                : $URL == rtrim($this->pattern,'/')
69
-        ){
71
+        ) {
70 72
             foreach ($args as $key => $value) {
71
-              if ( false === is_string($key) ) unset($args[$key]);
73
+              if ( false === is_string($key) ) {
74
+                unset($args[$key]);
75
+              }
72 76
             }
73 77
             return $args;
74 78
         }
@@ -81,7 +85,7 @@  discard block
 block discarded – undo
81 85
      * @param  string $method The HTTP Method requested.
82 86
      * @return array The callback response.
83 87
      */
84
-    public function run(array $args, $method='get'){
88
+    public function run(array $args, $method='get') {
85 89
         $method = strtolower($method);
86 90
         $this->response 			 		= '';
87 91
         $this->response_object 		= null;
@@ -150,7 +154,7 @@  discard block
 block discarded – undo
150 154
 
151 155
         Event::trigger('core.route.after', $this);
152 156
 
153
-        if ( $this->response_is_object ){
157
+        if ( $this->response_is_object ) {
154 158
 					$this->response = Response::json($this->response_object);
155 159
         } else {
156 160
 					Response::add($this->response);
@@ -167,7 +171,7 @@  discard block
 block discarded – undo
167 171
      * @param  string $method The HTTP Method to check against.
168 172
      * @return array The callback response.
169 173
      */
170
-    public function runIfMatch($URL, $method='get'){
174
+    public function runIfMatch($URL, $method='get') {
171 175
         return ($args = $this->match($URL,$method)) ? $this->run($args,$method) : null;
172 176
     }
173 177
 
@@ -177,7 +181,7 @@  discard block
 block discarded – undo
177 181
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
178 182
      * @return Route
179 183
      */
180
-    public static function on($URLPattern, $callback = null){
184
+    public static function on($URLPattern, $callback = null) {
181 185
         return new Route($URLPattern,$callback);
182 186
     }
183 187
 
@@ -187,7 +191,7 @@  discard block
 block discarded – undo
187 191
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
188 192
      * @return Route
189 193
      */
190
-    public static function any($URLPattern, $callback = null){
194
+    public static function any($URLPattern, $callback = null) {
191 195
         return (new Route($URLPattern,$callback))->via('*');
192 196
     }
193 197
 
@@ -233,7 +237,7 @@  discard block
 block discarded – undo
233 237
      */
234 238
     public function & via(){
235 239
         $this->methods = [];
236
-        foreach (func_get_args() as $method){
240
+        foreach (func_get_args() as $method) {
237 241
             $this->methods[strtolower($method)] = true;
238 242
         }
239 243
         return $this;
@@ -255,7 +259,7 @@  discard block
 block discarded – undo
255 259
      * @return Route
256 260
      */
257 261
     public function & rules(array $rules){
258
-        foreach ((array)$rules as $varname => $rule){
262
+        foreach ((array)$rules as $varname => $rule) {
259 263
             $this->rules[$varname] = $rule;
260 264
         }
261 265
         $this->pattern = $this->compilePatternAsRegex($this->URLPattern,$this->rules);
@@ -284,7 +288,9 @@  discard block
 block discarded – undo
284 288
         $route->callback = [];
285 289
         foreach ($callbacks as $method => $callback) {
286 290
            $method = strtolower($method);
287
-           if (Request::method() !== $method) continue;
291
+           if (Request::method() !== $method) {
292
+             continue;
293
+           }
288 294
            $route->callback[$method] = $callback;
289 295
            $route->methods[$method]  = 1;
290 296
         }
@@ -296,8 +302,8 @@  discard block
 block discarded – undo
296 302
      * @param  string $pattern The URL schema.
297 303
      * @return string The compiled PREG RegEx.
298 304
      */
299
-    protected static function compilePatternAsRegex($pattern, $rules=[]){
300
-        return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules){
305
+    protected static function compilePatternAsRegex($pattern, $rules=[]) {
306
+        return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules) {
301 307
             return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
302 308
         },str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
303 309
     }
@@ -309,12 +315,16 @@  discard block
 block discarded – undo
309 315
      * @param  boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
310 316
      * @return array The extracted variables
311 317
      */
312
-    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
318
+    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false) {
313 319
         $URL     = $URL ?: Request::URI();
314 320
         $pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
315
-        if ( !preg_match($pattern,$URL,$args) ) return false;
321
+        if ( !preg_match($pattern,$URL,$args) ) {
322
+          return false;
323
+        }
316 324
         foreach ($args as $key => $value) {
317
-            if (false === is_string($key)) unset($args[$key]);
325
+            if (false === is_string($key)) {
326
+              unset($args[$key]);
327
+            }
318 328
         }
319 329
         return $args;
320 330
     }
@@ -324,7 +334,7 @@  discard block
 block discarded – undo
324 334
      * @param  string  $pattern The URL schema.
325 335
      * @return boolean
326 336
      */
327
-    protected static function isDynamic($pattern){
337
+    protected static function isDynamic($pattern) {
328 338
       return strlen($pattern) != strcspn($pattern,':(?[*+');
329 339
     }
330 340
 
@@ -333,8 +343,10 @@  discard block
 block discarded – undo
333 343
      * @param Route $r
334 344
      * @return Route
335 345
      */
336
-    public static function add($r){
337
-        if ( isset(static::$group[0]) ) static::$group[0]->add($r);
346
+    public static function add($r) {
347
+        if ( isset(static::$group[0]) ) {
348
+          static::$group[0]->add($r);
349
+        }
338 350
         return static::$routes[implode('',static::$prefix)][] = $r;
339 351
     }
340 352
 
@@ -343,41 +355,55 @@  discard block
 block discarded – undo
343 355
      * @param  string $prefix The url prefix for the internal route definitions.
344 356
      * @param  string $callback This callback is invoked on $prefix match of the current request URI.
345 357
      */
346
-    public static function group($prefix,$callback=null){
358
+    public static function group($prefix,$callback=null) {
347 359
 
348 360
         // Skip definition if current request doesn't match group.
349 361
 
350 362
         $prefix_complete = rtrim(implode('',static::$prefix),'/') . $prefix;
351 363
 
352
-        if ( static::isDynamic($prefix) ){
364
+        if ( static::isDynamic($prefix) ) {
353 365
 
354 366
             // Dynamic group, capture vars
355 367
             $vars = static::extractVariablesFromURL(static::compilePatternAsRegex($prefix_complete),null,true);
356 368
 
357 369
             // Errors in compile pattern or variable extraction, aborting.
358
-            if (false === $vars) return;
370
+            if (false === $vars) {
371
+              return;
372
+            }
359 373
 
360 374
             static::$prefix[] = $prefix;
361
-            if (empty(static::$group)) static::$group = [];
375
+            if (empty(static::$group)) {
376
+              static::$group = [];
377
+            }
362 378
             array_unshift(static::$group, new RouteGroup());
363
-            if ($callback) call_user_func_array($callback,$vars);
379
+            if ($callback) {
380
+              call_user_func_array($callback,$vars);
381
+            }
364 382
             $group = static::$group[0];
365 383
             array_shift(static::$group);
366 384
             array_pop(static::$prefix);
367
-            if (empty(static::$prefix)) static::$prefix=[''];
385
+            if (empty(static::$prefix)) {
386
+              static::$prefix=[''];
387
+            }
368 388
             return $group;
369 389
 
370
-        } else if ( 0 === strpos(Request::URI(), $prefix_complete) ){
390
+        } else if ( 0 === strpos(Request::URI(), $prefix_complete) ) {
371 391
 
372 392
             // Static group
373 393
             static::$prefix[] = $prefix;
374
-            if (empty(static::$group)) static::$group = [];
394
+            if (empty(static::$group)) {
395
+              static::$group = [];
396
+            }
375 397
             array_unshift(static::$group, new RouteGroup());
376
-            if ($callback) call_user_func($callback);
398
+            if ($callback) {
399
+              call_user_func($callback);
400
+            }
377 401
             $group = static::$group[0];
378 402
             array_shift(static::$group);
379 403
             array_pop(static::$prefix);
380
-            if (empty(static::$prefix)) static::$prefix=[''];
404
+            if (empty(static::$prefix)) {
405
+              static::$prefix=[''];
406
+            }
381 407
             return $group;
382 408
         } else {
383 409
 
@@ -387,7 +413,7 @@  discard block
 block discarded – undo
387 413
 
388 414
     }
389 415
 
390
-    public static function exitWithError($code,$message="Application Error"){
416
+    public static function exitWithError($code,$message="Application Error") {
391 417
     	Response::error($code,$message);
392 418
     	Response::send();
393 419
     	exit;
@@ -398,19 +424,23 @@  discard block
 block discarded – undo
398 424
      * @param  string $URL The URL to match onto.
399 425
      * @return boolean true if a route callback was executed.
400 426
      */
401
-    public static function dispatch($URL=null,$method=null){
402
-        if (!$URL)     $URL     = Request::URI();
403
-        if (!$method)  $method  = Request::method();
427
+    public static function dispatch($URL=null,$method=null) {
428
+        if (!$URL) {
429
+          $URL     = Request::URI();
430
+        }
431
+        if (!$method) {
432
+          $method  = Request::method();
433
+        }
404 434
 
405
-        $__deferred_send = new Deferred(function(){
406
-          if (Options::get('core.response.autosend',false)){
435
+        $__deferred_send = new Deferred(function() {
436
+          if (Options::get('core.response.autosend',false)) {
407 437
             Response::send();
408 438
           }
409 439
         });
410 440
 
411
-        foreach ((array)static::$routes as $group => $routes){
441
+        foreach ((array)static::$routes as $group => $routes) {
412 442
             foreach ($routes as $route) {
413
-                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))){
443
+                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))) {
414 444
                     $route->run($args,$method);
415 445
                     return true;
416 446
                 }
@@ -426,34 +456,36 @@  discard block
 block discarded – undo
426 456
 class RouteGroup {
427 457
   protected $routes;
428 458
 
429
-  public function __construct(){
459
+  public function __construct() {
430 460
     $this->routes = new SplObjectStorage;
431 461
     return Route::add($this);
432 462
   }
433 463
 
434
-  public function has($r){
464
+  public function has($r) {
435 465
     return $this->routes->contains($r);
436 466
   }
437 467
 
438
-  public function add($r){
468
+  public function add($r) {
439 469
     $this->routes->attach($r);
440 470
     return $this;
441 471
   }
442 472
 
443
-  public function remove($r){
444
-    if ($this->routes->contains($r)) $this->routes->detach($r);
473
+  public function remove($r) {
474
+    if ($this->routes->contains($r)) {
475
+      $this->routes->detach($r);
476
+    }
445 477
     return $this;
446 478
   }
447 479
 
448
-  public function before($callbacks){
449
-    foreach ($this->routes as $route){
480
+  public function before($callbacks) {
481
+    foreach ($this->routes as $route) {
450 482
       $route->before($callbacks);
451 483
     }
452 484
     return $this;
453 485
   }
454 486
 
455
-  public function after($callbacks){
456
-    foreach ($this->routes as $route){
487
+  public function after($callbacks) {
488
+    foreach ($this->routes as $route) {
457 489
       $route->after($callbacks);
458 490
     }
459 491
     return $this;
Please login to merge, or discard this patch.
classes/View.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
     /**
31 31
      * Load a Template Handler
32
-     * @param  class $handler The template handler class instance
32
+     * @param  View\Adapter $handler The template handler class instance
33 33
      */
34 34
     public static function using(View\Adapter &$handler){
35 35
       static::$handler = $handler;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
     /**
71 71
      * Returns the handler instance
72
-     * @return mixed
72
+     * @return View\Adapter
73 73
      */
74 74
     public static function & handler(){
75 75
       return static::$handler;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * Construct a new view based on the passed template
24 24
      * @param  string $template The template path
25 25
      */
26
-    public function __construct($template){
26
+    public function __construct($template) {
27 27
       $this->options['template'] = $template;
28 28
     }
29 29
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * Load a Template Handler
32 32
      * @param  class $handler The template handler class instance
33 33
      */
34
-    public static function using(View\Adapter &$handler){
34
+    public static function using(View\Adapter & $handler) {
35 35
       static::$handler = $handler;
36 36
     }
37 37
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @param  array $data     The key-value map of data to pass to the view
42 42
      * @return View
43 43
      */
44
-    public static function from($template,$data=null){
44
+    public static function from($template, $data = null) {
45 45
       $view = new self($template);
46 46
       return $data ? $view->with($data) : $view;
47 47
     }
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
      * @param  array $data     The key-value map of data to pass to the view
52 52
      * @return View
53 53
      */
54
-    public function with($data){
55
-      if ($data){
56
-        $tmp = array_merge($data, (isset($this->options['data'])?$this->options['data']:[]));
54
+    public function with($data) {
55
+      if ($data) {
56
+        $tmp = array_merge($data, (isset($this->options['data']) ? $this->options['data'] : []));
57 57
         $this->options['data'] = $tmp;
58 58
       }
59 59
       return $this;
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
      * Render view when casted to a string
64 64
      * @return string The rendered view
65 65
      */
66
-    public function __toString(){
67
-      return Filter::with('core.view',static::$handler->render($this->options['template'],$this->options['data']));
66
+    public function __toString() {
67
+      return Filter::with('core.view', static::$handler->render($this->options['template'], $this->options['data']));
68 68
     }
69 69
 
70 70
     /**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * Check if a template exists
80 80
      * @return bool
81 81
      */
82
-    public static function exists($templatePath){
82
+    public static function exists($templatePath) {
83 83
       return static::$handler->exists($templatePath);
84 84
     }
85 85
 
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
     /**
88 88
      * Propagate the call to the handler
89 89
      */
90
-    public function __call($n,$p){
91
-      return call_user_func_array([static::$handler,$n],$p);
90
+    public function __call($n, $p) {
91
+      return call_user_func_array([static::$handler, $n], $p);
92 92
     }
93 93
 
94 94
     /**
95 95
      * Propagate the static call to the handler
96 96
      */
97
-    public static function __callStatic($n,$p){
98
-      return forward_static_call_array([static::$handler,$n],$p);
97
+    public static function __callStatic($n, $p) {
98
+      return forward_static_call_array([static::$handler, $n], $p);
99 99
     }
100 100
 
101 101
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * Construct a new view based on the passed template
24 24
      * @param  string $template The template path
25 25
      */
26
-    public function __construct($template){
26
+    public function __construct($template) {
27 27
       $this->options['template'] = $template;
28 28
     }
29 29
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * Load a Template Handler
32 32
      * @param  class $handler The template handler class instance
33 33
      */
34
-    public static function using(View\Adapter &$handler){
34
+    public static function using(View\Adapter &$handler) {
35 35
       static::$handler = $handler;
36 36
     }
37 37
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @param  array $data     The key-value map of data to pass to the view
42 42
      * @return View
43 43
      */
44
-    public static function from($template,$data=null){
44
+    public static function from($template,$data=null) {
45 45
       $view = new self($template);
46 46
       return $data ? $view->with($data) : $view;
47 47
     }
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
      * @param  array $data     The key-value map of data to pass to the view
52 52
      * @return View
53 53
      */
54
-    public function with($data){
55
-      if ($data){
54
+    public function with($data) {
55
+      if ($data) {
56 56
         $tmp = array_merge($data, (isset($this->options['data'])?$this->options['data']:[]));
57 57
         $this->options['data'] = $tmp;
58 58
       }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * Render view when casted to a string
64 64
      * @return string The rendered view
65 65
      */
66
-    public function __toString(){
66
+    public function __toString() {
67 67
       return Filter::with('core.view',static::$handler->render($this->options['template'],$this->options['data']));
68 68
     }
69 69
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * Check if a template exists
80 80
      * @return bool
81 81
      */
82
-    public static function exists($templatePath){
82
+    public static function exists($templatePath) {
83 83
       return static::$handler->exists($templatePath);
84 84
     }
85 85
 
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
     /**
88 88
      * Propagate the call to the handler
89 89
      */
90
-    public function __call($n,$p){
90
+    public function __call($n,$p) {
91 91
       return call_user_func_array([static::$handler,$n],$p);
92 92
     }
93 93
 
94 94
     /**
95 95
      * Propagate the static call to the handler
96 96
      */
97
-    public static function __callStatic($n,$p){
97
+    public static function __callStatic($n,$p) {
98 98
       return forward_static_call_array([static::$handler,$n],$p);
99 99
     }
100 100
 
Please login to merge, or discard this patch.
classes/SQL.php 4 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -101,6 +101,11 @@
 block discarded – undo
101 101
             $queries           = [],
102 102
             $last_exec_success = true;
103 103
 
104
+  /**
105
+   * @param string $dsn
106
+   * @param string $username
107
+   * @param string $password
108
+   */
104 109
   public function __construct($dsn, $username=null, $password=null, $options=[]){
105 110
     $this->connection = [
106 111
       'dsn'        => $dsn,
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 class SQL {
15 15
   use Module;
16 16
   protected static $connections = [],
17
-                   $current     = 'default';
17
+                    $current     = 'default';
18 18
 
19 19
   /**
20 20
    * Register a new datasource
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
     }
209 209
   }
210 210
 
211
- public function run($script){
211
+  public function run($script){
212 212
     if(!$this->connection()) return false;
213 213
 
214 214
     $sql_path = Options::get('database.sql.path',APP_DIR.'/sql');
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
   }
224 224
 
225 225
   public function all($query, $params=[], callable $looper = null){
226
-   if(!$this->connection()) return false;
227
-   return $this->each($query,$params,$looper);
226
+    if(!$this->connection()) return false;
227
+    return $this->each($query,$params,$looper);
228 228
   }
229 229
 
230 230
   public function delete($table, $pks=null, $pk='id', $inclusive=true){
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
    * @param  array  $options  Options to pass to the PDO constructor
26 26
    * @return SQLConnection    The datasource resource
27 27
    */
28
-  public static function register($name, $dsn, $username=null, $password=null, $options=[]){
28
+  public static function register($name, $dsn, $username = null, $password = null, $options = []) {
29 29
     return self::$connections[$name] = new SQLConnection($dsn, $username, $password, $options);
30 30
   }
31 31
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
    * @param  array  $options  Options to pass to the PDO constructor
38 38
    * @return SQLConnection    The datasource resource
39 39
    */
40
-  public static function connect($dsn, $username=null, $password=null, $options=[]){
40
+  public static function connect($dsn, $username = null, $password = null, $options = []) {
41 41
     return self::register('default', $dsn, $username, $password, $options);
42 42
   }
43 43
 
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
    * @param  string $name The datasource name
47 47
    * @return bool       `true` if correctly changed
48 48
    */
49
-  public static function defaultTo($name){
50
-    if (isset(self::$connections[$name])){
49
+  public static function defaultTo($name) {
50
+    if (isset(self::$connections[$name])) {
51 51
       self::$current = $name;
52 52
       return true;
53 53
     } else return false;
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
    * @param  string $name The datasource name, omit for close all of them
59 59
    * @return bool       `true` if one or more datasource where closed
60 60
    */
61
-  public static function close($name=null){
61
+  public static function close($name = null) {
62 62
     if ($name === null) {
63 63
       foreach (self::$connections as $conn) $conn->close();
64 64
       return true;
65
-    } else if (isset(self::$connections[$name])){
65
+    } else if (isset(self::$connections[$name])) {
66 66
       self::$connections[$name]->close();
67 67
       return true;
68 68
     } else return false;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
    * @param  strinf $name The datasource name
74 74
    * @return SQLConnect   The datasource connection
75 75
    */
76
-  public static function using($name){
76
+  public static function using($name) {
77 77
     if (empty(self::$connections[$name])) throw new \Exception("[SQL] Unknown connection named '$name'.");
78 78
     return self::$connections[$name];
79 79
   }
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
    * @param  array $args    The method arguments
85 85
    * @return mixed          The method return value
86 86
    */
87
-  public static function __callStatic($method, $args){
87
+  public static function __callStatic($method, $args) {
88 88
     if (empty(self::$connections[self::$current])) throw new \Exception("[SQL] No default connection defined.");
89
-    return call_user_func_array([self::$connections[self::$current],$method],$args);
89
+    return call_user_func_array([self::$connections[self::$current], $method], $args);
90 90
   }
91 91
 
92 92
 }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             $queries           = [],
102 102
             $last_exec_success = true;
103 103
 
104
-  public function __construct($dsn, $username=null, $password=null, $options=[]){
104
+  public function __construct($dsn, $username = null, $password = null, $options = []) {
105 105
     $this->connection = [
106 106
       'dsn'        => $dsn,
107 107
       'pdo'        => null,
@@ -111,20 +111,20 @@  discard block
 block discarded – undo
111 111
         PDO::ATTR_ERRMODE              => PDO::ERRMODE_EXCEPTION,
112 112
         PDO::ATTR_DEFAULT_FETCH_MODE   => PDO::FETCH_ASSOC,
113 113
         PDO::ATTR_EMULATE_PREPARES     => true,
114
-      ],$options),
114
+      ], $options),
115 115
     ];
116 116
     // "The auto-commit mode cannot be changed for this driver" SQLite workaround
117
-    if (strpos($dsn,'sqlite:') === 0) {
117
+    if (strpos($dsn, 'sqlite:') === 0) {
118 118
       $this->connection['options'] = $options;
119 119
     }
120 120
   }
121 121
 
122
-  public function close(){
122
+  public function close() {
123 123
     $this->connection['pdo'] = null;
124 124
   }
125 125
 
126
-  public function connection(){
127
-    if(empty($this->connection['pdo'])) {
126
+  public function connection() {
127
+    if (empty($this->connection['pdo'])) {
128 128
       try {
129 129
         $this->connection['pdo'] = new PDO(
130 130
             $this->connection['dsn'],
@@ -133,26 +133,26 @@  discard block
 block discarded – undo
133 133
             $this->connection['options']
134 134
 
135 135
         );
136
-        Event::trigger('core.sql.connect',$this);
137
-      } catch(Exception $e) {
136
+        Event::trigger('core.sql.connect', $this);
137
+      } catch (Exception $e) {
138 138
         $this->connection['pdo'] = null;
139 139
       }
140 140
     }
141 141
     return $this->connection['pdo'];
142 142
   }
143 143
 
144
-  public function prepare($query){
145
-    if(!$this->connection()) return false;
144
+  public function prepare($query) {
145
+    if (!$this->connection()) return false;
146 146
     return isset($this->queries[$query]) ? $this->queries[$query] : ($this->queries[$query] = $this->connection()->prepare($query));
147 147
   }
148 148
 
149
-  public function exec($query, $params=[]){
150
-    if(!$this->connection()) return false;
149
+  public function exec($query, $params = []) {
150
+    if (!$this->connection()) return false;
151 151
 
152
-    if (false==is_array($params)) $params = (array)$params;
153
-    $query = Filter::with('core.sql.query',$query);
154
-    if($statement = $this->prepare($query)){
155
-      Event::trigger('core.sql.query',$query,$params,(bool)$statement);
152
+    if (false == is_array($params)) $params = (array) $params;
153
+    $query = Filter::with('core.sql.query', $query);
154
+    if ($statement = $this->prepare($query)) {
155
+      Event::trigger('core.sql.query', $query, $params, (bool) $statement);
156 156
 
157 157
       foreach ($params as $key => $val) {
158 158
         $type = PDO::PARAM_STR;
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
           $type = PDO::PARAM_INT;
165 165
         }
166 166
         // bindValue need a 1-based numeric parameter
167
-        $statement->bindValue(is_numeric($key)?$key+1:':'.$key, $val, $type);
167
+        $statement->bindValue(is_numeric($key) ? $key + 1 : ':'.$key, $val, $type);
168 168
       }
169 169
     } else {
170
-      Event::trigger('core.sql.error',$query,$params);
170
+      Event::trigger('core.sql.error', $query, $params);
171 171
       return false;
172 172
     }
173 173
 
@@ -175,32 +175,32 @@  discard block
 block discarded – undo
175 175
     return $statement;
176 176
   }
177 177
 
178
-  public function value($query, $params=[], $column=0){
179
-    if(!$this->connection()) return false;
178
+  public function value($query, $params = [], $column = 0) {
179
+    if (!$this->connection()) return false;
180 180
 
181
-    $res = $this->exec($query,$params);
181
+    $res = $this->exec($query, $params);
182 182
     return $res ? $res->fetchColumn($column) : null;
183 183
   }
184 184
 
185
-  public function each($query, $params=[], callable $looper = null){
186
-    if(!$this->connection()) return false;
185
+  public function each($query, $params = [], callable $looper = null) {
186
+    if (!$this->connection()) return false;
187 187
 
188 188
     // ($query,$looper) shorthand
189
-    if ($looper===null && is_callable($params)) {$looper = $params; $params = [];}
190
-    if( $res = $this->exec($query,$params) ){
191
-      if(is_callable($looper))
189
+    if ($looper === null && is_callable($params)) {$looper = $params;$params = [];}
190
+    if ($res = $this->exec($query, $params)) {
191
+      if (is_callable($looper))
192 192
         while ($row = $res->fetchObject()) $looper($row);
193 193
       else
194 194
         return $res->fetchAll(PDO::FETCH_CLASS);
195 195
     }
196 196
   }
197 197
 
198
-  public function single($query, $params=[], callable $handler = null){
199
-    if(!$this->connection()) return false;
198
+  public function single($query, $params = [], callable $handler = null) {
199
+    if (!$this->connection()) return false;
200 200
 
201 201
     // ($query,$handler) shorthand
202
-    if ($handler===null && is_callable($params)) {$handler = $params; $params = [];}
203
-    if( $res = $this->exec($query,$params) ){
202
+    if ($handler === null && is_callable($params)) {$handler = $params;$params = [];}
203
+    if ($res = $this->exec($query, $params)) {
204 204
         if (is_callable($handler))
205 205
           $handler($res->fetchObject());
206 206
         else
@@ -208,76 +208,76 @@  discard block
 block discarded – undo
208 208
     }
209 209
   }
210 210
 
211
- public function run($script){
212
-    if(!$this->connection()) return false;
211
+ public function run($script) {
212
+    if (!$this->connection()) return false;
213 213
 
214
-    $sql_path = Options::get('database.sql.path',APP_DIR.'/sql');
215
-    $sql_sep  = Options::get('database.sql.separator',';');
216
-    if (is_file($f = "$sql_path/$script.sql")){
214
+    $sql_path = Options::get('database.sql.path', APP_DIR.'/sql');
215
+    $sql_sep  = Options::get('database.sql.separator', ';');
216
+    if (is_file($f = "$sql_path/$script.sql")) {
217 217
         $result = true;
218
-        foreach(explode($sql_sep,file_get_contents($f)) as $statement) {
218
+        foreach (explode($sql_sep, file_get_contents($f)) as $statement) {
219 219
             $result = $this->exec($statement);
220 220
         }
221 221
         return $result;
222 222
     } else return false;
223 223
   }
224 224
 
225
-  public function all($query, $params=[], callable $looper = null){
226
-   if(!$this->connection()) return false;
227
-   return $this->each($query,$params,$looper);
225
+  public function all($query, $params = [], callable $looper = null) {
226
+   if (!$this->connection()) return false;
227
+   return $this->each($query, $params, $looper);
228 228
   }
229 229
 
230
-  public function delete($table, $pks=null, $pk='id', $inclusive=true){
231
-    if(!$this->connection()) return false;
230
+  public function delete($table, $pks = null, $pk = 'id', $inclusive = true) {
231
+    if (!$this->connection()) return false;
232 232
 
233
-    if (null===$pks) {
233
+    if (null === $pks) {
234 234
       return $this->exec("DELETE FROM `$table`");
235 235
     } else {
236
-      return $this->exec("DELETE FROM `$table` WHERE `$pk` ".($inclusive ? "" : "NOT " )."IN (" . implode( ',', array_fill_keys( (array)$pks, '?' ) ) . ")",(array)$pks);
236
+      return $this->exec("DELETE FROM `$table` WHERE `$pk` ".($inclusive ? "" : "NOT ")."IN (".implode(',', array_fill_keys((array) $pks, '?')).")", (array) $pks);
237 237
     }
238 238
   }
239 239
 
240
-  public function insert($table, $data){
241
-    if(!$this->connection()) return false;
240
+  public function insert($table, $data) {
241
+    if (!$this->connection()) return false;
242 242
 
243
-    if (false==is_array($data)) $data = (array)$data;
243
+    if (false == is_array($data)) $data = (array) $data;
244 244
     $k = array_keys($data);
245 245
     asort($k);
246 246
     $pk = $k;
247
-    array_walk($pk,function(&$e){ $e = ':'.$e;});
248
-    $q = "INSERT INTO `$table` (`".implode('`,`',$k)."`) VALUES (".implode(',',$pk).")";
249
-    $this->exec($q,$data);
247
+    array_walk($pk, function(&$e) { $e = ':'.$e;});
248
+    $q = "INSERT INTO `$table` (`".implode('`,`', $k)."`) VALUES (".implode(',', $pk).")";
249
+    $this->exec($q, $data);
250 250
     return $this->last_exec_success ? $this->connection()->lastInsertId() : false;
251 251
   }
252 252
 
253
-  public function updateWhere($table, $data, $where, $pk='id'){
254
-    if(!$this->connection()) return false;
253
+  public function updateWhere($table, $data, $where, $pk = 'id') {
254
+    if (!$this->connection()) return false;
255 255
 
256
-    if (false==is_array($data)) $data = (array)$data;
256
+    if (false == is_array($data)) $data = (array) $data;
257 257
     if (empty($data)) return false;
258 258
     $k = array_keys($data);
259 259
     asort($k);
260 260
 
261 261
     // Remove primary key from SET
262
-    array_walk($k,function(&$e) use ($pk) {
263
-      $e = ($e==$pk) ? null : "`$e`=:$e";
262
+    array_walk($k, function(&$e) use ($pk) {
263
+      $e = ($e == $pk) ? null : "`$e`=:$e";
264 264
     });
265 265
 
266
-    $q = "UPDATE `$table` SET ".implode(', ',array_filter($k))." WHERE $where";
267
-    $this->exec($q,$data);
266
+    $q = "UPDATE `$table` SET ".implode(', ', array_filter($k))." WHERE $where";
267
+    $this->exec($q, $data);
268 268
     return $this->last_exec_success;
269 269
   }
270 270
 
271
-  public function update($table, $data, $pk='id', $extra_where=''){
271
+  public function update($table, $data, $pk = 'id', $extra_where = '') {
272 272
     return $this->updateWhere($table, $data, "`$pk`=:$pk $extra_where", $pk);
273 273
   }
274 274
 
275
-  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where=''){
276
-    if(!$this->connection()) return false;
275
+  public function insertOrUpdate($table, $data = [], $pk = 'id', $extra_where = '') {
276
+    if (!$this->connection()) return false;
277 277
 
278
-    if (false==is_array($data)) $data = (array)$data;
278
+    if (false == is_array($data)) $data = (array) $data;
279 279
     if (empty($data[$pk])) return $this->insert($table, $data);
280
-    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ){
280
+    if ((string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk]) {
281 281
         return $this->update($table, $data, $pk, $extra_where);
282 282
     } else {
283 283
         return $this->insert($table, $data);
Please login to merge, or discard this patch.
Braces   +104 added lines, -58 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
    * @param  array  $options  Options to pass to the PDO constructor
26 26
    * @return SQLConnection    The datasource resource
27 27
    */
28
-  public static function register($name, $dsn, $username=null, $password=null, $options=[]){
28
+  public static function register($name, $dsn, $username=null, $password=null, $options=[]) {
29 29
     return self::$connections[$name] = new SQLConnection($dsn, $username, $password, $options);
30 30
   }
31 31
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
    * @param  array  $options  Options to pass to the PDO constructor
38 38
    * @return SQLConnection    The datasource resource
39 39
    */
40
-  public static function connect($dsn, $username=null, $password=null, $options=[]){
40
+  public static function connect($dsn, $username=null, $password=null, $options=[]) {
41 41
     return self::register('default', $dsn, $username, $password, $options);
42 42
   }
43 43
 
@@ -46,11 +46,13 @@  discard block
 block discarded – undo
46 46
    * @param  string $name The datasource name
47 47
    * @return bool       `true` if correctly changed
48 48
    */
49
-  public static function defaultTo($name){
50
-    if (isset(self::$connections[$name])){
49
+  public static function defaultTo($name) {
50
+    if (isset(self::$connections[$name])) {
51 51
       self::$current = $name;
52 52
       return true;
53
-    } else return false;
53
+    } else {
54
+      return false;
55
+    }
54 56
   }
55 57
 
56 58
   /**
@@ -58,14 +60,16 @@  discard block
 block discarded – undo
58 60
    * @param  string $name The datasource name, omit for close all of them
59 61
    * @return bool       `true` if one or more datasource where closed
60 62
    */
61
-  public static function close($name=null){
63
+  public static function close($name=null) {
62 64
     if ($name === null) {
63 65
       foreach (self::$connections as $conn) $conn->close();
64 66
       return true;
65
-    } else if (isset(self::$connections[$name])){
67
+    } else if (isset(self::$connections[$name])) {
66 68
       self::$connections[$name]->close();
67 69
       return true;
68
-    } else return false;
70
+    } else {
71
+      return false;
72
+    }
69 73
   }
70 74
 
71 75
   /**
@@ -73,8 +77,10 @@  discard block
 block discarded – undo
73 77
    * @param  strinf $name The datasource name
74 78
    * @return SQLConnect   The datasource connection
75 79
    */
76
-  public static function using($name){
77
-    if (empty(self::$connections[$name])) throw new \Exception("[SQL] Unknown connection named '$name'.");
80
+  public static function using($name) {
81
+    if (empty(self::$connections[$name])) {
82
+      throw new \Exception("[SQL] Unknown connection named '$name'.");
83
+    }
78 84
     return self::$connections[$name];
79 85
   }
80 86
 
@@ -84,8 +90,10 @@  discard block
 block discarded – undo
84 90
    * @param  array $args    The method arguments
85 91
    * @return mixed          The method return value
86 92
    */
87
-  public static function __callStatic($method, $args){
88
-    if (empty(self::$connections[self::$current])) throw new \Exception("[SQL] No default connection defined.");
93
+  public static function __callStatic($method, $args) {
94
+    if (empty(self::$connections[self::$current])) {
95
+      throw new \Exception("[SQL] No default connection defined.");
96
+    }
89 97
     return call_user_func_array([self::$connections[self::$current],$method],$args);
90 98
   }
91 99
 
@@ -101,7 +109,7 @@  discard block
 block discarded – undo
101 109
             $queries           = [],
102 110
             $last_exec_success = true;
103 111
 
104
-  public function __construct($dsn, $username=null, $password=null, $options=[]){
112
+  public function __construct($dsn, $username=null, $password=null, $options=[]) {
105 113
     $this->connection = [
106 114
       'dsn'        => $dsn,
107 115
       'pdo'        => null,
@@ -119,11 +127,11 @@  discard block
 block discarded – undo
119 127
     }
120 128
   }
121 129
 
122
-  public function close(){
130
+  public function close() {
123 131
     $this->connection['pdo'] = null;
124 132
   }
125 133
 
126
-  public function connection(){
134
+  public function connection() {
127 135
     if(empty($this->connection['pdo'])) {
128 136
       try {
129 137
         $this->connection['pdo'] = new PDO(
@@ -141,17 +149,23 @@  discard block
 block discarded – undo
141 149
     return $this->connection['pdo'];
142 150
   }
143 151
 
144
-  public function prepare($query){
145
-    if(!$this->connection()) return false;
152
+  public function prepare($query) {
153
+    if(!$this->connection()) {
154
+      return false;
155
+    }
146 156
     return isset($this->queries[$query]) ? $this->queries[$query] : ($this->queries[$query] = $this->connection()->prepare($query));
147 157
   }
148 158
 
149
-  public function exec($query, $params=[]){
150
-    if(!$this->connection()) return false;
159
+  public function exec($query, $params=[]) {
160
+    if(!$this->connection()) {
161
+      return false;
162
+    }
151 163
 
152
-    if (false==is_array($params)) $params = (array)$params;
164
+    if (false==is_array($params)) {
165
+      $params = (array)$params;
166
+    }
153 167
     $query = Filter::with('core.sql.query',$query);
154
-    if($statement = $this->prepare($query)){
168
+    if($statement = $this->prepare($query)) {
155 169
       Event::trigger('core.sql.query',$query,$params,(bool)$statement);
156 170
 
157 171
       foreach ($params as $key => $val) {
@@ -175,60 +189,76 @@  discard block
 block discarded – undo
175 189
     return $statement;
176 190
   }
177 191
 
178
-  public function value($query, $params=[], $column=0){
179
-    if(!$this->connection()) return false;
192
+  public function value($query, $params=[], $column=0) {
193
+    if(!$this->connection()) {
194
+      return false;
195
+    }
180 196
 
181 197
     $res = $this->exec($query,$params);
182 198
     return $res ? $res->fetchColumn($column) : null;
183 199
   }
184 200
 
185
-  public function each($query, $params=[], callable $looper = null){
186
-    if(!$this->connection()) return false;
201
+  public function each($query, $params=[], callable $looper = null) {
202
+    if(!$this->connection()) {
203
+      return false;
204
+    }
187 205
 
188 206
     // ($query,$looper) shorthand
189 207
     if ($looper===null && is_callable($params)) {$looper = $params; $params = [];}
190
-    if( $res = $this->exec($query,$params) ){
191
-      if(is_callable($looper))
192
-        while ($row = $res->fetchObject()) $looper($row);
193
-      else
194
-        return $res->fetchAll(PDO::FETCH_CLASS);
208
+    if( $res = $this->exec($query,$params) ) {
209
+      if(is_callable($looper)) {
210
+              while ($row = $res->fetchObject()) $looper($row);
211
+      } else {
212
+              return $res->fetchAll(PDO::FETCH_CLASS);
213
+      }
195 214
     }
196 215
   }
197 216
 
198
-  public function single($query, $params=[], callable $handler = null){
199
-    if(!$this->connection()) return false;
217
+  public function single($query, $params=[], callable $handler = null) {
218
+    if(!$this->connection()) {
219
+      return false;
220
+    }
200 221
 
201 222
     // ($query,$handler) shorthand
202 223
     if ($handler===null && is_callable($params)) {$handler = $params; $params = [];}
203
-    if( $res = $this->exec($query,$params) ){
204
-        if (is_callable($handler))
205
-          $handler($res->fetchObject());
206
-        else
207
-          return $res->fetchObject();
224
+    if( $res = $this->exec($query,$params) ) {
225
+        if (is_callable($handler)) {
226
+                  $handler($res->fetchObject());
227
+        } else {
228
+                  return $res->fetchObject();
229
+        }
208 230
     }
209 231
   }
210 232
 
211
- public function run($script){
212
-    if(!$this->connection()) return false;
233
+ public function run($script) {
234
+    if(!$this->connection()) {
235
+      return false;
236
+    }
213 237
 
214 238
     $sql_path = Options::get('database.sql.path',APP_DIR.'/sql');
215 239
     $sql_sep  = Options::get('database.sql.separator',';');
216
-    if (is_file($f = "$sql_path/$script.sql")){
240
+    if (is_file($f = "$sql_path/$script.sql")) {
217 241
         $result = true;
218 242
         foreach(explode($sql_sep,file_get_contents($f)) as $statement) {
219 243
             $result = $this->exec($statement);
220 244
         }
221 245
         return $result;
222
-    } else return false;
246
+    } else {
247
+      return false;
248
+    }
223 249
   }
224 250
 
225
-  public function all($query, $params=[], callable $looper = null){
226
-   if(!$this->connection()) return false;
251
+  public function all($query, $params=[], callable $looper = null) {
252
+   if(!$this->connection()) {
253
+     return false;
254
+   }
227 255
    return $this->each($query,$params,$looper);
228 256
   }
229 257
 
230
-  public function delete($table, $pks=null, $pk='id', $inclusive=true){
231
-    if(!$this->connection()) return false;
258
+  public function delete($table, $pks=null, $pk='id', $inclusive=true) {
259
+    if(!$this->connection()) {
260
+      return false;
261
+    }
232 262
 
233 263
     if (null===$pks) {
234 264
       return $this->exec("DELETE FROM `$table`");
@@ -237,10 +267,14 @@  discard block
 block discarded – undo
237 267
     }
238 268
   }
239 269
 
240
-  public function insert($table, $data){
241
-    if(!$this->connection()) return false;
270
+  public function insert($table, $data) {
271
+    if(!$this->connection()) {
272
+      return false;
273
+    }
242 274
 
243
-    if (false==is_array($data)) $data = (array)$data;
275
+    if (false==is_array($data)) {
276
+      $data = (array)$data;
277
+    }
244 278
     $k = array_keys($data);
245 279
     asort($k);
246 280
     $pk = $k;
@@ -250,11 +284,17 @@  discard block
 block discarded – undo
250 284
     return $this->last_exec_success ? $this->connection()->lastInsertId() : false;
251 285
   }
252 286
 
253
-  public function updateWhere($table, $data, $where, $pk='id'){
254
-    if(!$this->connection()) return false;
287
+  public function updateWhere($table, $data, $where, $pk='id') {
288
+    if(!$this->connection()) {
289
+      return false;
290
+    }
255 291
 
256
-    if (false==is_array($data)) $data = (array)$data;
257
-    if (empty($data)) return false;
292
+    if (false==is_array($data)) {
293
+      $data = (array)$data;
294
+    }
295
+    if (empty($data)) {
296
+      return false;
297
+    }
258 298
     $k = array_keys($data);
259 299
     asort($k);
260 300
 
@@ -268,16 +308,22 @@  discard block
 block discarded – undo
268 308
     return $this->last_exec_success;
269 309
   }
270 310
 
271
-  public function update($table, $data, $pk='id', $extra_where=''){
311
+  public function update($table, $data, $pk='id', $extra_where='') {
272 312
     return $this->updateWhere($table, $data, "`$pk`=:$pk $extra_where", $pk);
273 313
   }
274 314
 
275
-  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where=''){
276
-    if(!$this->connection()) return false;
315
+  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where='') {
316
+    if(!$this->connection()) {
317
+      return false;
318
+    }
277 319
 
278
-    if (false==is_array($data)) $data = (array)$data;
279
-    if (empty($data[$pk])) return $this->insert($table, $data);
280
-    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ){
320
+    if (false==is_array($data)) {
321
+      $data = (array)$data;
322
+    }
323
+    if (empty($data[$pk])) {
324
+      return $this->insert($table, $data);
325
+    }
326
+    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ) {
281 327
         return $this->update($table, $data, $pk, $extra_where);
282 328
     } else {
283 329
         return $this->insert($table, $data);
Please login to merge, or discard this patch.
classes/Response.php 4 patches
Doc Comments   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
     /**
91 91
      * Check if an response output buffering is active.
92
-     * @return boolean
92
+     * @return boolean|null
93 93
      */
94 94
     public static function isBuffering(){
95 95
         return static::$buffer;
@@ -113,7 +113,6 @@  discard block
 block discarded – undo
113 113
 
114 114
     /**
115 115
      * Append a text to the buffer.
116
-     * @param  mixed $payload Text to append to the response buffer
117 116
      */
118 117
     public static function text(){
119 118
         static::type(static::TYPE_TEXT);
@@ -122,7 +121,6 @@  discard block
 block discarded – undo
122 121
 
123 122
     /**
124 123
      * Append an XML string to the buffer.
125
-     * @param  mixed $payload Data to append to the response buffer
126 124
      */
127 125
     public static function xml(){
128 126
         static::type(static::TYPE_XML);
@@ -131,7 +129,6 @@  discard block
 block discarded – undo
131 129
 
132 130
     /**
133 131
      * Append a SVG string to the buffer.
134
-     * @param  mixed $payload Data to append to the response buffer
135 132
      */
136 133
     public static function svg(){
137 134
         static::type(static::TYPE_SVG);
@@ -140,7 +137,6 @@  discard block
 block discarded – undo
140 137
 
141 138
     /**
142 139
      * Append an HTML string to the buffer.
143
-     * @param  mixed $payload Data to append to the response buffer
144 140
      */
145 141
     public static function html(){
146 142
         static::type(static::TYPE_HTML);
@@ -149,16 +145,21 @@  discard block
 block discarded – undo
149 145
 
150 146
     /**
151 147
      * Append a raw string to the buffer.
152
-     * @param  mixed $payload Data to append to the response buffer
153 148
      */
154 149
     public static function add(){
155 150
         static::$payload[] = implode('',func_get_args());
156 151
     }
157 152
 
153
+    /**
154
+     * @param integer $code
155
+     */
158 156
     public static function status($code,$message=''){
159 157
         static::header('Status',$message?:$code,$code);
160 158
     }
161 159
 
160
+    /**
161
+     * @param string $name
162
+     */
162 163
     public static function header($name,$value,$code=null){
163 164
         static::$headers[$name] = [$value,$code];
164 165
     }
Please login to merge, or discard this patch.
Braces   +43 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
                      $sent        = false;
33 33
 
34 34
 
35
-    public static function charset($charset){
35
+    public static function charset($charset) {
36 36
         static::$charset = $charset;
37 37
     }
38 38
 
39
-    public static function type($mime){
39
+    public static function type($mime) {
40 40
         static::header('Content-Type',$mime . (static::$charset ? '; charset='.static::$charset : ''));
41 41
     }
42 42
 
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
      * @param  string/bool $filename Pass a falsy value to disable download or pass a filename for exporting content
46 46
      * @return [type]        [description]
47 47
      */
48
-    public static function download($filename){
48
+    public static function download($filename) {
49 49
         static::$force_dl = $filename;
50 50
     }
51 51
 
52 52
     /**
53 53
      * Start capturing output
54 54
      */
55
-    public static function start(){
55
+    public static function start() {
56 56
         static::$buffer = ob_start();
57 57
     }
58 58
 
59 59
     /**
60 60
      * Enable CORS HTTP headers.
61 61
      */
62
-    public static function enableCORS(){
62
+    public static function enableCORS() {
63 63
 
64 64
         // Allow from any origin
65 65
         if ($origin = filter_input(INPUT_SERVER,'HTTP_ORIGIN')) {
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
      * Finish the output buffer capturing.
94 94
      * @return string The captured buffer
95 95
      */
96
-    public static function end(){
97
-        if (static::$buffer){
96
+    public static function end() {
97
+        if (static::$buffer) {
98 98
             static::$payload[] = ob_get_contents();
99 99
             ob_end_clean();
100 100
             static::$buffer = null;
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
      * Check if an response output buffering is active.
107 107
      * @return boolean
108 108
      */
109
-    public static function isBuffering(){
109
+    public static function isBuffering() {
110 110
         return static::$buffer;
111 111
     }
112 112
 
113 113
     /**
114 114
      * Clear the response body
115 115
      */
116
-    public static function clean(){
116
+    public static function clean() {
117 117
         static::$payload = [];
118 118
     }
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      * Append a JSON object to the buffer.
122 122
      * @param  mixed $payload Data to append to the response buffer
123 123
      */
124
-    public static function json($payload){
124
+    public static function json($payload) {
125 125
         static::type(static::TYPE_JSON);
126 126
         static::$payload[] = json_encode($payload, Options::get('core.response.json_flags',JSON_NUMERIC_CHECK));
127 127
     }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * Append a text to the buffer.
131 131
      * @param  mixed $payload Text to append to the response buffer
132 132
      */
133
-    public static function text(){
133
+    public static function text() {
134 134
         static::type(static::TYPE_TEXT);
135 135
         static::$payload[] = implode('',func_get_args());
136 136
     }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      * Append an XML string to the buffer.
140 140
      * @param  mixed $payload Data to append to the response buffer
141 141
      */
142
-    public static function xml(){
142
+    public static function xml() {
143 143
         static::type(static::TYPE_XML);
144 144
         static::$payload[] = implode('',func_get_args());
145 145
     }
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      * Append a SVG string to the buffer.
149 149
      * @param  mixed $payload Data to append to the response buffer
150 150
      */
151
-    public static function svg(){
151
+    public static function svg() {
152 152
         static::type(static::TYPE_SVG);
153 153
         static::$payload[] = implode('',func_get_args());
154 154
     }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * Append an HTML string to the buffer.
158 158
      * @param  mixed $payload Data to append to the response buffer
159 159
      */
160
-    public static function html(){
160
+    public static function html() {
161 161
         static::type(static::TYPE_HTML);
162 162
         static::$payload[] = implode('',func_get_args());
163 163
     }
@@ -166,30 +166,34 @@  discard block
 block discarded – undo
166 166
      * Append a raw string to the buffer.
167 167
      * @param  mixed $payload Data to append to the response buffer
168 168
      */
169
-    public static function add(){
169
+    public static function add() {
170 170
         static::$payload[] = implode('',func_get_args());
171 171
     }
172 172
 
173
-    public static function status($code,$message=''){
173
+    public static function status($code,$message='') {
174 174
         static::header('Status',$message?:$code,$code);
175 175
     }
176 176
 
177
-    public static function header($name,$value,$code=null){
177
+    public static function header($name,$value,$code=null) {
178 178
         static::$headers[$name] = [$value,$code];
179 179
     }
180 180
 
181
-    public static function error($code=500,$message='Application Error'){
181
+    public static function error($code=500,$message='Application Error') {
182 182
         Event::trigger('core.response.error',$code,$message);
183 183
         static::status($code,$message);
184 184
     }
185 185
 
186
-    public static function body($setBody=null){
187
-      if ($setBody) static::$payload = [$setBody];
186
+    public static function body($setBody=null) {
187
+      if ($setBody) {
188
+        static::$payload = [$setBody];
189
+      }
188 190
       return Filter::with('core.response.body',is_array(static::$payload)?implode('',static::$payload):static::$payload);
189 191
     }
190 192
 
191
-    public static function headers($setHeaders=null){
192
-       if ($setHeaders) static::$headers = $setHeaders;
193
+    public static function headers($setHeaders=null) {
194
+       if ($setHeaders) {
195
+         static::$headers = $setHeaders;
196
+       }
193 197
        return static::$headers;
194 198
     }
195 199
 
@@ -200,7 +204,7 @@  discard block
 block discarded – undo
200 204
      *
201 205
      * @return array Headers and body of the response
202 206
      */
203
-    public static function save(){
207
+    public static function save() {
204 208
         return [
205 209
           'head' => static::$headers,
206 210
           'body' => static::body(),
@@ -214,27 +218,33 @@  discard block
 block discarded – undo
214 218
      *
215 219
      * @param  array $data head/body saved state
216 220
      */
217
-    public static function load($data){
221
+    public static function load($data) {
218 222
       $data = (object)$data;
219
-      if (isset($data->head)) static::headers($data->head);
220
-      if (isset($data->body)) static::body($data->body);
223
+      if (isset($data->head)) {
224
+        static::headers($data->head);
225
+      }
226
+      if (isset($data->body)) {
227
+        static::body($data->body);
228
+      }
221 229
     }
222 230
 
223
-    public static function send($force = false){
231
+    public static function send($force = false) {
224 232
       if (!static::$sent || $force) {
225 233
         static::$sent = true;
226 234
         Event::trigger('core.response.send');
227
-        if (false === headers_sent()) foreach (static::$headers as $name => $value_code) {
235
+        if (false === headers_sent()) {
236
+          foreach (static::$headers as $name => $value_code) {
228 237
 
229 238
             if (is_array($value_code)) {
230 239
                 list($value, $code) = (count($value_code) > 1) ? $value_code : [current($value_code), 200];
240
+        }
231 241
             } else {
232 242
                 $value = $value_code;
233 243
                 $code  = null;
234 244
             }
235 245
 
236
-            if ($value == 'Status'){
237
-              if (function_exists('http_response_code')){
246
+            if ($value == 'Status') {
247
+              if (function_exists('http_response_code')) {
238 248
                 http_response_code($code);
239 249
               } else {
240 250
                 header("Status: $code", true, $code);
@@ -246,7 +256,9 @@  discard block
 block discarded – undo
246 256
                 : header("$name: $value", true);
247 257
             }
248 258
         }
249
-        if (static::$force_dl) header('Content-Disposition: attachment; filename="'.static::$force_dl.'"');
259
+        if (static::$force_dl) {
260
+          header('Content-Disposition: attachment; filename="'.static::$force_dl.'"');
261
+        }
250 262
         echo static::body();
251 263
       }
252 264
     }
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
           TYPE_BIN                = 'application/octet-stream';
24 24
 
25 25
     protected static $payload     = [],
26
-                     $status      = 200,
27
-                     $charset     = "utf-8",
28
-                     $headers     = ['Content-Type' => ['text/html; charset=utf-8']],
29
-                     $buffer      = null,
30
-                     $force_dl    = false,
31
-                     $link        = null,
32
-                     $sent        = false;
26
+                      $status      = 200,
27
+                      $charset     = "utf-8",
28
+                      $headers     = ['Content-Type' => ['text/html; charset=utf-8']],
29
+                      $buffer      = null,
30
+                      $force_dl    = false,
31
+                      $link        = null,
32
+                      $sent        = false;
33 33
 
34 34
 
35 35
     public static function charset($charset){
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
       if ($setBody) static::$payload = [$setBody];
188 188
       return Filter::with('core.response.body',
189 189
                 is_array(static::$payload) ? implode('',static::$payload) : static::$payload
190
-             );
190
+              );
191 191
     }
192 192
 
193 193
     public static function headers($setHeaders=null){
194
-       if ($setHeaders) static::$headers = $setHeaders;
195
-       return static::$headers;
194
+        if ($setHeaders) static::$headers = $setHeaders;
195
+        return static::$headers;
196 196
     }
197 197
 
198 198
     /**
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
                      $sent        = false;
33 33
 
34 34
 
35
-    public static function charset($charset){
35
+    public static function charset($charset) {
36 36
         static::$charset = $charset;
37 37
     }
38 38
 
39
-    public static function type($mime){
40
-        static::header('Content-Type',$mime . (static::$charset ? '; charset='.static::$charset : ''));
39
+    public static function type($mime) {
40
+        static::header('Content-Type', $mime.(static::$charset ? '; charset='.static::$charset : ''));
41 41
     }
42 42
 
43 43
     /**
@@ -45,39 +45,39 @@  discard block
 block discarded – undo
45 45
      * @param  string/bool $filename Pass a falsy value to disable download or pass a filename for exporting content
46 46
      * @return [type]        [description]
47 47
      */
48
-    public static function download($filename){
48
+    public static function download($filename) {
49 49
         static::$force_dl = $filename;
50 50
     }
51 51
 
52 52
     /**
53 53
      * Start capturing output
54 54
      */
55
-    public static function start(){
55
+    public static function start() {
56 56
         static::$buffer = ob_start();
57 57
     }
58 58
 
59 59
     /**
60 60
      * Enable CORS HTTP headers.
61 61
      */
62
-    public static function enableCORS(){
62
+    public static function enableCORS() {
63 63
 
64 64
         // Allow from any origin
65
-        if ($origin = filter_input(INPUT_SERVER,'HTTP_ORIGIN')) {
65
+        if ($origin = filter_input(INPUT_SERVER, 'HTTP_ORIGIN')) {
66 66
           static::header('Access-Control-Allow-Origin', $origin);
67 67
           static::header('Access-Control-Allow-Credentials', 'true');
68 68
           static::header('Access-Control-Max-Age', 86400);
69 69
         }
70 70
 
71 71
         // Access-Control headers are received during OPTIONS requests
72
-        if (filter_input(INPUT_SERVER,'REQUEST_METHOD') == 'OPTIONS') {
72
+        if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') == 'OPTIONS') {
73 73
             static::clean();
74 74
 
75
-            if (filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_METHOD')) {
75
+            if (filter_input(INPUT_SERVER, 'HTTP_ACCESS_CONTROL_REQUEST_METHOD')) {
76 76
               static::header('Access-Control-Allow-Methods',
77 77
                 'GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, PATCH, TRACE');
78 78
             }
79
-            if ($req_h = filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_HEADERS')) {
80
-              static::header('Access-Control-Allow-Headers',$req_h);
79
+            if ($req_h = filter_input(INPUT_SERVER, 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS')) {
80
+              static::header('Access-Control-Allow-Headers', $req_h);
81 81
             }
82 82
 
83 83
             static::send();
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
      * Finish the output buffer capturing.
94 94
      * @return string The captured buffer
95 95
      */
96
-    public static function end(){
97
-        if (static::$buffer){
96
+    public static function end() {
97
+        if (static::$buffer) {
98 98
             static::$payload[] = ob_get_contents();
99 99
             ob_end_clean();
100 100
             static::$buffer = null;
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
      * Check if an response output buffering is active.
107 107
      * @return boolean
108 108
      */
109
-    public static function isBuffering(){
109
+    public static function isBuffering() {
110 110
         return static::$buffer;
111 111
     }
112 112
 
113 113
     /**
114 114
      * Clear the response body
115 115
      */
116
-    public static function clean(){
116
+    public static function clean() {
117 117
         static::$payload = [];
118 118
     }
119 119
 
@@ -121,76 +121,76 @@  discard block
 block discarded – undo
121 121
      * Append a JSON object to the buffer.
122 122
      * @param  mixed $payload Data to append to the response buffer
123 123
      */
124
-    public static function json($payload){
124
+    public static function json($payload) {
125 125
         static::type(static::TYPE_JSON);
126
-        static::$payload[] = json_encode($payload, Options::get('core.response.json_flags',JSON_NUMERIC_CHECK));
126
+        static::$payload[] = json_encode($payload, Options::get('core.response.json_flags', JSON_NUMERIC_CHECK));
127 127
     }
128 128
 
129 129
     /**
130 130
      * Append a text to the buffer.
131 131
      * @param  mixed $payload Text to append to the response buffer
132 132
      */
133
-    public static function text(){
133
+    public static function text() {
134 134
         static::type(static::TYPE_TEXT);
135
-        static::$payload[] = implode('',func_get_args());
135
+        static::$payload[] = implode('', func_get_args());
136 136
     }
137 137
 
138 138
     /**
139 139
      * Append an XML string to the buffer.
140 140
      * @param  mixed $payload Data to append to the response buffer
141 141
      */
142
-    public static function xml(){
142
+    public static function xml() {
143 143
         static::type(static::TYPE_XML);
144
-        static::$payload[] = implode('',func_get_args());
144
+        static::$payload[] = implode('', func_get_args());
145 145
     }
146 146
 
147 147
     /**
148 148
      * Append a SVG string to the buffer.
149 149
      * @param  mixed $payload Data to append to the response buffer
150 150
      */
151
-    public static function svg(){
151
+    public static function svg() {
152 152
         static::type(static::TYPE_SVG);
153
-        static::$payload[] = implode('',func_get_args());
153
+        static::$payload[] = implode('', func_get_args());
154 154
     }
155 155
 
156 156
     /**
157 157
      * Append an HTML string to the buffer.
158 158
      * @param  mixed $payload Data to append to the response buffer
159 159
      */
160
-    public static function html(){
160
+    public static function html() {
161 161
         static::type(static::TYPE_HTML);
162
-        static::$payload[] = implode('',func_get_args());
162
+        static::$payload[] = implode('', func_get_args());
163 163
     }
164 164
 
165 165
     /**
166 166
      * Append a raw string to the buffer.
167 167
      * @param  mixed $payload Data to append to the response buffer
168 168
      */
169
-    public static function add(){
170
-        static::$payload[] = implode('',func_get_args());
169
+    public static function add() {
170
+        static::$payload[] = implode('', func_get_args());
171 171
     }
172 172
 
173
-    public static function status($code,$message=''){
174
-        static::header('Status',$message?:$code,$code);
173
+    public static function status($code, $message = '') {
174
+        static::header('Status', $message ?: $code, $code);
175 175
     }
176 176
 
177
-    public static function header($name,$value,$code=null){
178
-        static::$headers[$name] = [$value,$code];
177
+    public static function header($name, $value, $code = null) {
178
+        static::$headers[$name] = [$value, $code];
179 179
     }
180 180
 
181
-    public static function error($code=500,$message='Application Error'){
182
-        Event::trigger('core.response.error',$code,$message);
183
-        static::status($code,$message);
181
+    public static function error($code = 500, $message = 'Application Error') {
182
+        Event::trigger('core.response.error', $code, $message);
183
+        static::status($code, $message);
184 184
     }
185 185
 
186
-    public static function body($setBody=null){
186
+    public static function body($setBody = null) {
187 187
       if ($setBody) static::$payload = [$setBody];
188 188
       return Filter::with('core.response.body',
189
-                is_array(static::$payload) ? implode('',static::$payload) : static::$payload
189
+                is_array(static::$payload) ? implode('', static::$payload) : static::$payload
190 190
              );
191 191
     }
192 192
 
193
-    public static function headers($setHeaders=null){
193
+    public static function headers($setHeaders = null) {
194 194
        if ($setHeaders) static::$headers = $setHeaders;
195 195
        return static::$headers;
196 196
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      *
203 203
      * @return array Headers and body of the response
204 204
      */
205
-    public static function save(){
205
+    public static function save() {
206 206
         return [
207 207
           'head' => static::$headers,
208 208
           'body' => static::body(),
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
      *
217 217
      * @param  array $data head/body saved state
218 218
      */
219
-    public static function load($data){
220
-      $data = (object)$data;
219
+    public static function load($data) {
220
+      $data = (object) $data;
221 221
       if (isset($data->head)) static::headers($data->head);
222 222
       if (isset($data->body)) static::body($data->body);
223 223
     }
224 224
 
225
-    public static function send($force = false){
225
+    public static function send($force = false) {
226 226
       if (!static::$sent || $force) {
227 227
         static::$sent = true;
228 228
         Event::trigger('core.response.send');
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
                 $code  = null;
236 236
             }
237 237
 
238
-            if ($value == 'Status'){
239
-              if (function_exists('http_response_code')){
238
+            if ($value == 'Status') {
239
+              if (function_exists('http_response_code')) {
240 240
                 http_response_code($code);
241 241
               } else {
242 242
                 header("Status: $code", true, $code);
Please login to merge, or discard this patch.
classes/Session.php 4 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @access public
34 34
 	 * @static
35
-	 * @param string $key The session name
36 35
 	 * @return string The session value
37 36
 	 */
38 37
 	static public function name($name=null){
@@ -62,7 +61,7 @@  discard block
 block discarded – undo
62 61
 	 *
63 62
 	 * @access public
64 63
 	 * @static
65
-	 * @param mixed $key The variable name
64
+	 * @param string $key The variable name
66 65
 	 * @param mixed $value The variable value
67 66
 	 * @return void
68 67
 	 */
@@ -80,7 +79,7 @@  discard block
 block discarded – undo
80 79
 	 *
81 80
 	 * @access public
82 81
 	 * @static
83
-	 * @param mixed $key The variable name
82
+	 * @param string $key The variable name
84 83
 	 * @return void
85 84
 	 */
86 85
 	static public function delete($key){
@@ -107,7 +106,7 @@  discard block
 block discarded – undo
107 106
 	 *
108 107
 	 * @access public
109 108
 	 * @static
110
-	 * @return void
109
+	 * @return boolean
111 110
 	 */
112 111
 	static public function active(){
113 112
 		return session_status() == PHP_SESSION_ACTIVE;
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -13,126 +13,126 @@  discard block
 block discarded – undo
13 13
 class Session {
14 14
     use Module;
15 15
 
16
-	/**
17
-	 * Start session handler
18
-	 *
19
-	 * @access public
20
-	 * @static
21
-	 * @return void
22
-	 */
23
-	static public function start($name=null){
24
-		if (isset($_SESSION)) return;
25
-		static::name($name);
26
-		session_cache_limiter('must-revalidate');
27
-		@session_start();
28
-	}
29
-
30
-	/**
31
-	 * Get/Set Session name
32
-	 *
33
-	 * @access public
34
-	 * @static
35
-	 * @param string $key The session name
36
-	 * @return string The session value
37
-	 */
38
-	static public function name($name=null){
39
-		return $name ? session_name($name) : session_name();
40
-	}
41
-
42
-	/**
43
-	 * Get a session variable reference
44
-	 *
45
-	 * @access public
46
-	 * @static
47
-	 * @param mixed $key The variable name
48
-	 * @return mixed The variable value
49
-	 */
50
-	static public function get($key,$default=null){
16
+  /**
17
+   * Start session handler
18
+   *
19
+   * @access public
20
+   * @static
21
+   * @return void
22
+   */
23
+  static public function start($name=null){
24
+    if (isset($_SESSION)) return;
25
+    static::name($name);
26
+    session_cache_limiter('must-revalidate');
27
+    @session_start();
28
+  }
29
+
30
+  /**
31
+   * Get/Set Session name
32
+   *
33
+   * @access public
34
+   * @static
35
+   * @param string $key The session name
36
+   * @return string The session value
37
+   */
38
+  static public function name($name=null){
39
+    return $name ? session_name($name) : session_name();
40
+  }
41
+
42
+  /**
43
+   * Get a session variable reference
44
+   *
45
+   * @access public
46
+   * @static
47
+   * @param mixed $key The variable name
48
+   * @return mixed The variable value
49
+   */
50
+  static public function get($key,$default=null){
51 51
                 if (($active = static::active()) && isset($_SESSION[$key])) {
52
-			return $_SESSION[$key];
52
+      return $_SESSION[$key];
53 53
                 } else if ($active) {
54
-                	return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default);
54
+                  return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default);
55 55
                 } else {
56
-                 	return (is_callable($default)?call_user_func($default):$default);
56
+                    return (is_callable($default)?call_user_func($default):$default);
57 57
                 }
58
-	}
59
-
60
-	/**
61
-	 * Set a session variable
62
-	 *
63
-	 * @access public
64
-	 * @static
65
-	 * @param mixed $key The variable name
66
-	 * @param mixed $value The variable value
67
-	 * @return void
68
-	 */
69
-	static public function set($key,$value=null){
70
-		static::start();
71
-		if($value==null && is_array($key)){
72
-			foreach($key as $k=>$v) $_SESSION[$k]=$v;
73
-		} else {
74
-			$_SESSION[$key] = $value;
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Delete a session variable
80
-	 *
81
-	 * @access public
82
-	 * @static
83
-	 * @param mixed $key The variable name
84
-	 * @return void
85
-	 */
86
-	static public function delete($key){
87
-		static::start();
88
-		unset($_SESSION[$key]);
89
-	}
90
-
91
-
92
-	/**
93
-	 * Delete all session variables
94
-	 *
95
-	 * @access public
96
-	 * @static
97
-	 * @return void
98
-	 */
99
-	static public function clear(){
100
-		static::start();
101
-		session_unset();
102
-		session_destroy();
103
-	}
104
-
105
-	/**
106
-	 * Check if session is active
107
-	 *
108
-	 * @access public
109
-	 * @static
110
-	 * @return void
111
-	 */
112
-	static public function active(){
113
-		return session_status() == PHP_SESSION_ACTIVE;
114
-	}
115
-
116
-	/**
117
-	 * Check if a session variable exists
118
-	 *
119
-	 * @access public
120
-	 * @static
121
-	 * @param mixed $key The variable name
122
-	 * @return bool
123
-	 */
124
-	static public function exists($key){
125
-		static::start();
126
-		return isset($_SESSION[$key]);
127
-	}
128
-
129
-	/**
130
-	 * Return a read-only accessor to session variables for in-view use.
131
-	 * @return SessionReadOnly
132
-	 */
133
-	static public function readOnly(){
134
-		return new SessionReadOnly;
135
-	}
58
+  }
59
+
60
+  /**
61
+   * Set a session variable
62
+   *
63
+   * @access public
64
+   * @static
65
+   * @param mixed $key The variable name
66
+   * @param mixed $value The variable value
67
+   * @return void
68
+   */
69
+  static public function set($key,$value=null){
70
+    static::start();
71
+    if($value==null && is_array($key)){
72
+      foreach($key as $k=>$v) $_SESSION[$k]=$v;
73
+    } else {
74
+      $_SESSION[$key] = $value;
75
+    }
76
+  }
77
+
78
+  /**
79
+   * Delete a session variable
80
+   *
81
+   * @access public
82
+   * @static
83
+   * @param mixed $key The variable name
84
+   * @return void
85
+   */
86
+  static public function delete($key){
87
+    static::start();
88
+    unset($_SESSION[$key]);
89
+  }
90
+
91
+
92
+  /**
93
+   * Delete all session variables
94
+   *
95
+   * @access public
96
+   * @static
97
+   * @return void
98
+   */
99
+  static public function clear(){
100
+    static::start();
101
+    session_unset();
102
+    session_destroy();
103
+  }
104
+
105
+  /**
106
+   * Check if session is active
107
+   *
108
+   * @access public
109
+   * @static
110
+   * @return void
111
+   */
112
+  static public function active(){
113
+    return session_status() == PHP_SESSION_ACTIVE;
114
+  }
115
+
116
+  /**
117
+   * Check if a session variable exists
118
+   *
119
+   * @access public
120
+   * @static
121
+   * @param mixed $key The variable name
122
+   * @return bool
123
+   */
124
+  static public function exists($key){
125
+    static::start();
126
+    return isset($_SESSION[$key]);
127
+  }
128
+
129
+  /**
130
+   * Return a read-only accessor to session variables for in-view use.
131
+   * @return SessionReadOnly
132
+   */
133
+  static public function readOnly(){
134
+    return new SessionReadOnly;
135
+  }
136 136
 
137 137
 }  /* End of class */
138 138
 
@@ -144,36 +144,36 @@  discard block
 block discarded – undo
144 144
 
145 145
 class SessionReadOnly {
146 146
 
147
-	/**
148
-	 * Get a session variable reference
149
-	 *
150
-	 * @access public
151
-	 * @param mixed $key The variable name
152
-	 * @return mixed The variable value
153
-	 */
154
-	public function get($key){
155
-		return Session::get($key);
156
-	}
157
-	public function __get($key){
158
-		return Session::get($key);
159
-	}
160
-
161
-	public function name(){
162
-		return Session::name();
163
-	}
164
-
165
-	/**
166
-	 * Check if a session variable exists
167
-	 *
168
-	 * @access public
169
-	 * @param mixed $key The variable name
170
-	 * @return bool
171
-	 */
172
-	public function exists($key){
173
-		return Session::exists($key);
174
-	}
175
-	public function __isset($key){
176
-		return Session::exists($key);
177
-	}
147
+  /**
148
+   * Get a session variable reference
149
+   *
150
+   * @access public
151
+   * @param mixed $key The variable name
152
+   * @return mixed The variable value
153
+   */
154
+  public function get($key){
155
+    return Session::get($key);
156
+  }
157
+  public function __get($key){
158
+    return Session::get($key);
159
+  }
160
+
161
+  public function name(){
162
+    return Session::name();
163
+  }
164
+
165
+  /**
166
+   * Check if a session variable exists
167
+   *
168
+   * @access public
169
+   * @param mixed $key The variable name
170
+   * @return bool
171
+   */
172
+  public function exists($key){
173
+    return Session::exists($key);
174
+  }
175
+  public function __isset($key){
176
+    return Session::exists($key);
177
+  }
178 178
 
179 179
 }  /* End of class */
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @static
21 21
 	 * @return void
22 22
 	 */
23
-	static public function start($name=null){
23
+	static public function start($name = null) {
24 24
 		if (isset($_SESSION)) return;
25 25
 		static::name($name);
26 26
 		session_cache_limiter('must-revalidate');
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param string $key The session name
36 36
 	 * @return string The session value
37 37
 	 */
38
-	static public function name($name=null){
38
+	static public function name($name = null) {
39 39
 		return $name ? session_name($name) : session_name();
40 40
 	}
41 41
 
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 	 * @param mixed $key The variable name
48 48
 	 * @return mixed The variable value
49 49
 	 */
50
-	static public function get($key,$default=null){
50
+	static public function get($key, $default = null) {
51 51
                 if (($active = static::active()) && isset($_SESSION[$key])) {
52 52
 			return $_SESSION[$key];
53 53
                 } else if ($active) {
54
-                	return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default);
54
+                	return $_SESSION[$key] = (is_callable($default) ? call_user_func($default) : $default);
55 55
                 } else {
56
-                 	return (is_callable($default)?call_user_func($default):$default);
56
+                 	return (is_callable($default) ? call_user_func($default) : $default);
57 57
                 }
58 58
 	}
59 59
 
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param mixed $value The variable value
67 67
 	 * @return void
68 68
 	 */
69
-	static public function set($key,$value=null){
69
+	static public function set($key, $value = null) {
70 70
 		static::start();
71
-		if($value==null && is_array($key)){
72
-			foreach($key as $k=>$v) $_SESSION[$k]=$v;
71
+		if ($value == null && is_array($key)) {
72
+			foreach ($key as $k=>$v) $_SESSION[$k] = $v;
73 73
 		} else {
74 74
 			$_SESSION[$key] = $value;
75 75
 		}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param mixed $key The variable name
84 84
 	 * @return void
85 85
 	 */
86
-	static public function delete($key){
86
+	static public function delete($key) {
87 87
 		static::start();
88 88
 		unset($_SESSION[$key]);
89 89
 	}
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @static
97 97
 	 * @return void
98 98
 	 */
99
-	static public function clear(){
99
+	static public function clear() {
100 100
 		static::start();
101 101
 		session_unset();
102 102
 		session_destroy();
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @static
110 110
 	 * @return void
111 111
 	 */
112
-	static public function active(){
112
+	static public function active() {
113 113
 		return session_status() == PHP_SESSION_ACTIVE;
114 114
 	}
115 115
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param mixed $key The variable name
122 122
 	 * @return bool
123 123
 	 */
124
-	static public function exists($key){
124
+	static public function exists($key) {
125 125
 		static::start();
126 126
 		return isset($_SESSION[$key]);
127 127
 	}
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * Return a read-only accessor to session variables for in-view use.
131 131
 	 * @return SessionReadOnly
132 132
 	 */
133
-	static public function readOnly(){
133
+	static public function readOnly() {
134 134
 		return new SessionReadOnly;
135 135
 	}
136 136
 
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 	 * @param mixed $key The variable name
152 152
 	 * @return mixed The variable value
153 153
 	 */
154
-	public function get($key){
154
+	public function get($key) {
155 155
 		return Session::get($key);
156 156
 	}
157
-	public function __get($key){
157
+	public function __get($key) {
158 158
 		return Session::get($key);
159 159
 	}
160 160
 
161
-	public function name(){
161
+	public function name() {
162 162
 		return Session::name();
163 163
 	}
164 164
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 	 * @param mixed $key The variable name
170 170
 	 * @return bool
171 171
 	 */
172
-	public function exists($key){
172
+	public function exists($key) {
173 173
 		return Session::exists($key);
174 174
 	}
175
-	public function __isset($key){
175
+	public function __isset($key) {
176 176
 		return Session::exists($key);
177 177
 	}
178 178
 
Please login to merge, or discard this patch.
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,8 +20,10 @@  discard block
 block discarded – undo
20 20
 	 * @static
21 21
 	 * @return void
22 22
 	 */
23
-	static public function start($name=null){
24
-		if (isset($_SESSION)) return;
23
+	static public function start($name=null) {
24
+		if (isset($_SESSION)) {
25
+		  return;
26
+		}
25 27
 		static::name($name);
26 28
 		session_cache_limiter('must-revalidate');
27 29
 		@session_start();
@@ -35,7 +37,7 @@  discard block
 block discarded – undo
35 37
 	 * @param string $key The session name
36 38
 	 * @return string The session value
37 39
 	 */
38
-	static public function name($name=null){
40
+	static public function name($name=null) {
39 41
 		return $name ? session_name($name) : session_name();
40 42
 	}
41 43
 
@@ -47,7 +49,7 @@  discard block
 block discarded – undo
47 49
 	 * @param mixed $key The variable name
48 50
 	 * @return mixed The variable value
49 51
 	 */
50
-	static public function get($key,$default=null){
52
+	static public function get($key,$default=null) {
51 53
                 if (($active = static::active()) && isset($_SESSION[$key])) {
52 54
 			return $_SESSION[$key];
53 55
                 } else if ($active) {
@@ -66,9 +68,9 @@  discard block
 block discarded – undo
66 68
 	 * @param mixed $value The variable value
67 69
 	 * @return void
68 70
 	 */
69
-	static public function set($key,$value=null){
71
+	static public function set($key,$value=null) {
70 72
 		static::start();
71
-		if($value==null && is_array($key)){
73
+		if($value==null && is_array($key)) {
72 74
 			foreach($key as $k=>$v) $_SESSION[$k]=$v;
73 75
 		} else {
74 76
 			$_SESSION[$key] = $value;
@@ -83,7 +85,7 @@  discard block
 block discarded – undo
83 85
 	 * @param mixed $key The variable name
84 86
 	 * @return void
85 87
 	 */
86
-	static public function delete($key){
88
+	static public function delete($key) {
87 89
 		static::start();
88 90
 		unset($_SESSION[$key]);
89 91
 	}
@@ -96,7 +98,7 @@  discard block
 block discarded – undo
96 98
 	 * @static
97 99
 	 * @return void
98 100
 	 */
99
-	static public function clear(){
101
+	static public function clear() {
100 102
 		static::start();
101 103
 		session_unset();
102 104
 		session_destroy();
@@ -109,7 +111,7 @@  discard block
 block discarded – undo
109 111
 	 * @static
110 112
 	 * @return void
111 113
 	 */
112
-	static public function active(){
114
+	static public function active() {
113 115
 		return session_status() == PHP_SESSION_ACTIVE;
114 116
 	}
115 117
 
@@ -121,7 +123,7 @@  discard block
 block discarded – undo
121 123
 	 * @param mixed $key The variable name
122 124
 	 * @return bool
123 125
 	 */
124
-	static public function exists($key){
126
+	static public function exists($key) {
125 127
 		static::start();
126 128
 		return isset($_SESSION[$key]);
127 129
 	}
@@ -130,7 +132,7 @@  discard block
 block discarded – undo
130 132
 	 * Return a read-only accessor to session variables for in-view use.
131 133
 	 * @return SessionReadOnly
132 134
 	 */
133
-	static public function readOnly(){
135
+	static public function readOnly() {
134 136
 		return new SessionReadOnly;
135 137
 	}
136 138
 
@@ -151,14 +153,14 @@  discard block
 block discarded – undo
151 153
 	 * @param mixed $key The variable name
152 154
 	 * @return mixed The variable value
153 155
 	 */
154
-	public function get($key){
156
+	public function get($key) {
155 157
 		return Session::get($key);
156 158
 	}
157
-	public function __get($key){
159
+	public function __get($key) {
158 160
 		return Session::get($key);
159 161
 	}
160 162
 
161
-	public function name(){
163
+	public function name() {
162 164
 		return Session::name();
163 165
 	}
164 166
 
@@ -169,10 +171,10 @@  discard block
 block discarded – undo
169 171
 	 * @param mixed $key The variable name
170 172
 	 * @return bool
171 173
 	 */
172
-	public function exists($key){
174
+	public function exists($key) {
173 175
 		return Session::exists($key);
174 176
 	}
175
-	public function __isset($key){
177
+	public function __isset($key) {
176 178
 		return Session::exists($key);
177 179
 	}
178 180
 
Please login to merge, or discard this patch.
classes/Email/Envelope.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -96,6 +96,9 @@
 block discarded – undo
96 96
     return $this->replyTo;
97 97
   }
98 98
 
99
+  /**
100
+   * @return string
101
+   */
99 102
   public function subject($value=null){
100 103
     if ($value!==null && $value) {
101 104
       $this->compiled_head = null;
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
15 15
 class Envelope {
16 16
 
17 17
   protected  $uid,
18
-             $to,
19
-             $from,
20
-             $cc,
21
-             $bcc,
22
-             $replyTo,
23
-             $subject,
24
-             $message,
25
-             $contentType = 'text/html; charset="utf-8"',
26
-             $attachments,
27
-             $compiled_head,
28
-             $compiled_body;
18
+              $to,
19
+              $from,
20
+              $cc,
21
+              $bcc,
22
+              $replyTo,
23
+              $subject,
24
+              $message,
25
+              $contentType = 'text/html; charset="utf-8"',
26
+              $attachments,
27
+              $compiled_head,
28
+              $compiled_body;
29 29
 
30 30
   public function __construct($email=null){
31 31
     if ($email) {
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,126 +27,126 @@  discard block
 block discarded – undo
27 27
              $compiled_head,
28 28
              $compiled_body;
29 29
 
30
-  public function __construct($email=null){
30
+  public function __construct($email = null) {
31 31
     if ($email) {
32
-      $email = (object)$email;
33
-      if(isset($email->to))           $this->to($email->to);
34
-      if(isset($email->from))         $this->from($email->from);
35
-      if(isset($email->cc))           $this->cc($email->cc);
36
-      if(isset($email->bcc))          $this->bcc($email->bcc);
37
-      if(isset($email->replyTo))      $this->replyTo($email->replyTo);
38
-      if(isset($email->subject))      $this->subject($email->subject);
39
-      if(isset($email->message))      $this->message($email->message);
40
-      if(isset($email->attachments))  $this->attach($email->attachments);
32
+      $email = (object) $email;
33
+      if (isset($email->to))           $this->to($email->to);
34
+      if (isset($email->from))         $this->from($email->from);
35
+      if (isset($email->cc))           $this->cc($email->cc);
36
+      if (isset($email->bcc))          $this->bcc($email->bcc);
37
+      if (isset($email->replyTo))      $this->replyTo($email->replyTo);
38
+      if (isset($email->subject))      $this->subject($email->subject);
39
+      if (isset($email->message))      $this->message($email->message);
40
+      if (isset($email->attachments))  $this->attach($email->attachments);
41 41
     }
42
-    $this->uid  = '_CORE_'.md5(uniqid(time()));
42
+    $this->uid = '_CORE_'.md5(uniqid(time()));
43 43
 
44 44
   }
45 45
 
46
-  protected function add_emails(&$pool, $emails, $append=true){
46
+  protected function add_emails(&$pool, $emails, $append = true) {
47 47
     $this->compiled_head = null;
48
-    foreach ((array)$emails as $values) {
49
-      foreach(preg_split('/\s*,\s*/',$values) as $value) {
50
-        if(strpos($value,'<')!==false){
51
-          $value   = str_replace('>','',$value);
52
-          $parts   = explode('<',$value,2);
48
+    foreach ((array) $emails as $values) {
49
+      foreach (preg_split('/\s*,\s*/', $values) as $value) {
50
+        if (strpos($value, '<') !== false) {
51
+          $value   = str_replace('>', '', $value);
52
+          $parts   = explode('<', $value, 2);
53 53
           $name    = trim(current($parts));
54 54
           $email   = trim(end($parts));
55 55
           $address = "$name <{$email}>";
56 56
         } else {
57 57
           $address = $value;
58 58
         }
59
-        if ($append) $pool[] = $address; else $pool = $address;
59
+        if ($append) $pool[] = $address;else $pool = $address;
60 60
       }
61 61
     }
62 62
   }
63 63
 
64
-  public function from($value=null){
65
-    if ($value!==null && $value) {
64
+  public function from($value = null) {
65
+    if ($value !== null && $value) {
66 66
       $this->add_emails($this->from, $value, false);
67
-    } else if ($value===false) $this->from = '';
67
+    } else if ($value === false) $this->from = '';
68 68
     return $this->from;
69 69
   }
70 70
 
71
-  public function to($value=null){
72
-    if ($value!==null && $value) {
71
+  public function to($value = null) {
72
+    if ($value !== null && $value) {
73 73
       $this->add_emails($this->to, $value);
74
-    } else if ($value===false) $this->to = [];
74
+    } else if ($value === false) $this->to = [];
75 75
     return $this->to;
76 76
   }
77 77
 
78
-  public function cc($value=null){
79
-    if ($value!==null && $value) {
78
+  public function cc($value = null) {
79
+    if ($value !== null && $value) {
80 80
       $this->add_emails($this->cc, $value);
81
-    } else if ($value===false) $this->cc = [];
81
+    } else if ($value === false) $this->cc = [];
82 82
     return $this->cc;
83 83
   }
84 84
 
85
-  public function bcc($value=null){
86
-    if ($value!==null && $value) {
85
+  public function bcc($value = null) {
86
+    if ($value !== null && $value) {
87 87
       $this->add_emails($this->bcc, $value);
88
-    } else if ($value===false) $this->bcc = [];
88
+    } else if ($value === false) $this->bcc = [];
89 89
     return $this->bcc;
90 90
   }
91 91
 
92
-  public function replyTo($value=null){
93
-    if ($value!==null && $value) {
92
+  public function replyTo($value = null) {
93
+    if ($value !== null && $value) {
94 94
       $this->add_emails($this->replyTo, $value, false);
95
-    } else if ($value===false) $this->replyTo = '';
95
+    } else if ($value === false) $this->replyTo = '';
96 96
     return $this->replyTo;
97 97
   }
98 98
 
99
-  public function subject($value=null){
100
-    if ($value!==null && $value) {
99
+  public function subject($value = null) {
100
+    if ($value !== null && $value) {
101 101
       $this->compiled_head = null;
102 102
       $this->subject = $value;
103
-    } else if ($value===false) $this->subject = '';
103
+    } else if ($value === false) $this->subject = '';
104 104
     return $this->subject;
105 105
   }
106 106
 
107
-  public function contentType($value=null){
108
-    if ($value!==null && $value) {
107
+  public function contentType($value = null) {
108
+    if ($value !== null && $value) {
109 109
       $this->compiled_body = null;
110 110
       $this->contentType = $value;
111
-    } else if ($value===false) $this->contentType = '';
111
+    } else if ($value === false) $this->contentType = '';
112 112
     return $this->contentType;
113 113
   }
114 114
 
115
-  public function message($value=null){
116
-    if ($value!==null && $value) {
115
+  public function message($value = null) {
116
+    if ($value !== null && $value) {
117 117
       $this->compiled_body = null;
118 118
       $this->message = $value;
119
-    } else if ($value===false) $this->message = '';
119
+    } else if ($value === false) $this->message = '';
120 120
     return $this->message;
121 121
   }
122 122
 
123
-  public function attach($file){
123
+  public function attach($file) {
124 124
     $this->compiled_body = null;
125 125
     if (isset($file->content) || isset($file['content'])) {
126 126
       $this->attachments[] = $file;
127
-    } else foreach ((array)$file as $curfile) {
127
+    } else foreach ((array) $file as $curfile) {
128 128
       $this->attachments[] = $curfile;
129 129
     }
130 130
   }
131 131
 
132
-  public function head($recompile = false){
133
-    if ($recompile || (null === $this->compiled_head)){
132
+  public function head($recompile = false) {
133
+    if ($recompile || (null === $this->compiled_head)) {
134 134
       $head   = [];
135 135
       $head[] = "Subject: {$this->subject}";
136
-      if($this->from)                        $head[] = "From: {$this->from}";
137
-      if(is_array($this->to)  && !empty($this->to))  $head[] = "To: "  . implode(', ',$this->to);
138
-      if(is_array($this->cc)  && !empty($this->cc))  $head[] = "Cc: "  . implode(', ',$this->cc);
139
-      if(is_array($this->bcc) && !empty($this->bcc)) $head[] = "Bcc: " . implode(', ',$this->bcc);
140
-      if($this->replyTo)                     $head[] = "Reply-To: {$this->replyTo}";
136
+      if ($this->from)                        $head[] = "From: {$this->from}";
137
+      if (is_array($this->to) && !empty($this->to))  $head[] = "To: ".implode(', ', $this->to);
138
+      if (is_array($this->cc) && !empty($this->cc))  $head[] = "Cc: ".implode(', ', $this->cc);
139
+      if (is_array($this->bcc) && !empty($this->bcc)) $head[] = "Bcc: ".implode(', ', $this->bcc);
140
+      if ($this->replyTo)                     $head[] = "Reply-To: {$this->replyTo}";
141 141
       $head[] = 'MIME-Version: 1.0';
142 142
       $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->uid}\"";
143 143
       $this->compiled_head = implode("\r\n", $head);
144 144
     }
145
-    return \Filter::with( 'core.email.source.head', $this->compiled_head);
145
+    return \Filter::with('core.email.source.head', $this->compiled_head);
146 146
   }
147 147
 
148
-  public function body($recompile = false){
149
-    if ($recompile || (null === $this->compiled_body)){
148
+  public function body($recompile = false) {
149
+    if ($recompile || (null === $this->compiled_body)) {
150 150
       $body[] = "--{$this->uid}";
151 151
       $body[] = "Content-Type: {$this->contentType}";
152 152
       $body[] = "Content-Transfer-Encoding: quoted-printable";
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
       $body[] = quoted_printable_encode($this->message);
155 155
       $body[] = '';
156 156
 
157
-      if (!empty($this->attachments)) foreach ((array)$this->attachments as $file) {
157
+      if (!empty($this->attachments)) foreach ((array) $this->attachments as $file) {
158 158
 
159 159
         if (is_string($file)) {
160 160
           $name = basename($file);
161 161
           $data = file_get_contents($file);
162 162
         } else {
163
-          $name = isset($file['name'])    ? $file['name']    : 'untitled';
163
+          $name = isset($file['name']) ? $file['name'] : 'untitled';
164 164
           $data = isset($file['content']) ? $file['content'] : '';
165 165
         }
166 166
 
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 
178 178
       $this->compiled_body = implode("\r\n", $body);
179 179
     }
180
-    return \Filter::with( 'core.email.source.body', $this->compiled_body);
180
+    return \Filter::with('core.email.source.body', $this->compiled_body);
181 181
   }
182 182
 
183
-  public function build(){
184
-    return \Filter::with( 'core.email.source', $this->head() . "\r\n" . $this->body() );
183
+  public function build() {
184
+    return \Filter::with('core.email.source', $this->head()."\r\n".$this->body());
185 185
   }
186 186
 
187 187
 }
Please login to merge, or discard this patch.
Braces   +91 added lines, -41 removed lines patch added patch discarded remove patch
@@ -27,27 +27,43 @@  discard block
 block discarded – undo
27 27
              $compiled_head,
28 28
              $compiled_body;
29 29
 
30
-  public function __construct($email=null){
30
+  public function __construct($email=null) {
31 31
     if ($email) {
32 32
       $email = (object)$email;
33
-      if(isset($email->to))           $this->to($email->to);
34
-      if(isset($email->from))         $this->from($email->from);
35
-      if(isset($email->cc))           $this->cc($email->cc);
36
-      if(isset($email->bcc))          $this->bcc($email->bcc);
37
-      if(isset($email->replyTo))      $this->replyTo($email->replyTo);
38
-      if(isset($email->subject))      $this->subject($email->subject);
39
-      if(isset($email->message))      $this->message($email->message);
40
-      if(isset($email->attachments))  $this->attach($email->attachments);
33
+      if(isset($email->to)) {
34
+        $this->to($email->to);
35
+      }
36
+      if(isset($email->from)) {
37
+        $this->from($email->from);
38
+      }
39
+      if(isset($email->cc)) {
40
+        $this->cc($email->cc);
41
+      }
42
+      if(isset($email->bcc)) {
43
+        $this->bcc($email->bcc);
44
+      }
45
+      if(isset($email->replyTo)) {
46
+        $this->replyTo($email->replyTo);
47
+      }
48
+      if(isset($email->subject)) {
49
+        $this->subject($email->subject);
50
+      }
51
+      if(isset($email->message)) {
52
+        $this->message($email->message);
53
+      }
54
+      if(isset($email->attachments)) {
55
+        $this->attach($email->attachments);
56
+      }
41 57
     }
42 58
     $this->uid  = '_CORE_'.md5(uniqid(time()));
43 59
 
44 60
   }
45 61
 
46
-  protected function add_emails(&$pool, $emails, $append=true){
62
+  protected function add_emails(&$pool, $emails, $append=true) {
47 63
     $this->compiled_head = null;
48 64
     foreach ((array)$emails as $values) {
49 65
       foreach(preg_split('/\s*,\s*/',$values) as $value) {
50
-        if(strpos($value,'<')!==false){
66
+        if(strpos($value,'<')!==false) {
51 67
           $value   = str_replace('>','',$value);
52 68
           $parts   = explode('<',$value,2);
53 69
           $name    = trim(current($parts));
@@ -56,88 +72,120 @@  discard block
 block discarded – undo
56 72
         } else {
57 73
           $address = $value;
58 74
         }
59
-        if ($append) $pool[] = $address; else $pool = $address;
75
+        if ($append) {
76
+          $pool[] = $address;
77
+        } else {
78
+          $pool = $address;
79
+        }
60 80
       }
61 81
     }
62 82
   }
63 83
 
64
-  public function from($value=null){
84
+  public function from($value=null) {
65 85
     if ($value!==null && $value) {
66 86
       $this->add_emails($this->from, $value, false);
67
-    } else if ($value===false) $this->from = '';
87
+    } else if ($value===false) {
88
+      $this->from = '';
89
+    }
68 90
     return $this->from;
69 91
   }
70 92
 
71
-  public function to($value=null){
93
+  public function to($value=null) {
72 94
     if ($value!==null && $value) {
73 95
       $this->add_emails($this->to, $value);
74
-    } else if ($value===false) $this->to = [];
96
+    } else if ($value===false) {
97
+      $this->to = [];
98
+    }
75 99
     return $this->to;
76 100
   }
77 101
 
78
-  public function cc($value=null){
102
+  public function cc($value=null) {
79 103
     if ($value!==null && $value) {
80 104
       $this->add_emails($this->cc, $value);
81
-    } else if ($value===false) $this->cc = [];
105
+    } else if ($value===false) {
106
+      $this->cc = [];
107
+    }
82 108
     return $this->cc;
83 109
   }
84 110
 
85
-  public function bcc($value=null){
111
+  public function bcc($value=null) {
86 112
     if ($value!==null && $value) {
87 113
       $this->add_emails($this->bcc, $value);
88
-    } else if ($value===false) $this->bcc = [];
114
+    } else if ($value===false) {
115
+      $this->bcc = [];
116
+    }
89 117
     return $this->bcc;
90 118
   }
91 119
 
92
-  public function replyTo($value=null){
120
+  public function replyTo($value=null) {
93 121
     if ($value!==null && $value) {
94 122
       $this->add_emails($this->replyTo, $value, false);
95
-    } else if ($value===false) $this->replyTo = '';
123
+    } else if ($value===false) {
124
+      $this->replyTo = '';
125
+    }
96 126
     return $this->replyTo;
97 127
   }
98 128
 
99
-  public function subject($value=null){
129
+  public function subject($value=null) {
100 130
     if ($value!==null && $value) {
101 131
       $this->compiled_head = null;
102 132
       $this->subject = $value;
103
-    } else if ($value===false) $this->subject = '';
133
+    } else if ($value===false) {
134
+      $this->subject = '';
135
+    }
104 136
     return $this->subject;
105 137
   }
106 138
 
107
-  public function contentType($value=null){
139
+  public function contentType($value=null) {
108 140
     if ($value!==null && $value) {
109 141
       $this->compiled_body = null;
110 142
       $this->contentType = $value;
111
-    } else if ($value===false) $this->contentType = '';
143
+    } else if ($value===false) {
144
+      $this->contentType = '';
145
+    }
112 146
     return $this->contentType;
113 147
   }
114 148
 
115
-  public function message($value=null){
149
+  public function message($value=null) {
116 150
     if ($value!==null && $value) {
117 151
       $this->compiled_body = null;
118 152
       $this->message = $value;
119
-    } else if ($value===false) $this->message = '';
153
+    } else if ($value===false) {
154
+      $this->message = '';
155
+    }
120 156
     return $this->message;
121 157
   }
122 158
 
123
-  public function attach($file){
159
+  public function attach($file) {
124 160
     $this->compiled_body = null;
125 161
     if (isset($file->content) || isset($file['content'])) {
126 162
       $this->attachments[] = $file;
127
-    } else foreach ((array)$file as $curfile) {
163
+    } else {
164
+      foreach ((array)$file as $curfile) {
128 165
       $this->attachments[] = $curfile;
129 166
     }
167
+    }
130 168
   }
131 169
 
132
-  public function head($recompile = false){
133
-    if ($recompile || (null === $this->compiled_head)){
170
+  public function head($recompile = false) {
171
+    if ($recompile || (null === $this->compiled_head)) {
134 172
       $head   = [];
135 173
       $head[] = "Subject: {$this->subject}";
136
-      if($this->from)                        $head[] = "From: {$this->from}";
137
-      if(is_array($this->to)  && !empty($this->to))  $head[] = "To: "  . implode(', ',$this->to);
138
-      if(is_array($this->cc)  && !empty($this->cc))  $head[] = "Cc: "  . implode(', ',$this->cc);
139
-      if(is_array($this->bcc) && !empty($this->bcc)) $head[] = "Bcc: " . implode(', ',$this->bcc);
140
-      if($this->replyTo)                     $head[] = "Reply-To: {$this->replyTo}";
174
+      if($this->from) {
175
+        $head[] = "From: {$this->from}";
176
+      }
177
+      if(is_array($this->to)  && !empty($this->to)) {
178
+        $head[] = "To: "  . implode(', ',$this->to);
179
+      }
180
+      if(is_array($this->cc)  && !empty($this->cc)) {
181
+        $head[] = "Cc: "  . implode(', ',$this->cc);
182
+      }
183
+      if(is_array($this->bcc) && !empty($this->bcc)) {
184
+        $head[] = "Bcc: " . implode(', ',$this->bcc);
185
+      }
186
+      if($this->replyTo) {
187
+        $head[] = "Reply-To: {$this->replyTo}";
188
+      }
141 189
       $head[] = 'MIME-Version: 1.0';
142 190
       $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->uid}\"";
143 191
       $this->compiled_head = implode("\r\n", $head);
@@ -145,8 +193,8 @@  discard block
 block discarded – undo
145 193
     return \Filter::with( 'core.email.source.head', $this->compiled_head);
146 194
   }
147 195
 
148
-  public function body($recompile = false){
149
-    if ($recompile || (null === $this->compiled_body)){
196
+  public function body($recompile = false) {
197
+    if ($recompile || (null === $this->compiled_body)) {
150 198
       $body[] = "--{$this->uid}";
151 199
       $body[] = "Content-Type: {$this->contentType}";
152 200
       $body[] = "Content-Transfer-Encoding: quoted-printable";
@@ -154,10 +202,12 @@  discard block
 block discarded – undo
154 202
       $body[] = quoted_printable_encode($this->message);
155 203
       $body[] = '';
156 204
 
157
-      if (!empty($this->attachments)) foreach ((array)$this->attachments as $file) {
205
+      if (!empty($this->attachments)) {
206
+        foreach ((array)$this->attachments as $file) {
158 207
 
159 208
         if (is_string($file)) {
160 209
           $name = basename($file);
210
+      }
161 211
           $data = file_get_contents($file);
162 212
         } else {
163 213
           $name = isset($file['name'])    ? $file['name']    : 'untitled';
@@ -180,7 +230,7 @@  discard block
 block discarded – undo
180 230
     return \Filter::with( 'core.email.source.body', $this->compiled_body);
181 231
   }
182 232
 
183
-  public function build(){
233
+  public function build() {
184 234
     return \Filter::with( 'core.email.source', $this->head() . "\r\n" . $this->body() );
185 235
   }
186 236
 
Please login to merge, or discard this patch.
classes/HTTP.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -18,6 +18,9 @@
 block discarded – undo
18 18
   protected static $headers     = [];
19 19
   protected static $last_info   = null;
20 20
 
21
+  /**
22
+   * @param string $method
23
+   */
21 24
   protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){
22 25
     $http_method = strtoupper($method);
23 26
     $ch = curl_init($url);
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
   protected static $headers     = [];
19 19
   protected static $last_info   = null;
20 20
 
21
-  protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){
21
+  protected static function request($method, $url, $data = [], array $headers = [], $data_as_json = false, $username = null, $password = null) {
22 22
     $http_method = strtoupper($method);
23 23
     $ch = curl_init($url);
24 24
     $opt = [
@@ -33,26 +33,26 @@  discard block
 block discarded – undo
33 33
       CURLOPT_ENCODING        => '',
34 34
     ];
35 35
 
36
-    if($username && $password) {
37
-      $opt[CURLOPT_USERPWD]   =  "$username:$password";
36
+    if ($username && $password) {
37
+      $opt[CURLOPT_USERPWD] = "$username:$password";
38 38
     }
39 39
 
40
-    $headers = array_merge($headers,static::$headers);
40
+    $headers = array_merge($headers, static::$headers);
41 41
 
42
-    if($http_method == 'GET'){
43
-        if($data && is_array($data)){
42
+    if ($http_method == 'GET') {
43
+        if ($data && is_array($data)) {
44 44
           $tmp                       = [];
45 45
           $queried_url               = $url;
46
-          foreach($data as $key=>$val) $tmp[] = $key.'='.$val;
47
-          $queried_url               .= (strpos($queried_url,'?')===false)?'?':'&';
48
-          $queried_url               .= implode('&',$tmp);
46
+          foreach ($data as $key=>$val) $tmp[] = $key.'='.$val;
47
+          $queried_url               .= (strpos($queried_url, '?') === false) ? '?' : '&';
48
+          $queried_url               .= implode('&', $tmp);
49 49
           $opt[CURLOPT_URL]          = $queried_url;
50 50
           unset($opt[CURLOPT_CUSTOMREQUEST]);
51 51
           $opt[CURLOPT_HTTPGET]      = true;
52 52
         } 
53 53
     } else {
54 54
         $opt[CURLOPT_CUSTOMREQUEST]   = $http_method;
55
-        if($data_as_json or is_object($data)){
55
+        if ($data_as_json or is_object($data)) {
56 56
           $headers['Content-Type']    = 'application/json';
57 57
           $opt[CURLOPT_POSTFIELDS]    = json_encode($data);     
58 58
         } else {
@@ -61,56 +61,56 @@  discard block
 block discarded – undo
61 61
     }
62 62
 
63 63
 
64
-    curl_setopt_array($ch,$opt);
64
+    curl_setopt_array($ch, $opt);
65 65
     $_harr = [];
66
-    foreach($headers as $key=>$val)  $_harr[] = $key.': '.$val;
66
+    foreach ($headers as $key=>$val)  $_harr[] = $key.': '.$val;
67 67
     curl_setopt($ch, CURLOPT_HTTPHEADER, $_harr);
68 68
     $result = curl_exec($ch);
69 69
     $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
70 70
     static::$last_info = curl_getinfo($ch);
71
-    if(false !== strpos($contentType,'json')) $result = json_decode($result);
71
+    if (false !== strpos($contentType, 'json')) $result = json_decode($result);
72 72
     curl_close($ch);
73 73
     return $result;
74 74
   }
75 75
   
76
-  public static function useJSON($value=null){
77
-    return static::$json_data = ($value===null?static::$json_data:$value);
76
+  public static function useJSON($value = null) {
77
+    return static::$json_data = ($value === null ? static::$json_data : $value);
78 78
   }
79 79
 
80
-  public static function addHeader($name,$value){
80
+  public static function addHeader($name, $value) {
81 81
     static::$headers[$name] = $value;
82 82
   }
83 83
 
84
-  public static function removeHeader($name){
84
+  public static function removeHeader($name) {
85 85
     unset(static::$headers[$name]);
86 86
   }
87 87
 
88
-  public static function headers($name=null){
89
-    return null===$name?static::$headers:(isset(static::$headers[$name])?static::$headers[$name]:'');
88
+  public static function headers($name = null) {
89
+    return null === $name ? static::$headers : (isset(static::$headers[$name]) ? static::$headers[$name] : '');
90 90
   }
91 91
 
92
-  public static function userAgent($value=null){
93
-    return static::$UA = ($value===null?static::$UA:$value);
92
+  public static function userAgent($value = null) {
93
+    return static::$UA = ($value === null ? static::$UA : $value);
94 94
   }
95 95
 
96
-  public static function get($url,$data=null,array $headers=[], $username = null, $password = null){
97
-    return static::request('get',$url,$data,$headers,false,$username,$password);
96
+  public static function get($url, $data = null, array $headers = [], $username = null, $password = null) {
97
+    return static::request('get', $url, $data, $headers, false, $username, $password);
98 98
   }
99 99
 
100
-  public static function post($url,$data=null,array $headers=[], $username = null, $password = null){
101
-    return static::request('post',$url,$data,$headers,static::$json_data,$username,$password);
100
+  public static function post($url, $data = null, array $headers = [], $username = null, $password = null) {
101
+    return static::request('post', $url, $data, $headers, static::$json_data, $username, $password);
102 102
   }
103 103
 
104
-  public static function put($url,$data=null,array $headers=[], $username = null, $password = null){
105
-    return static::request('put',$url,$data,$headers,static::$json_data,$username,$password);
104
+  public static function put($url, $data = null, array $headers = [], $username = null, $password = null) {
105
+    return static::request('put', $url, $data, $headers, static::$json_data, $username, $password);
106 106
   }
107 107
 
108
-  public static function delete($url,$data=null,array $headers=[], $username = null, $password = null){
109
-    return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password);
108
+  public static function delete($url, $data = null, array $headers = [], $username = null, $password = null) {
109
+    return static::request('delete', $url, $data, $headers, static::$json_data, $username, $password);
110 110
   }
111 111
 
112
-  public static function info($url=null){
113
-    if ($url){
112
+  public static function info($url = null) {
113
+    if ($url) {
114 114
       $ch = curl_init($url);
115 115
       curl_setopt_array($ch, [
116 116
         CURLOPT_SSL_VERIFYHOST  => false,
Please login to merge, or discard this patch.
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
   protected static $headers     = [];
19 19
   protected static $last_info   = null;
20 20
 
21
-  protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){
21
+  protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null) {
22 22
     $http_method = strtoupper($method);
23 23
     $ch = curl_init($url);
24 24
     $opt = [
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 
40 40
     $headers = array_merge($headers,static::$headers);
41 41
 
42
-    if($http_method == 'GET'){
43
-        if($data && is_array($data)){
42
+    if($http_method == 'GET') {
43
+        if($data && is_array($data)) {
44 44
           $tmp                       = [];
45 45
           $queried_url               = $url;
46 46
           foreach($data as $key=>$val) $tmp[] = $key.'='.$val;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
         } 
53 53
     } else {
54 54
         $opt[CURLOPT_CUSTOMREQUEST]   = $http_method;
55
-        if($data_as_json or is_object($data)){
55
+        if($data_as_json or is_object($data)) {
56 56
           $headers['Content-Type']    = 'application/json';
57 57
           $opt[CURLOPT_POSTFIELDS]    = json_encode($data);     
58 58
         } else {
@@ -68,49 +68,51 @@  discard block
 block discarded – undo
68 68
     $result = curl_exec($ch);
69 69
     $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
70 70
     static::$last_info = curl_getinfo($ch);
71
-    if(false !== strpos($contentType,'json')) $result = json_decode($result);
71
+    if(false !== strpos($contentType,'json')) {
72
+      $result = json_decode($result);
73
+    }
72 74
     curl_close($ch);
73 75
     return $result;
74 76
   }
75 77
   
76
-  public static function useJSON($value=null){
78
+  public static function useJSON($value=null) {
77 79
     return static::$json_data = ($value===null?static::$json_data:$value);
78 80
   }
79 81
 
80
-  public static function addHeader($name,$value){
82
+  public static function addHeader($name,$value) {
81 83
     static::$headers[$name] = $value;
82 84
   }
83 85
 
84
-  public static function removeHeader($name){
86
+  public static function removeHeader($name) {
85 87
     unset(static::$headers[$name]);
86 88
   }
87 89
 
88
-  public static function headers($name=null){
90
+  public static function headers($name=null) {
89 91
     return null===$name?static::$headers:(isset(static::$headers[$name])?static::$headers[$name]:'');
90 92
   }
91 93
 
92
-  public static function userAgent($value=null){
94
+  public static function userAgent($value=null) {
93 95
     return static::$UA = ($value===null?static::$UA:$value);
94 96
   }
95 97
 
96
-  public static function get($url,$data=null,array $headers=[], $username = null, $password = null){
98
+  public static function get($url,$data=null,array $headers=[], $username = null, $password = null) {
97 99
     return static::request('get',$url,$data,$headers,false,$username,$password);
98 100
   }
99 101
 
100
-  public static function post($url,$data=null,array $headers=[], $username = null, $password = null){
102
+  public static function post($url,$data=null,array $headers=[], $username = null, $password = null) {
101 103
     return static::request('post',$url,$data,$headers,static::$json_data,$username,$password);
102 104
   }
103 105
 
104
-  public static function put($url,$data=null,array $headers=[], $username = null, $password = null){
106
+  public static function put($url,$data=null,array $headers=[], $username = null, $password = null) {
105 107
     return static::request('put',$url,$data,$headers,static::$json_data,$username,$password);
106 108
   }
107 109
 
108
-  public static function delete($url,$data=null,array $headers=[], $username = null, $password = null){
110
+  public static function delete($url,$data=null,array $headers=[], $username = null, $password = null) {
109 111
     return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password);
110 112
   }
111 113
 
112
-  public static function info($url=null){
113
-    if ($url){
114
+  public static function info($url=null) {
115
+    if ($url) {
114 116
       $ch = curl_init($url);
115 117
       curl_setopt_array($ch, [
116 118
         CURLOPT_SSL_VERIFYHOST  => false,
Please login to merge, or discard this patch.