Completed
Push — master ( 1f9686...114e61 )
by Stefano
03:01
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
-         echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
169
+          // Use preg_replace_callback for fast regex matches navigation
170
+          echo strtr(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
-         },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]);
180
+          },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]);
181 181
       } else {
182
-         echo strtr($message,["&BR;"=>PHP_EOL]);
182
+          echo strtr($message,["&BR;"=>PHP_EOL]);
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   +60 added lines, -60 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,22 +164,22 @@  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
-         echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
170
+         echo strtr(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
-         },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]);
180
+         },strtr($message, ["\n"=>"&BR;"])), ["&BR;"=>PHP_EOL]);
181 181
       } else {
182
-         echo strtr($message,["&BR;"=>PHP_EOL]);
182
+         echo strtr($message, ["&BR;"=>PHP_EOL]);
183 183
       }
184 184
    }
185 185
    
@@ -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
-         echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){
174
+         echo strtr(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
          },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]);
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   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
       Event::trigger('core.route.end', $this);
141 141
 
142 142
       return [Filter::with('core.route.response', Response::body())];
143
-     }
143
+      }
144 144
 
145 145
     /**
146 146
      * Check if route match URL and HTTP Method and run if it is valid.
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -38,12 +38,12 @@  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
-      $prefix  = static::$prefix ? rtrim(implode('',static::$prefix),'/') : '';
43
-      $pattern = "/" . trim($URLPattern, "/");
41
+    public function __construct($URLPattern, $callback = null, $method = 'get') {
42
+      $prefix  = static::$prefix ? rtrim(implode('', static::$prefix), '/') : '';
43
+      $pattern = "/".trim($URLPattern, "/");
44 44
       // Adjust / optionality with dynamic patterns
45 45
       // Ex:  /test/(:a) ===> /test(/:a)
46
-      $this->URLPattern = str_replace('//','/',str_replace('/(','(/', rtrim("{$prefix}{$pattern}","/")));
46
+      $this->URLPattern = str_replace('//', '/', str_replace('/(', '(/', rtrim("{$prefix}{$pattern}", "/")));
47 47
 
48 48
       $this->dynamic    = $this->isDynamic($this->URLPattern);
49 49
       $this->pattern    = $this->dynamic ? $this->compilePatternAsRegex($this->URLPattern, $this->rules) : $this->URLPattern;
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
      * @param  string $method The HTTP Method to check against.
61 61
      * @return boolean
62 62
      */
63
-    public function match($URL,$method='get'){
63
+    public function match($URL, $method = 'get') {
64 64
       $method = strtolower($method);
65 65
 
66 66
       // * is an http method wildcard
67 67
       if (empty($this->methods[$method]) && empty($this->methods['*'])) return false;
68
-      $URL  = rtrim($URL,'/');
68
+      $URL  = rtrim($URL, '/');
69 69
       $args = [];
70
-      if ( $this->dynamic
71
-           ? preg_match($this->pattern,$URL,$args)
72
-           : $URL == rtrim($this->pattern,'/')
73
-      ){
74
-        foreach ( $args as $key => $value ) {
75
-          if ( false === is_string($key) ) unset($args[$key]);
70
+      if ($this->dynamic
71
+           ? preg_match($this->pattern, $URL, $args)
72
+           : $URL == rtrim($this->pattern, '/')
73
+      ) {
74
+        foreach ($args as $key => $value) {
75
+          if (false === is_string($key)) unset($args[$key]);
76 76
         }
77 77
         return $args;
78 78
       }
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
      * @param  string $method The HTTP Method requested.
86 86
      * @return array The callback response.
87 87
      */
88
-    public function run(array $args, $method='get'){
88
+    public function run(array $args, $method = 'get') {
89 89
       $method = strtolower($method);
90
-      $append_echoed_text = Options::get('core.route.append_echoed_text',true);
90
+      $append_echoed_text = Options::get('core.route.append_echoed_text', true);
91 91
 
92 92
       // Call direct befores
93
-      if ( $this->befores ) {
93
+      if ($this->befores) {
94 94
         // Reverse befores order
95 95
         foreach (array_reverse($this->befores) as $mw) {
96 96
           Event::trigger('core.route.before', $this, $mw);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
           $mw_result  = call_user_func($mw);
99 99
           $raw_echoed = ob_get_clean();
100 100
           if ($append_echoed_text) Response::add($raw_echoed);
101
-          if ( false  === $mw_result ) {
101
+          if (false === $mw_result) {
102 102
             return [''];
103 103
           } else {
104 104
             Response::add($mw_result);
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                   : $this->callback;
112 112
 
113 113
       if (is_callable($callback)) {
114
-        Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) );
114
+        Response::type(Options::get('core.route.response_default_type', Response::TYPE_HTML));
115 115
 
116 116
         ob_start();
117 117
         $view_results = call_user_func_array($callback, $args);
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
       }
123 123
 
124 124
       // Apply afters
125
-      if ( $this->afters ) {
125
+      if ($this->afters) {
126 126
         foreach ($this->afters as $mw) {
127 127
           Event::trigger('core.route.after', $this, $mw);
128 128
           ob_start();
129 129
           $mw_result  = call_user_func($mw);
130 130
           $raw_echoed = ob_get_clean();
131 131
           if ($append_echoed_text) Response::add($raw_echoed);
132
-          if ( false  === $mw_result ) {
132
+          if (false === $mw_result) {
133 133
             return [''];
134 134
           } else {
135 135
             Response::add($mw_result);
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
      * @param  string $method The HTTP Method to check against.
149 149
      * @return array The callback response.
150 150
      */
151
-    public function runIfMatch($URL, $method='get'){
152
-      return ($args = $this->match($URL,$method)) ? $this->run($args,$method) : null;
151
+    public function runIfMatch($URL, $method = 'get') {
152
+      return ($args = $this->match($URL, $method)) ? $this->run($args, $method) : null;
153 153
     }
154 154
 
155 155
     /**
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
159 159
      * @return Route
160 160
      */
161
-    public static function on($URLPattern, $callback = null){
162
-      return new Route($URLPattern,$callback);
161
+    public static function on($URLPattern, $callback = null) {
162
+      return new Route($URLPattern, $callback);
163 163
     }
164 164
 
165 165
     /**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
169 169
      * @return Route
170 170
      */
171
-    public static function get($URLPattern, $callback = null){
172
-      return (new Route($URLPattern,$callback))->via('get');
171
+    public static function get($URLPattern, $callback = null) {
172
+      return (new Route($URLPattern, $callback))->via('get');
173 173
     }
174 174
 
175 175
     /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
179 179
      * @return Route
180 180
      */
181
-    public static function post($URLPattern, $callback = null){
182
-      return (new Route($URLPattern,$callback))->via('post');
181
+    public static function post($URLPattern, $callback = null) {
182
+      return (new Route($URLPattern, $callback))->via('post');
183 183
     }
184 184
 
185 185
     /**
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
189 189
      * @return Route
190 190
      */
191
-    public static function any($URLPattern, $callback = null){
192
-      return (new Route($URLPattern,$callback))->via('*');
191
+    public static function any($URLPattern, $callback = null) {
192
+      return (new Route($URLPattern, $callback))->via('*');
193 193
     }
194 194
 
195 195
     /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function & via(){
236 236
       $this->methods = [];
237
-      foreach (func_get_args() as $method){
237
+      foreach (func_get_args() as $method) {
238 238
         $this->methods[strtolower($method)] = true;
239 239
       }
240 240
       return $this;
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
      * @return Route
257 257
      */
258 258
     public function & rules(array $rules){
259
-      foreach ((array)$rules as $varname => $rule){
259
+      foreach ((array) $rules as $varname => $rule) {
260 260
         $this->rules[$varname] = $rule;
261 261
       }
262
-      $this->pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules );
262
+      $this->pattern = $this->compilePatternAsRegex($this->URLPattern, $this->rules);
263 263
       return $this;
264 264
     }
265 265
 
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
      * @param  string $pattern The URL schema.
298 298
      * @return string The compiled PREG RegEx.
299 299
      */
300
-    protected static function compilePatternAsRegex($pattern, $rules=[]){
301
-      return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules){
302
-        return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
303
-      },str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
300
+    protected static function compilePatternAsRegex($pattern, $rules = []) {
301
+      return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S', function($g) use (&$rules){
302
+        return '(?<'.$g[1].'>'.(isset($rules[$g[1]]) ? $rules[$g[1]] : '[^/]+').')';
303
+      },str_replace(['.', ')', '*'], ['\.', ')?', '.+'], $pattern)).'$#';
304 304
     }
305 305
 
306 306
     /**
@@ -310,10 +310,10 @@  discard block
 block discarded – undo
310 310
      * @param  boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
311 311
      * @return array The extracted variables
312 312
      */
313
-    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
313
+    protected static function extractVariablesFromURL($pattern, $URL = null, $cut = false) {
314 314
       $URL     = $URL ?: Request::URI();
315
-      $pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
316
-      if ( !preg_match($pattern,$URL,$args) ) return false;
315
+      $pattern = $cut ? str_replace('$#', '', $pattern).'#' : $pattern;
316
+      if (!preg_match($pattern, $URL, $args)) return false;
317 317
       foreach ($args as $key => $value) {
318 318
         if (false === is_string($key)) unset($args[$key]);
319 319
       }
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
      * @param  string  $pattern The URL schema.
326 326
      * @return boolean
327 327
      */
328
-    protected static function isDynamic($pattern){
329
-      return strlen($pattern) != strcspn($pattern,':(?[*+');
328
+    protected static function isDynamic($pattern) {
329
+      return strlen($pattern) != strcspn($pattern, ':(?[*+');
330 330
     }
331 331
 
332 332
     /**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
      * @param Route $r
335 335
      * @return Route
336 336
      */
337
-    public static function add($r){
338
-      if ( isset(static::$group[0]) ) static::$group[0]->add($r);
337
+    public static function add($r) {
338
+      if (isset(static::$group[0])) static::$group[0]->add($r);
339 339
       return static::$routes[implode('', static::$prefix)][] = $r;
340 340
     }
341 341
 
@@ -344,10 +344,10 @@  discard block
 block discarded – undo
344 344
      * @param  string $prefix The url prefix for the internal route definitions.
345 345
      * @param  string $callback This callback is invoked on $prefix match of the current request URI.
346 346
      */
347
-    public static function group($prefix, $callback=null){
347
+    public static function group($prefix, $callback = null) {
348 348
 
349 349
       // Skip definition if current request doesn't match group.
350
-      $prefix_complete = rtrim(implode('',static::$prefix),'/') . $prefix;
350
+      $prefix_complete = rtrim(implode('', static::$prefix), '/').$prefix;
351 351
 
352 352
       static::$prefix[] = $prefix;
353 353
       if (empty(static::$group)) static::$group = [];
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
           $vars = static::extractVariablesFromURL(static::compilePatternAsRegex($prefix_complete), null, true);
362 362
           // Errors in compile pattern or variable extraction, aborting.
363 363
           if (false === $vars) return false;
364
-          if ($callback) call_user_func_array($callback,$vars);
364
+          if ($callback) call_user_func_array($callback, $vars);
365 365
         break;
366 366
 
367 367
         // Static group
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 
380 380
     }
381 381
 
382
-    public static function exitWithError($code,$message="Application Error"){
383
-      Response::error($code,$message);
382
+    public static function exitWithError($code, $message = "Application Error") {
383
+      Response::error($code, $message);
384 384
       Response::send();
385 385
       exit;
386 386
     }
@@ -390,27 +390,27 @@  discard block
 block discarded – undo
390 390
      * @param  string $URL The URL to match onto.
391 391
      * @return boolean true if a route callback was executed.
392 392
      */
393
-    public static function dispatch($URL=null,$method=null){
393
+    public static function dispatch($URL = null, $method = null) {
394 394
         if (!$URL)     $URL     = Request::URI();
395 395
         if (!$method)  $method  = Request::method();
396 396
 
397
-        $__deferred_send = new Deferred(function(){
398
-          if (Options::get('core.response.autosend',true)){
397
+        $__deferred_send = new Deferred(function() {
398
+          if (Options::get('core.response.autosend', true)) {
399 399
             Response::send();
400 400
           }
401 401
         });
402 402
 
403
-        foreach ((array)static::$routes as $group => $routes){
403
+        foreach ((array) static::$routes as $group => $routes) {
404 404
             foreach ($routes as $route) {
405
-                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))){
406
-                    $route->run($args,$method);
405
+                if (is_a($route, 'Route') && false !== ($args = $route->match($URL, $method))) {
406
+                    $route->run($args, $method);
407 407
                     return true;
408 408
                 }
409 409
             }
410 410
         }
411 411
 
412 412
         Response::status(404, '404 Resource not found.');
413
-        foreach (array_filter(Event::trigger(404)) as $res){
413
+        foreach (array_filter(Event::trigger(404)) as $res) {
414 414
 
415 415
         }
416 416
         return false;
@@ -420,34 +420,34 @@  discard block
 block discarded – undo
420 420
 class RouteGroup {
421 421
   protected $routes;
422 422
 
423
-  public function __construct(){
423
+  public function __construct() {
424 424
     $this->routes = new SplObjectStorage;
425 425
     return Route::add($this);
426 426
   }
427 427
 
428
-  public function has($r){
428
+  public function has($r) {
429 429
     return $this->routes->contains($r);
430 430
   }
431 431
 
432
-  public function add($r){
432
+  public function add($r) {
433 433
     $this->routes->attach($r);
434 434
     return $this;
435 435
   }
436 436
 
437
-  public function remove($r){
437
+  public function remove($r) {
438 438
     if ($this->routes->contains($r)) $this->routes->detach($r);
439 439
     return $this;
440 440
   }
441 441
 
442
-  public function before($callbacks){
443
-    foreach ($this->routes as $route){
442
+  public function before($callbacks) {
443
+    foreach ($this->routes as $route) {
444 444
       $route->before($callbacks);
445 445
     }
446 446
     return $this;
447 447
   }
448 448
 
449
-  public function after($callbacks){
450
-    foreach ($this->routes as $route){
449
+  public function after($callbacks) {
450
+    foreach ($this->routes as $route) {
451 451
       $route->after($callbacks);
452 452
     }
453 453
     return $this;
Please login to merge, or discard this patch.
Braces   +83 added lines, -49 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
       $prefix  = static::$prefix ? rtrim(implode('',static::$prefix),'/') : '';
43 43
       $pattern = "/" . trim($URLPattern, "/");
44 44
       // Adjust / optionality with dynamic patterns
@@ -60,19 +60,23 @@  discard block
 block discarded – undo
60 60
      * @param  string $method The HTTP Method to check against.
61 61
      * @return boolean
62 62
      */
63
-    public function match($URL,$method='get'){
63
+    public function match($URL,$method='get') {
64 64
       $method = strtolower($method);
65 65
 
66 66
       // * is an http method wildcard
67
-      if (empty($this->methods[$method]) && empty($this->methods['*'])) return false;
67
+      if (empty($this->methods[$method]) && empty($this->methods['*'])) {
68
+        return false;
69
+      }
68 70
       $URL  = rtrim($URL,'/');
69 71
       $args = [];
70 72
       if ( $this->dynamic
71 73
            ? preg_match($this->pattern,$URL,$args)
72 74
            : $URL == rtrim($this->pattern,'/')
73
-      ){
75
+      ) {
74 76
         foreach ( $args as $key => $value ) {
75
-          if ( false === is_string($key) ) unset($args[$key]);
77
+          if ( false === is_string($key) ) {
78
+            unset($args[$key]);
79
+          }
76 80
         }
77 81
         return $args;
78 82
       }
@@ -85,7 +89,7 @@  discard block
 block discarded – undo
85 89
      * @param  string $method The HTTP Method requested.
86 90
      * @return array The callback response.
87 91
      */
88
-    public function run(array $args, $method='get'){
92
+    public function run(array $args, $method='get') {
89 93
       $method = strtolower($method);
90 94
       $append_echoed_text = Options::get('core.route.append_echoed_text',true);
91 95
 
@@ -97,7 +101,9 @@  discard block
 block discarded – undo
97 101
           ob_start();
98 102
           $mw_result  = call_user_func($mw);
99 103
           $raw_echoed = ob_get_clean();
100
-          if ($append_echoed_text) Response::add($raw_echoed);
104
+          if ($append_echoed_text) {
105
+            Response::add($raw_echoed);
106
+          }
101 107
           if ( false  === $mw_result ) {
102 108
             return [''];
103 109
           } else {
@@ -117,7 +123,9 @@  discard block
 block discarded – undo
117 123
         $view_results = call_user_func_array($callback, $args);
118 124
         $raw_echoed   = ob_get_clean();
119 125
 
120
-        if ($append_echoed_text) Response::add($raw_echoed);
126
+        if ($append_echoed_text) {
127
+          Response::add($raw_echoed);
128
+        }
121 129
         Response::add($view_results);
122 130
       }
123 131
 
@@ -128,7 +136,9 @@  discard block
 block discarded – undo
128 136
           ob_start();
129 137
           $mw_result  = call_user_func($mw);
130 138
           $raw_echoed = ob_get_clean();
131
-          if ($append_echoed_text) Response::add($raw_echoed);
139
+          if ($append_echoed_text) {
140
+            Response::add($raw_echoed);
141
+          }
132 142
           if ( false  === $mw_result ) {
133 143
             return [''];
134 144
           } else {
@@ -148,7 +158,7 @@  discard block
 block discarded – undo
148 158
      * @param  string $method The HTTP Method to check against.
149 159
      * @return array The callback response.
150 160
      */
151
-    public function runIfMatch($URL, $method='get'){
161
+    public function runIfMatch($URL, $method='get') {
152 162
       return ($args = $this->match($URL,$method)) ? $this->run($args,$method) : null;
153 163
     }
154 164
 
@@ -158,7 +168,7 @@  discard block
 block discarded – undo
158 168
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
159 169
      * @return Route
160 170
      */
161
-    public static function on($URLPattern, $callback = null){
171
+    public static function on($URLPattern, $callback = null) {
162 172
       return new Route($URLPattern,$callback);
163 173
     }
164 174
 
@@ -168,7 +178,7 @@  discard block
 block discarded – undo
168 178
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
169 179
      * @return Route
170 180
      */
171
-    public static function get($URLPattern, $callback = null){
181
+    public static function get($URLPattern, $callback = null) {
172 182
       return (new Route($URLPattern,$callback))->via('get');
173 183
     }
174 184
 
@@ -178,7 +188,7 @@  discard block
 block discarded – undo
178 188
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
179 189
      * @return Route
180 190
      */
181
-    public static function post($URLPattern, $callback = null){
191
+    public static function post($URLPattern, $callback = null) {
182 192
       return (new Route($URLPattern,$callback))->via('post');
183 193
     }
184 194
 
@@ -188,7 +198,7 @@  discard block
 block discarded – undo
188 198
      * @param  $callback The callback to be invoked (with variables extracted from the route if present) when the route match the request URI.
189 199
      * @return Route
190 200
      */
191
-    public static function any($URLPattern, $callback = null){
201
+    public static function any($URLPattern, $callback = null) {
192 202
       return (new Route($URLPattern,$callback))->via('*');
193 203
     }
194 204
 
@@ -234,7 +244,7 @@  discard block
 block discarded – undo
234 244
      */
235 245
     public function & via(){
236 246
       $this->methods = [];
237
-      foreach (func_get_args() as $method){
247
+      foreach (func_get_args() as $method) {
238 248
         $this->methods[strtolower($method)] = true;
239 249
       }
240 250
       return $this;
@@ -256,7 +266,7 @@  discard block
 block discarded – undo
256 266
      * @return Route
257 267
      */
258 268
     public function & rules(array $rules){
259
-      foreach ((array)$rules as $varname => $rule){
269
+      foreach ((array)$rules as $varname => $rule) {
260 270
         $this->rules[$varname] = $rule;
261 271
       }
262 272
       $this->pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules );
@@ -285,7 +295,9 @@  discard block
 block discarded – undo
285 295
       $route->callback = [];
286 296
       foreach ($callbacks as $method => $callback) {
287 297
         $method = strtolower($method);
288
-        if (Request::method() !== $method) continue;
298
+        if (Request::method() !== $method) {
299
+          continue;
300
+        }
289 301
         $route->callback[$method] = $callback;
290 302
         $route->methods[$method]  = 1;
291 303
       }
@@ -297,8 +309,8 @@  discard block
 block discarded – undo
297 309
      * @param  string $pattern The URL schema.
298 310
      * @return string The compiled PREG RegEx.
299 311
      */
300
-    protected static function compilePatternAsRegex($pattern, $rules=[]){
301
-      return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules){
312
+    protected static function compilePatternAsRegex($pattern, $rules=[]) {
313
+      return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#S',function($g) use (&$rules) {
302 314
         return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
303 315
       },str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
304 316
     }
@@ -310,12 +322,16 @@  discard block
 block discarded – undo
310 322
      * @param  boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
311 323
      * @return array The extracted variables
312 324
      */
313
-    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
325
+    protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false) {
314 326
       $URL     = $URL ?: Request::URI();
315 327
       $pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
316
-      if ( !preg_match($pattern,$URL,$args) ) return false;
328
+      if ( !preg_match($pattern,$URL,$args) ) {
329
+        return false;
330
+      }
317 331
       foreach ($args as $key => $value) {
318
-        if (false === is_string($key)) unset($args[$key]);
332
+        if (false === is_string($key)) {
333
+          unset($args[$key]);
334
+        }
319 335
       }
320 336
       return $args;
321 337
     }
@@ -325,7 +341,7 @@  discard block
 block discarded – undo
325 341
      * @param  string  $pattern The URL schema.
326 342
      * @return boolean
327 343
      */
328
-    protected static function isDynamic($pattern){
344
+    protected static function isDynamic($pattern) {
329 345
       return strlen($pattern) != strcspn($pattern,':(?[*+');
330 346
     }
331 347
 
@@ -334,8 +350,10 @@  discard block
 block discarded – undo
334 350
      * @param Route $r
335 351
      * @return Route
336 352
      */
337
-    public static function add($r){
338
-      if ( isset(static::$group[0]) ) static::$group[0]->add($r);
353
+    public static function add($r) {
354
+      if ( isset(static::$group[0]) ) {
355
+        static::$group[0]->add($r);
356
+      }
339 357
       return static::$routes[implode('', static::$prefix)][] = $r;
340 358
     }
341 359
 
@@ -344,13 +362,15 @@  discard block
 block discarded – undo
344 362
      * @param  string $prefix The url prefix for the internal route definitions.
345 363
      * @param  string $callback This callback is invoked on $prefix match of the current request URI.
346 364
      */
347
-    public static function group($prefix, $callback=null){
365
+    public static function group($prefix, $callback=null) {
348 366
 
349 367
       // Skip definition if current request doesn't match group.
350 368
       $prefix_complete = rtrim(implode('',static::$prefix),'/') . $prefix;
351 369
 
352 370
       static::$prefix[] = $prefix;
353
-      if (empty(static::$group)) static::$group = [];
371
+      if (empty(static::$group)) {
372
+        static::$group = [];
373
+      }
354 374
       array_unshift(static::$group, new RouteGroup());
355 375
 
356 376
       switch (true) {
@@ -360,13 +380,19 @@  discard block
 block discarded – undo
360 380
           // Capture vars
361 381
           $vars = static::extractVariablesFromURL(static::compilePatternAsRegex($prefix_complete), null, true);
362 382
           // Errors in compile pattern or variable extraction, aborting.
363
-          if (false === $vars) return false;
364
-          if ($callback) call_user_func_array($callback,$vars);
383
+          if (false === $vars) {
384
+            return false;
385
+          }
386
+          if ($callback) {
387
+            call_user_func_array($callback,$vars);
388
+          }
365 389
         break;
366 390
 
367 391
         // Static group
368 392
         case 0 === strpos(Request::URI(), $prefix_complete) :
369
-          if ($callback) call_user_func($callback);
393
+          if ($callback) {
394
+            call_user_func($callback);
395
+          }
370 396
         break;
371 397
 
372 398
       }
@@ -374,12 +400,14 @@  discard block
 block discarded – undo
374 400
       $group = static::$group[0];
375 401
       array_shift(static::$group);
376 402
       array_pop(static::$prefix);
377
-      if (empty(static::$prefix)) static::$prefix = [''];
403
+      if (empty(static::$prefix)) {
404
+        static::$prefix = [''];
405
+      }
378 406
       return $group;
379 407
 
380 408
     }
381 409
 
382
-    public static function exitWithError($code,$message="Application Error"){
410
+    public static function exitWithError($code,$message="Application Error") {
383 411
       Response::error($code,$message);
384 412
       Response::send();
385 413
       exit;
@@ -390,19 +418,23 @@  discard block
 block discarded – undo
390 418
      * @param  string $URL The URL to match onto.
391 419
      * @return boolean true if a route callback was executed.
392 420
      */
393
-    public static function dispatch($URL=null,$method=null){
394
-        if (!$URL)     $URL     = Request::URI();
395
-        if (!$method)  $method  = Request::method();
421
+    public static function dispatch($URL=null,$method=null) {
422
+        if (!$URL) {
423
+          $URL     = Request::URI();
424
+        }
425
+        if (!$method) {
426
+          $method  = Request::method();
427
+        }
396 428
 
397
-        $__deferred_send = new Deferred(function(){
398
-          if (Options::get('core.response.autosend',true)){
429
+        $__deferred_send = new Deferred(function() {
430
+          if (Options::get('core.response.autosend',true)) {
399 431
             Response::send();
400 432
           }
401 433
         });
402 434
 
403
-        foreach ((array)static::$routes as $group => $routes){
435
+        foreach ((array)static::$routes as $group => $routes) {
404 436
             foreach ($routes as $route) {
405
-                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))){
437
+                if (is_a($route, 'Route') && false !== ($args = $route->match($URL,$method))) {
406 438
                     $route->run($args,$method);
407 439
                     return true;
408 440
                 }
@@ -410,7 +442,7 @@  discard block
 block discarded – undo
410 442
         }
411 443
 
412 444
         Response::status(404, '404 Resource not found.');
413
-        foreach (array_filter(Event::trigger(404)) as $res){
445
+        foreach (array_filter(Event::trigger(404)) as $res) {
414 446
 
415 447
         }
416 448
         return false;
@@ -420,34 +452,36 @@  discard block
 block discarded – undo
420 452
 class RouteGroup {
421 453
   protected $routes;
422 454
 
423
-  public function __construct(){
455
+  public function __construct() {
424 456
     $this->routes = new SplObjectStorage;
425 457
     return Route::add($this);
426 458
   }
427 459
 
428
-  public function has($r){
460
+  public function has($r) {
429 461
     return $this->routes->contains($r);
430 462
   }
431 463
 
432
-  public function add($r){
464
+  public function add($r) {
433 465
     $this->routes->attach($r);
434 466
     return $this;
435 467
   }
436 468
 
437
-  public function remove($r){
438
-    if ($this->routes->contains($r)) $this->routes->detach($r);
469
+  public function remove($r) {
470
+    if ($this->routes->contains($r)) {
471
+      $this->routes->detach($r);
472
+    }
439 473
     return $this;
440 474
   }
441 475
 
442
-  public function before($callbacks){
443
-    foreach ($this->routes as $route){
476
+  public function before($callbacks) {
477
+    foreach ($this->routes as $route) {
444 478
       $route->before($callbacks);
445 479
     }
446 480
     return $this;
447 481
   }
448 482
 
449
-  public function after($callbacks){
450
-    foreach ($this->routes as $route){
483
+  public function after($callbacks) {
484
+    foreach ($this->routes as $route) {
451 485
       $route->after($callbacks);
452 486
     }
453 487
     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   +73 added lines, -73 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,18 +175,18 @@  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 column($query, $params=[], $column=0){
186
-    if(!$this->connection()) return false;
185
+  public function column($query, $params = [], $column = 0) {
186
+    if (!$this->connection()) return false;
187 187
 
188 188
     $results = [];
189
-    $res     = $this->exec($query,$params);
189
+    $res     = $this->exec($query, $params);
190 190
 
191 191
     if (is_string($column))
192 192
       while ($x = $res->fetch(PDO::FETCH_OBJ)) $results[] = $x->$column;
@@ -196,25 +196,25 @@  discard block
 block discarded – undo
196 196
     return $results;
197 197
   }
198 198
 
199
-  public function each($query, $params=[], callable $looper = null){
200
-    if(!$this->connection()) return false;
199
+  public function each($query, $params = [], callable $looper = null) {
200
+    if (!$this->connection()) return false;
201 201
 
202 202
     // ($query,$looper) shorthand
203
-    if ($looper===null && is_callable($params)) {$looper = $params; $params = [];}
204
-    if( $res = $this->exec($query,$params) ){
205
-      if(is_callable($looper))
203
+    if ($looper === null && is_callable($params)) {$looper = $params;$params = [];}
204
+    if ($res = $this->exec($query, $params)) {
205
+      if (is_callable($looper))
206 206
         while ($row = $res->fetchObject()) $looper($row);
207 207
       else
208 208
         return $res->fetchAll(PDO::FETCH_CLASS);
209 209
     }
210 210
   }
211 211
 
212
-  public function single($query, $params=[], callable $handler = null){
213
-    if(!$this->connection()) return false;
212
+  public function single($query, $params = [], callable $handler = null) {
213
+    if (!$this->connection()) return false;
214 214
 
215 215
     // ($query,$handler) shorthand
216
-    if ($handler===null && is_callable($params)) {$handler = $params; $params = [];}
217
-    if( $res = $this->exec($query,$params) ){
216
+    if ($handler === null && is_callable($params)) {$handler = $params;$params = [];}
217
+    if ($res = $this->exec($query, $params)) {
218 218
         if (is_callable($handler))
219 219
           $handler($res->fetchObject());
220 220
         else
@@ -222,76 +222,76 @@  discard block
 block discarded – undo
222 222
     }
223 223
   }
224 224
 
225
- public function run($script){
226
-    if(!$this->connection()) return false;
225
+ public function run($script) {
226
+    if (!$this->connection()) return false;
227 227
 
228
-    $sql_path = Options::get('database.sql.path',APP_DIR.'/sql');
229
-    $sql_sep  = Options::get('database.sql.separator',';');
230
-    if (is_file($f = "$sql_path/$script.sql")){
228
+    $sql_path = Options::get('database.sql.path', APP_DIR.'/sql');
229
+    $sql_sep  = Options::get('database.sql.separator', ';');
230
+    if (is_file($f = "$sql_path/$script.sql")) {
231 231
         $result = true;
232
-        foreach(explode($sql_sep,file_get_contents($f)) as $statement) {
232
+        foreach (explode($sql_sep, file_get_contents($f)) as $statement) {
233 233
             $result = $this->exec($statement);
234 234
         }
235 235
         return $result;
236 236
     } else return false;
237 237
   }
238 238
 
239
-  public function all($query, $params=[], callable $looper = null){
240
-   if(!$this->connection()) return false;
241
-   return $this->each($query,$params,$looper);
239
+  public function all($query, $params = [], callable $looper = null) {
240
+   if (!$this->connection()) return false;
241
+   return $this->each($query, $params, $looper);
242 242
   }
243 243
 
244
-  public function delete($table, $pks=null, $pk='id', $inclusive=true){
245
-    if(!$this->connection()) return false;
244
+  public function delete($table, $pks = null, $pk = 'id', $inclusive = true) {
245
+    if (!$this->connection()) return false;
246 246
 
247
-    if (null===$pks) {
247
+    if (null === $pks) {
248 248
       return $this->exec("DELETE FROM `$table`");
249 249
     } else {
250
-      return $this->exec("DELETE FROM `$table` WHERE `$pk` ".($inclusive ? "" : "NOT " )."IN (" . implode( ',', array_fill_keys( (array)$pks, '?' ) ) . ")",(array)$pks);
250
+      return $this->exec("DELETE FROM `$table` WHERE `$pk` ".($inclusive ? "" : "NOT ")."IN (".implode(',', array_fill_keys((array) $pks, '?')).")", (array) $pks);
251 251
     }
252 252
   }
253 253
 
254
-  public function insert($table, $data){
255
-    if(!$this->connection()) return false;
254
+  public function insert($table, $data) {
255
+    if (!$this->connection()) return false;
256 256
 
257
-    if (false==is_array($data)) $data = (array)$data;
257
+    if (false == is_array($data)) $data = (array) $data;
258 258
     $k = array_keys($data);
259 259
     asort($k);
260 260
     $pk = $k;
261
-    array_walk($pk,function(&$e){ $e = ':'.$e;});
262
-    $q = "INSERT INTO `$table` (`".implode('`,`',$k)."`) VALUES (".implode(',',$pk).")";
263
-    $this->exec($q,$data);
261
+    array_walk($pk, function(&$e) { $e = ':'.$e;});
262
+    $q = "INSERT INTO `$table` (`".implode('`,`', $k)."`) VALUES (".implode(',', $pk).")";
263
+    $this->exec($q, $data);
264 264
     return $this->last_exec_success ? $this->connection()->lastInsertId() : false;
265 265
   }
266 266
 
267
-  public function updateWhere($table, $data, $where, $pk='id'){
268
-    if(!$this->connection()) return false;
267
+  public function updateWhere($table, $data, $where, $pk = 'id') {
268
+    if (!$this->connection()) return false;
269 269
 
270
-    if (false==is_array($data)) $data = (array)$data;
270
+    if (false == is_array($data)) $data = (array) $data;
271 271
     if (empty($data)) return false;
272 272
     $k = array_keys($data);
273 273
     asort($k);
274 274
 
275 275
     // Remove primary key from SET
276
-    array_walk($k,function(&$e) use ($pk) {
277
-      $e = ($e==$pk) ? null : "`$e`=:$e";
276
+    array_walk($k, function(&$e) use ($pk) {
277
+      $e = ($e == $pk) ? null : "`$e`=:$e";
278 278
     });
279 279
 
280
-    $q = "UPDATE `$table` SET ".implode(', ',array_filter($k))." WHERE $where";
281
-    $this->exec($q,$data);
280
+    $q = "UPDATE `$table` SET ".implode(', ', array_filter($k))." WHERE $where";
281
+    $this->exec($q, $data);
282 282
     return $this->last_exec_success;
283 283
   }
284 284
 
285
-  public function update($table, $data, $pk='id', $extra_where=''){
285
+  public function update($table, $data, $pk = 'id', $extra_where = '') {
286 286
     return $this->updateWhere($table, $data, "`$pk`=:$pk $extra_where", $pk);
287 287
   }
288 288
 
289
-  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where=''){
290
-    if(!$this->connection()) return false;
289
+  public function insertOrUpdate($table, $data = [], $pk = 'id', $extra_where = '') {
290
+    if (!$this->connection()) return false;
291 291
 
292
-    if (false==is_array($data)) $data = (array)$data;
292
+    if (false == is_array($data)) $data = (array) $data;
293 293
     if (empty($data[$pk])) return $this->insert($table, $data);
294
-    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ){
294
+    if ((string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk]) {
295 295
         return $this->update($table, $data, $pk, $extra_where);
296 296
     } else {
297 297
         return $this->insert($table, $data);
Please login to merge, or discard this patch.
Braces   +113 added lines, -64 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,74 +189,93 @@  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 column($query, $params=[], $column=0){
186
-    if(!$this->connection()) return false;
201
+  public function column($query, $params=[], $column=0) {
202
+    if(!$this->connection()) {
203
+      return false;
204
+    }
187 205
 
188 206
     $results = [];
189 207
     $res     = $this->exec($query,$params);
190 208
 
191
-    if (is_string($column))
192
-      while ($x = $res->fetch(PDO::FETCH_OBJ)) $results[] = $x->$column;
193
-    else
194
-      while ($x = $res->fetchColumn($column)) $results[] = $x;
209
+    if (is_string($column)) {
210
+          while ($x = $res->fetch(PDO::FETCH_OBJ)) $results[] = $x->$column;
211
+    } else {
212
+          while ($x = $res->fetchColumn($column)) $results[] = $x;
213
+    }
195 214
 
196 215
     return $results;
197 216
   }
198 217
 
199
-  public function each($query, $params=[], callable $looper = null){
200
-    if(!$this->connection()) return false;
218
+  public function each($query, $params=[], callable $looper = null) {
219
+    if(!$this->connection()) {
220
+      return false;
221
+    }
201 222
 
202 223
     // ($query,$looper) shorthand
203 224
     if ($looper===null && is_callable($params)) {$looper = $params; $params = [];}
204
-    if( $res = $this->exec($query,$params) ){
205
-      if(is_callable($looper))
206
-        while ($row = $res->fetchObject()) $looper($row);
207
-      else
208
-        return $res->fetchAll(PDO::FETCH_CLASS);
225
+    if( $res = $this->exec($query,$params) ) {
226
+      if(is_callable($looper)) {
227
+              while ($row = $res->fetchObject()) $looper($row);
228
+      } else {
229
+              return $res->fetchAll(PDO::FETCH_CLASS);
230
+      }
209 231
     }
210 232
   }
211 233
 
212
-  public function single($query, $params=[], callable $handler = null){
213
-    if(!$this->connection()) return false;
234
+  public function single($query, $params=[], callable $handler = null) {
235
+    if(!$this->connection()) {
236
+      return false;
237
+    }
214 238
 
215 239
     // ($query,$handler) shorthand
216 240
     if ($handler===null && is_callable($params)) {$handler = $params; $params = [];}
217
-    if( $res = $this->exec($query,$params) ){
218
-        if (is_callable($handler))
219
-          $handler($res->fetchObject());
220
-        else
221
-          return $res->fetchObject();
241
+    if( $res = $this->exec($query,$params) ) {
242
+        if (is_callable($handler)) {
243
+                  $handler($res->fetchObject());
244
+        } else {
245
+                  return $res->fetchObject();
246
+        }
222 247
     }
223 248
   }
224 249
 
225
- public function run($script){
226
-    if(!$this->connection()) return false;
250
+ public function run($script) {
251
+    if(!$this->connection()) {
252
+      return false;
253
+    }
227 254
 
228 255
     $sql_path = Options::get('database.sql.path',APP_DIR.'/sql');
229 256
     $sql_sep  = Options::get('database.sql.separator',';');
230
-    if (is_file($f = "$sql_path/$script.sql")){
257
+    if (is_file($f = "$sql_path/$script.sql")) {
231 258
         $result = true;
232 259
         foreach(explode($sql_sep,file_get_contents($f)) as $statement) {
233 260
             $result = $this->exec($statement);
234 261
         }
235 262
         return $result;
236
-    } else return false;
263
+    } else {
264
+      return false;
265
+    }
237 266
   }
238 267
 
239
-  public function all($query, $params=[], callable $looper = null){
240
-   if(!$this->connection()) return false;
268
+  public function all($query, $params=[], callable $looper = null) {
269
+   if(!$this->connection()) {
270
+     return false;
271
+   }
241 272
    return $this->each($query,$params,$looper);
242 273
   }
243 274
 
244
-  public function delete($table, $pks=null, $pk='id', $inclusive=true){
245
-    if(!$this->connection()) return false;
275
+  public function delete($table, $pks=null, $pk='id', $inclusive=true) {
276
+    if(!$this->connection()) {
277
+      return false;
278
+    }
246 279
 
247 280
     if (null===$pks) {
248 281
       return $this->exec("DELETE FROM `$table`");
@@ -251,10 +284,14 @@  discard block
 block discarded – undo
251 284
     }
252 285
   }
253 286
 
254
-  public function insert($table, $data){
255
-    if(!$this->connection()) return false;
287
+  public function insert($table, $data) {
288
+    if(!$this->connection()) {
289
+      return false;
290
+    }
256 291
 
257
-    if (false==is_array($data)) $data = (array)$data;
292
+    if (false==is_array($data)) {
293
+      $data = (array)$data;
294
+    }
258 295
     $k = array_keys($data);
259 296
     asort($k);
260 297
     $pk = $k;
@@ -264,11 +301,17 @@  discard block
 block discarded – undo
264 301
     return $this->last_exec_success ? $this->connection()->lastInsertId() : false;
265 302
   }
266 303
 
267
-  public function updateWhere($table, $data, $where, $pk='id'){
268
-    if(!$this->connection()) return false;
304
+  public function updateWhere($table, $data, $where, $pk='id') {
305
+    if(!$this->connection()) {
306
+      return false;
307
+    }
269 308
 
270
-    if (false==is_array($data)) $data = (array)$data;
271
-    if (empty($data)) return false;
309
+    if (false==is_array($data)) {
310
+      $data = (array)$data;
311
+    }
312
+    if (empty($data)) {
313
+      return false;
314
+    }
272 315
     $k = array_keys($data);
273 316
     asort($k);
274 317
 
@@ -282,16 +325,22 @@  discard block
 block discarded – undo
282 325
     return $this->last_exec_success;
283 326
   }
284 327
 
285
-  public function update($table, $data, $pk='id', $extra_where=''){
328
+  public function update($table, $data, $pk='id', $extra_where='') {
286 329
     return $this->updateWhere($table, $data, "`$pk`=:$pk $extra_where", $pk);
287 330
   }
288 331
 
289
-  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where=''){
290
-    if(!$this->connection()) return false;
332
+  public function insertOrUpdate($table, $data=[], $pk='id', $extra_where='') {
333
+    if(!$this->connection()) {
334
+      return false;
335
+    }
291 336
 
292
-    if (false==is_array($data)) $data = (array)$data;
293
-    if (empty($data[$pk])) return $this->insert($table, $data);
294
-    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ){
337
+    if (false==is_array($data)) {
338
+      $data = (array)$data;
339
+    }
340
+    if (empty($data[$pk])) {
341
+      return $this->insert($table, $data);
342
+    }
343
+    if( (string) $this->value("SELECT `$pk` FROM `$table` WHERE `$pk`=? LIMIT 1", [$data[$pk]]) === (string) $data[$pk] ) {
295 344
         return $this->update($table, $data, $pk, $extra_where);
296 345
     } else {
297 346
         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.
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,45 +121,45 @@  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
     /**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @param  mixed $payload Data to append to the response buffer
174 174
      */
175
-    public static function add(){
176
-      foreach(func_get_args() as $data){
175
+    public static function add() {
176
+      foreach (func_get_args() as $data) {
177 177
         switch (true) {
178 178
           case is_callable($data) :
179 179
             return static::add($data());
@@ -187,27 +187,27 @@  discard block
 block discarded – undo
187 187
       }
188 188
     }
189 189
 
190
-    public static function status($code,$message=''){
191
-        static::header('Status',$message?:$code,$code);
190
+    public static function status($code, $message = '') {
191
+        static::header('Status', $message ?: $code, $code);
192 192
     }
193 193
 
194
-    public static function header($name,$value,$code=null){
195
-        static::$headers[$name] = [$value,$code];
194
+    public static function header($name, $value, $code = null) {
195
+        static::$headers[$name] = [$value, $code];
196 196
     }
197 197
 
198
-    public static function error($code=500,$message='Application Error'){
199
-        Event::trigger('core.response.error',$code,$message);
200
-        static::status($code,$message);
198
+    public static function error($code = 500, $message = 'Application Error') {
199
+        Event::trigger('core.response.error', $code, $message);
200
+        static::status($code, $message);
201 201
     }
202 202
 
203
-    public static function body($setBody=null){
203
+    public static function body($setBody = null) {
204 204
       if ($setBody) static::$payload = [$setBody];
205 205
       return Filter::with('core.response.body',
206
-                is_array(static::$payload) ? implode('',static::$payload) : static::$payload
206
+                is_array(static::$payload) ? implode('', static::$payload) : static::$payload
207 207
              );
208 208
     }
209 209
 
210
-    public static function headers($setHeaders=null){
210
+    public static function headers($setHeaders = null) {
211 211
        if ($setHeaders) static::$headers = $setHeaders;
212 212
        return static::$headers;
213 213
     }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      *
220 220
      * @return array Headers and body of the response
221 221
      */
222
-    public static function save(){
222
+    public static function save() {
223 223
         return [
224 224
           'head' => static::$headers,
225 225
           'body' => static::body(),
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
      *
234 234
      * @param  array $data head/body saved state
235 235
      */
236
-    public static function load($data){
237
-      $data = (object)$data;
236
+    public static function load($data) {
237
+      $data = (object) $data;
238 238
       if (isset($data->head)) static::headers($data->head);
239 239
       if (isset($data->body)) static::body($data->body);
240 240
     }
241 241
 
242
-    public static function send($force = false){
242
+    public static function send($force = false) {
243 243
       if (!static::$sent || $force) {
244 244
         static::$sent = true;
245 245
         Event::trigger('core.response.send');
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
                 $code  = null;
253 253
             }
254 254
 
255
-            if ($value == 'Status'){
256
-              if (function_exists('http_response_code')){
255
+            if ($value == 'Status') {
256
+              if (function_exists('http_response_code')) {
257 257
                 http_response_code($code);
258 258
               } else {
259 259
                 header("Status: $code", true, $code);
Please login to merge, or discard this patch.
Braces   +44 added lines, -32 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
     }
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @param  mixed $payload Data to append to the response buffer
174 174
      */
175
-    public static function add(){
176
-      foreach(func_get_args() as $data){
175
+    public static function add() {
176
+      foreach(func_get_args() as $data) {
177 177
         switch (true) {
178 178
           case is_callable($data) :
179 179
             return static::add($data());
@@ -187,28 +187,32 @@  discard block
 block discarded – undo
187 187
       }
188 188
     }
189 189
 
190
-    public static function status($code,$message=''){
190
+    public static function status($code,$message='') {
191 191
         static::header('Status',$message?:$code,$code);
192 192
     }
193 193
 
194
-    public static function header($name,$value,$code=null){
194
+    public static function header($name,$value,$code=null) {
195 195
         static::$headers[$name] = [$value,$code];
196 196
     }
197 197
 
198
-    public static function error($code=500,$message='Application Error'){
198
+    public static function error($code=500,$message='Application Error') {
199 199
         Event::trigger('core.response.error',$code,$message);
200 200
         static::status($code,$message);
201 201
     }
202 202
 
203
-    public static function body($setBody=null){
204
-      if ($setBody) static::$payload = [$setBody];
203
+    public static function body($setBody=null) {
204
+      if ($setBody) {
205
+        static::$payload = [$setBody];
206
+      }
205 207
       return Filter::with('core.response.body',
206 208
                 is_array(static::$payload) ? implode('',static::$payload) : static::$payload
207 209
              );
208 210
     }
209 211
 
210
-    public static function headers($setHeaders=null){
211
-       if ($setHeaders) static::$headers = $setHeaders;
212
+    public static function headers($setHeaders=null) {
213
+       if ($setHeaders) {
214
+         static::$headers = $setHeaders;
215
+       }
212 216
        return static::$headers;
213 217
     }
214 218
 
@@ -219,7 +223,7 @@  discard block
 block discarded – undo
219 223
      *
220 224
      * @return array Headers and body of the response
221 225
      */
222
-    public static function save(){
226
+    public static function save() {
223 227
         return [
224 228
           'head' => static::$headers,
225 229
           'body' => static::body(),
@@ -233,27 +237,33 @@  discard block
 block discarded – undo
233 237
      *
234 238
      * @param  array $data head/body saved state
235 239
      */
236
-    public static function load($data){
240
+    public static function load($data) {
237 241
       $data = (object)$data;
238
-      if (isset($data->head)) static::headers($data->head);
239
-      if (isset($data->body)) static::body($data->body);
242
+      if (isset($data->head)) {
243
+        static::headers($data->head);
244
+      }
245
+      if (isset($data->body)) {
246
+        static::body($data->body);
247
+      }
240 248
     }
241 249
 
242
-    public static function send($force = false){
250
+    public static function send($force = false) {
243 251
       if (!static::$sent || $force) {
244 252
         static::$sent = true;
245 253
         Event::trigger('core.response.send');
246
-        if (false === headers_sent()) foreach (static::$headers as $name => $value_code) {
254
+        if (false === headers_sent()) {
255
+          foreach (static::$headers as $name => $value_code) {
247 256
 
248 257
             if (is_array($value_code)) {
249 258
                 list($value, $code) = (count($value_code) > 1) ? $value_code : [current($value_code), 200];
259
+        }
250 260
             } else {
251 261
                 $value = $value_code;
252 262
                 $code  = null;
253 263
             }
254 264
 
255
-            if ($value == 'Status'){
256
-              if (function_exists('http_response_code')){
265
+            if ($value == 'Status') {
266
+              if (function_exists('http_response_code')) {
257 267
                 http_response_code($code);
258 268
               } else {
259 269
                 header("Status: $code", true, $code);
@@ -265,7 +275,9 @@  discard block
 block discarded – undo
265 275
                 : header("$name: $value", true);
266 276
             }
267 277
         }
268
-        if (static::$force_dl) header('Content-Disposition: attachment; filename="'.static::$force_dl.'"');
278
+        if (static::$force_dl) {
279
+          header('Content-Disposition: attachment; filename="'.static::$force_dl.'"');
280
+        }
269 281
         echo static::body();
270 282
       }
271 283
     }
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.
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.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -13,128 +13,128 @@  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);
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 26
     // Obfuscate IDs
27 27
     ini_set('session.hash_function', 'whirlpool');
28
-		session_cache_limiter('must-revalidate');
29
-		@session_start();
30
-	}
31
-
32
-	/**
33
-	 * Get/Set Session name
34
-	 *
35
-	 * @access public
36
-	 * @static
37
-	 * @param string $key The session name
38
-	 * @return string The session value
39
-	 */
40
-	static public function name($name=null){
41
-		return $name ? session_name($name) : session_name();
42
-	}
43
-
44
-	/**
45
-	 * Get a session variable reference
46
-	 *
47
-	 * @access public
48
-	 * @static
49
-	 * @param mixed $key The variable name
50
-	 * @return mixed The variable value
51
-	 */
52
-	static public function get($key,$default=null){
28
+    session_cache_limiter('must-revalidate');
29
+    @session_start();
30
+  }
31
+
32
+  /**
33
+   * Get/Set Session name
34
+   *
35
+   * @access public
36
+   * @static
37
+   * @param string $key The session name
38
+   * @return string The session value
39
+   */
40
+  static public function name($name=null){
41
+    return $name ? session_name($name) : session_name();
42
+  }
43
+
44
+  /**
45
+   * Get a session variable reference
46
+   *
47
+   * @access public
48
+   * @static
49
+   * @param mixed $key The variable name
50
+   * @return mixed The variable value
51
+   */
52
+  static public function get($key,$default=null){
53 53
                 if (($active = static::active()) && isset($_SESSION[$key])) {
54
-			return $_SESSION[$key];
54
+      return $_SESSION[$key];
55 55
                 } else if ($active) {
56
-                	return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default);
56
+                  return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default);
57 57
                 } else {
58
-                 	return (is_callable($default)?call_user_func($default):$default);
58
+                    return (is_callable($default)?call_user_func($default):$default);
59 59
                 }
60
-	}
61
-
62
-	/**
63
-	 * Set a session variable
64
-	 *
65
-	 * @access public
66
-	 * @static
67
-	 * @param mixed $key The variable name
68
-	 * @param mixed $value The variable value
69
-	 * @return void
70
-	 */
71
-	static public function set($key,$value=null){
72
-		static::start();
73
-		if($value==null && is_array($key)){
74
-			foreach($key as $k=>$v) $_SESSION[$k]=$v;
75
-		} else {
76
-			$_SESSION[$key] = $value;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Delete a session variable
82
-	 *
83
-	 * @access public
84
-	 * @static
85
-	 * @param mixed $key The variable name
86
-	 * @return void
87
-	 */
88
-	static public function delete($key){
89
-		static::start();
90
-		unset($_SESSION[$key]);
91
-	}
92
-
93
-
94
-	/**
95
-	 * Delete all session variables
96
-	 *
97
-	 * @access public
98
-	 * @static
99
-	 * @return void
100
-	 */
101
-	static public function clear(){
102
-		static::start();
103
-		session_unset();
104
-		session_destroy();
105
-	}
106
-
107
-	/**
108
-	 * Check if session is active
109
-	 *
110
-	 * @access public
111
-	 * @static
112
-	 * @return void
113
-	 */
114
-	static public function active(){
115
-		return session_status() == PHP_SESSION_ACTIVE;
116
-	}
117
-
118
-	/**
119
-	 * Check if a session variable exists
120
-	 *
121
-	 * @access public
122
-	 * @static
123
-	 * @param mixed $key The variable name
124
-	 * @return bool
125
-	 */
126
-	static public function exists($key){
127
-		static::start();
128
-		return isset($_SESSION[$key]);
129
-	}
130
-
131
-	/**
132
-	 * Return a read-only accessor to session variables for in-view use.
133
-	 * @return SessionReadOnly
134
-	 */
135
-	static public function readOnly(){
136
-		return new SessionReadOnly;
137
-	}
60
+  }
61
+
62
+  /**
63
+   * Set a session variable
64
+   *
65
+   * @access public
66
+   * @static
67
+   * @param mixed $key The variable name
68
+   * @param mixed $value The variable value
69
+   * @return void
70
+   */
71
+  static public function set($key,$value=null){
72
+    static::start();
73
+    if($value==null && is_array($key)){
74
+      foreach($key as $k=>$v) $_SESSION[$k]=$v;
75
+    } else {
76
+      $_SESSION[$key] = $value;
77
+    }
78
+  }
79
+
80
+  /**
81
+   * Delete a session variable
82
+   *
83
+   * @access public
84
+   * @static
85
+   * @param mixed $key The variable name
86
+   * @return void
87
+   */
88
+  static public function delete($key){
89
+    static::start();
90
+    unset($_SESSION[$key]);
91
+  }
92
+
93
+
94
+  /**
95
+   * Delete all session variables
96
+   *
97
+   * @access public
98
+   * @static
99
+   * @return void
100
+   */
101
+  static public function clear(){
102
+    static::start();
103
+    session_unset();
104
+    session_destroy();
105
+  }
106
+
107
+  /**
108
+   * Check if session is active
109
+   *
110
+   * @access public
111
+   * @static
112
+   * @return void
113
+   */
114
+  static public function active(){
115
+    return session_status() == PHP_SESSION_ACTIVE;
116
+  }
117
+
118
+  /**
119
+   * Check if a session variable exists
120
+   *
121
+   * @access public
122
+   * @static
123
+   * @param mixed $key The variable name
124
+   * @return bool
125
+   */
126
+  static public function exists($key){
127
+    static::start();
128
+    return isset($_SESSION[$key]);
129
+  }
130
+
131
+  /**
132
+   * Return a read-only accessor to session variables for in-view use.
133
+   * @return SessionReadOnly
134
+   */
135
+  static public function readOnly(){
136
+    return new SessionReadOnly;
137
+  }
138 138
 
139 139
 }  /* End of class */
140 140
 
@@ -146,36 +146,36 @@  discard block
 block discarded – undo
146 146
 
147 147
 class SessionReadOnly {
148 148
 
149
-	/**
150
-	 * Get a session variable reference
151
-	 *
152
-	 * @access public
153
-	 * @param mixed $key The variable name
154
-	 * @return mixed The variable value
155
-	 */
156
-	public function get($key){
157
-		return Session::get($key);
158
-	}
159
-	public function __get($key){
160
-		return Session::get($key);
161
-	}
162
-
163
-	public function name(){
164
-		return Session::name();
165
-	}
166
-
167
-	/**
168
-	 * Check if a session variable exists
169
-	 *
170
-	 * @access public
171
-	 * @param mixed $key The variable name
172
-	 * @return bool
173
-	 */
174
-	public function exists($key){
175
-		return Session::exists($key);
176
-	}
177
-	public function __isset($key){
178
-		return Session::exists($key);
179
-	}
149
+  /**
150
+   * Get a session variable reference
151
+   *
152
+   * @access public
153
+   * @param mixed $key The variable name
154
+   * @return mixed The variable value
155
+   */
156
+  public function get($key){
157
+    return Session::get($key);
158
+  }
159
+  public function __get($key){
160
+    return Session::get($key);
161
+  }
162
+
163
+  public function name(){
164
+    return Session::name();
165
+  }
166
+
167
+  /**
168
+   * Check if a session variable exists
169
+   *
170
+   * @access public
171
+   * @param mixed $key The variable name
172
+   * @return bool
173
+   */
174
+  public function exists($key){
175
+    return Session::exists($key);
176
+  }
177
+  public function __isset($key){
178
+    return Session::exists($key);
179
+  }
180 180
 
181 181
 }  /* End of class */
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   +94 added lines, -42 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,89 +72,123 @@  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
-      if (empty($this->attachments)) $this->compiled_head = null;
141
+      if (empty($this->attachments)) {
142
+        $this->compiled_head = null;
143
+      }
110 144
       $this->compiled_body = null;
111 145
       $this->contentType = $value;
112
-    } else if ($value===false) $this->contentType = '';
146
+    } else if ($value===false) {
147
+      $this->contentType = '';
148
+    }
113 149
     return $this->contentType;
114 150
   }
115 151
 
116
-  public function message($value=null){
152
+  public function message($value=null) {
117 153
     if ($value!==null && $value) {
118 154
       $this->compiled_body = null;
119 155
       $this->message = $value;
120
-    } else if ($value===false) $this->message = '';
156
+    } else if ($value===false) {
157
+      $this->message = '';
158
+    }
121 159
     return $this->message;
122 160
   }
123 161
 
124
-  public function attach($file){
162
+  public function attach($file) {
125 163
     $this->compiled_body = null;
126 164
     if (isset($file->content) || isset($file['content'])) {
127 165
       $this->attachments[] = $file;
128
-    } else foreach ((array)$file as $curfile) {
166
+    } else {
167
+      foreach ((array)$file as $curfile) {
129 168
       $this->attachments[] = $curfile;
130 169
     }
170
+    }
131 171
   }
132 172
 
133
-  public function head($recompile = false){
134
-    if ($recompile || (null === $this->compiled_head)){
173
+  public function head($recompile = false) {
174
+    if ($recompile || (null === $this->compiled_head)) {
135 175
       $head   = [];
136 176
       $head[] = "Subject: {$this->subject}";
137
-      if($this->from)                        $head[] = "From: {$this->from}";
138
-      if(is_array($this->to)  && !empty($this->to))  $head[] = "To: "  . implode(', ',$this->to);
139
-      if(is_array($this->cc)  && !empty($this->cc))  $head[] = "Cc: "  . implode(', ',$this->cc);
140
-      if(is_array($this->bcc) && !empty($this->bcc)) $head[] = "Bcc: " . implode(', ',$this->bcc);
141
-      if($this->replyTo)                     $head[] = "Reply-To: {$this->replyTo}";
177
+      if($this->from) {
178
+        $head[] = "From: {$this->from}";
179
+      }
180
+      if(is_array($this->to)  && !empty($this->to)) {
181
+        $head[] = "To: "  . implode(', ',$this->to);
182
+      }
183
+      if(is_array($this->cc)  && !empty($this->cc)) {
184
+        $head[] = "Cc: "  . implode(', ',$this->cc);
185
+      }
186
+      if(is_array($this->bcc) && !empty($this->bcc)) {
187
+        $head[] = "Bcc: " . implode(', ',$this->bcc);
188
+      }
189
+      if($this->replyTo) {
190
+        $head[] = "Reply-To: {$this->replyTo}";
191
+      }
142 192
       $head[] = 'MIME-Version: 1.0';
143 193
       if (!empty($this->attachments)) {
144 194
         $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->uid}\"";
@@ -151,8 +201,8 @@  discard block
 block discarded – undo
151 201
     return \Filter::with( 'core.email.source.head', $this->compiled_head);
152 202
   }
153 203
 
154
-  public function body($recompile = false){
155
-    if ($recompile || (null === $this->compiled_body)){
204
+  public function body($recompile = false) {
205
+    if ($recompile || (null === $this->compiled_body)) {
156 206
       if (!empty($this->attachments)) {
157 207
         $body[] = "--{$this->uid}";
158 208
         $body[] = "Content-Type: {$this->contentType}";
@@ -162,10 +212,12 @@  discard block
 block discarded – undo
162 212
       $body[] = quoted_printable_encode($this->message);
163 213
       $body[] = '';
164 214
 
165
-      if (!empty($this->attachments)) foreach ((array)$this->attachments as $file) {
215
+      if (!empty($this->attachments)) {
216
+        foreach ((array)$this->attachments as $file) {
166 217
 
167 218
         if (is_string($file)) {
168 219
           $name = basename($file);
220
+      }
169 221
           $data = file_get_contents($file);
170 222
         } else {
171 223
           $name = isset($file['name'])    ? $file['name']    : 'untitled';
@@ -187,7 +239,7 @@  discard block
 block discarded – undo
187 239
     return \Filter::with( 'core.email.source.body', $this->compiled_body);
188 240
   }
189 241
 
190
-  public function build(){
242
+  public function build() {
191 243
     return \Filter::with( 'core.email.source', $this->head() . "\r\n" . $this->body() );
192 244
   }
193 245
 
Please login to merge, or discard this patch.
classes/HTTP.php 4 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.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@
 block discarded – undo
14 14
   use Module;
15 15
 
16 16
   protected static $UA          = "Mozilla/4.0 (compatible; Core::HTTP; Windows NT 6.1)",
17
-                   $json_data   = false,
18
-                   $headers     = [],
19
-                   $last_info   = null;
17
+                    $json_data   = false,
18
+                    $headers     = [],
19
+                    $last_info   = null;
20 20
 
21 21
   protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){
22 22
     $http_method = strtoupper($method);
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
                    $headers     = [],
19 19
                    $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) {
36
+    if ($username && $password) {
37 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
           $opt[CURLOPT_HTTPGET]      = true;
51 51
           unset($opt[CURLOPT_CUSTOMREQUEST]);
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 {
@@ -60,59 +60,59 @@  discard block
 block discarded – undo
60 60
         }
61 61
     }
62 62
 
63
-    curl_setopt_array($ch,$opt);
63
+    curl_setopt_array($ch, $opt);
64 64
     $_harr = [];
65
-    foreach($headers as $key=>$val)  $_harr[] = $key.': '.$val;
65
+    foreach ($headers as $key=>$val)  $_harr[] = $key.': '.$val;
66 66
     curl_setopt($ch, CURLOPT_HTTPHEADER, $_harr);
67 67
     $result = curl_exec($ch);
68 68
     $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
69 69
     static::$last_info = curl_getinfo($ch);
70
-    if(false !== strpos($contentType,'json')) $result = json_decode($result);
70
+    if (false !== strpos($contentType, 'json')) $result = json_decode($result);
71 71
     curl_close($ch);
72 72
     return $result;
73 73
   }
74 74
 
75
-  public static function useJSON($value=null){
76
-    return $value===null ? static::$json_data : static::$json_data = $value;
75
+  public static function useJSON($value = null) {
76
+    return $value === null ? static::$json_data : static::$json_data = $value;
77 77
   }
78 78
 
79
-  public static function addHeader($name,$value){
79
+  public static function addHeader($name, $value) {
80 80
     static::$headers[$name] = $value;
81 81
   }
82 82
 
83
-  public static function removeHeader($name){
83
+  public static function removeHeader($name) {
84 84
     unset(static::$headers[$name]);
85 85
   }
86 86
 
87
-  public static function headers($name=null){
87
+  public static function headers($name = null) {
88 88
     // null === $name ?? static::$headers ?? static::$headers[$name]
89 89
     return null === $name
90 90
            ? static::$headers
91
-           : ( isset(static::$headers[$name]) ? static::$headers[$name] : '' );
91
+           : (isset(static::$headers[$name]) ? static::$headers[$name] : '');
92 92
   }
93 93
 
94
-  public static function userAgent($value=null){
95
-    return $value===null ? static::$UA : static::$UA = $value;
94
+  public static function userAgent($value = null) {
95
+    return $value === null ? static::$UA : static::$UA = $value;
96 96
   }
97 97
 
98
-  public static function get($url, $data=null, array $headers=[], $username = null, $password = null){
99
-    return static::request('get',$url,$data,$headers,false,$username,$password);
98
+  public static function get($url, $data = null, array $headers = [], $username = null, $password = null) {
99
+    return static::request('get', $url, $data, $headers, false, $username, $password);
100 100
   }
101 101
 
102
-  public static function post($url, $data=null, array $headers=[], $username = null, $password = null){
103
-    return static::request('post',$url,$data,$headers,static::$json_data,$username,$password);
102
+  public static function post($url, $data = null, array $headers = [], $username = null, $password = null) {
103
+    return static::request('post', $url, $data, $headers, static::$json_data, $username, $password);
104 104
   }
105 105
 
106
-  public static function put($url, $data=null, array $headers=[], $username = null, $password = null){
107
-    return static::request('put',$url,$data,$headers,static::$json_data,$username,$password);
106
+  public static function put($url, $data = null, array $headers = [], $username = null, $password = null) {
107
+    return static::request('put', $url, $data, $headers, static::$json_data, $username, $password);
108 108
   }
109 109
 
110
-  public static function delete($url, $data=null, array $headers=[], $username = null, $password = null){
111
-    return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password);
110
+  public static function delete($url, $data = null, array $headers = [], $username = null, $password = null) {
111
+    return static::request('delete', $url, $data, $headers, static::$json_data, $username, $password);
112 112
   }
113 113
 
114
-  public static function info($url = null){
115
-    if ($url){
114
+  public static function info($url = null) {
115
+    if ($url) {
116 116
       curl_setopt_array($ch = curl_init($url), [
117 117
         CURLOPT_SSL_VERIFYHOST  => false,
118 118
         CURLOPT_CONNECTTIMEOUT  => 10,
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
                    $headers     = [],
19 19
                    $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 {
@@ -67,52 +67,54 @@  discard block
 block discarded – undo
67 67
     $result = curl_exec($ch);
68 68
     $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
69 69
     static::$last_info = curl_getinfo($ch);
70
-    if(false !== strpos($contentType,'json')) $result = json_decode($result);
70
+    if(false !== strpos($contentType,'json')) {
71
+      $result = json_decode($result);
72
+    }
71 73
     curl_close($ch);
72 74
     return $result;
73 75
   }
74 76
 
75
-  public static function useJSON($value=null){
77
+  public static function useJSON($value=null) {
76 78
     return $value===null ? static::$json_data : static::$json_data = $value;
77 79
   }
78 80
 
79
-  public static function addHeader($name,$value){
81
+  public static function addHeader($name,$value) {
80 82
     static::$headers[$name] = $value;
81 83
   }
82 84
 
83
-  public static function removeHeader($name){
85
+  public static function removeHeader($name) {
84 86
     unset(static::$headers[$name]);
85 87
   }
86 88
 
87
-  public static function headers($name=null){
89
+  public static function headers($name=null) {
88 90
     // null === $name ?? static::$headers ?? static::$headers[$name]
89 91
     return null === $name
90 92
            ? static::$headers
91 93
            : ( isset(static::$headers[$name]) ? static::$headers[$name] : '' );
92 94
   }
93 95
 
94
-  public static function userAgent($value=null){
96
+  public static function userAgent($value=null) {
95 97
     return $value===null ? static::$UA : static::$UA = $value;
96 98
   }
97 99
 
98
-  public static function get($url, $data=null, array $headers=[], $username = null, $password = null){
100
+  public static function get($url, $data=null, array $headers=[], $username = null, $password = null) {
99 101
     return static::request('get',$url,$data,$headers,false,$username,$password);
100 102
   }
101 103
 
102
-  public static function post($url, $data=null, array $headers=[], $username = null, $password = null){
104
+  public static function post($url, $data=null, array $headers=[], $username = null, $password = null) {
103 105
     return static::request('post',$url,$data,$headers,static::$json_data,$username,$password);
104 106
   }
105 107
 
106
-  public static function put($url, $data=null, array $headers=[], $username = null, $password = null){
108
+  public static function put($url, $data=null, array $headers=[], $username = null, $password = null) {
107 109
     return static::request('put',$url,$data,$headers,static::$json_data,$username,$password);
108 110
   }
109 111
 
110
-  public static function delete($url, $data=null, array $headers=[], $username = null, $password = null){
112
+  public static function delete($url, $data=null, array $headers=[], $username = null, $password = null) {
111 113
     return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password);
112 114
   }
113 115
 
114
-  public static function info($url = null){
115
-    if ($url){
116
+  public static function info($url = null) {
117
+    if ($url) {
116 118
       curl_setopt_array($ch = curl_init($url), [
117 119
         CURLOPT_SSL_VERIFYHOST  => false,
118 120
         CURLOPT_CONNECTTIMEOUT  => 10,
Please login to merge, or discard this patch.