@@ -65,7 +65,7 @@ |
||
| 65 | 65 | 'numeric' => 'The {0} must be a number.', |
| 66 | 66 | 'regex' => 'The {0} format is invalid.', |
| 67 | 67 | 'required' => 'The {0} field is required.', |
| 68 | - 'same' => 'The {0} and {1} must match.', |
|
| 68 | + 'same' => 'The {0} and {1} must match.', |
|
| 69 | 69 | 'size' => [ |
| 70 | 70 | 'numeric' => 'The {0} must be {1}.', |
| 71 | 71 | 'file' => 'The {0} must be {1} kilobytes.', |
@@ -30,8 +30,8 @@ |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function is($route) { |
| 33 | - return Str::contains($this->current(), $route); |
|
| 34 | - } |
|
| 33 | + return Str::contains($this->current(), $route); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | public function currentRouteName() { |
| 37 | 37 | return $this->getRoutes()[$this->current()][0][$this->type()][3]; |
@@ -73,22 +73,22 @@ discard block |
||
| 73 | 73 | public function verify($code) { |
| 74 | 74 | $this->startSession(); |
| 75 | 75 | |
| 76 | - $n = $this->name; |
|
| 76 | + $n = $this->name; |
|
| 77 | 77 | |
| 78 | - $valid = isset($_SESSION[$n]) |
|
| 79 | - && isset($_POST[$n]) |
|
| 80 | - && strlen($_POST[$n]) |
|
| 81 | - && ($_SESSION[$n] === crypt(strtolower($_POST[$n]), $this->salt())); |
|
| 78 | + $valid = isset($_SESSION[$n]) |
|
| 79 | + && isset($_POST[$n]) |
|
| 80 | + && strlen($_POST[$n]) |
|
| 81 | + && ($_SESSION[$n] === crypt(strtolower($_POST[$n]), $this->salt())); |
|
| 82 | 82 | |
| 83 | - if (isset($_POST[$n])) { |
|
| 84 | - unset($_POST[$n]); |
|
| 85 | - } |
|
| 83 | + if (isset($_POST[$n])) { |
|
| 84 | + unset($_POST[$n]); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if ($valid && isset($_SESSION[$n])) { |
|
| 88 | - unset($_SESSION[$n]); |
|
| 89 | - } |
|
| 87 | + if ($valid && isset($_SESSION[$n])) { |
|
| 88 | + unset($_SESSION[$n]); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $valid; |
|
| 91 | + return $valid; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | private function startSession() { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | private function setSession($string) { |
| 99 | 99 | $this->startSession(); |
| 100 | - $_SESSION[$this->name] = crypt(strtolower($string), $this->salt()); |
|
| 100 | + $_SESSION[$this->name] = crypt(strtolower($string), $this->salt()); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | private function _generate($length) { |
@@ -105,6 +105,6 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | private static function salt() { |
| 108 | - return md5(__FILE__.filemtime(__FILE__)); |
|
| 109 | - } |
|
| 108 | + return md5(__FILE__.filemtime(__FILE__)); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |
@@ -2,233 +2,233 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Str extends Prefab { |
| 4 | 4 | protected static $snakeCache = []; |
| 5 | - protected static $camelCache = []; |
|
| 6 | - protected static $studlyCache = []; |
|
| 5 | + protected static $camelCache = []; |
|
| 6 | + protected static $studlyCache = []; |
|
| 7 | 7 | |
| 8 | 8 | public static function after($subject, $search) { |
| 9 | - return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; |
|
| 10 | - } |
|
| 9 | + return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public static function before($subject, $search) { |
|
| 13 | - return $search === '' ? $subject : explode($search, $subject)[0]; |
|
| 14 | - } |
|
| 12 | + public static function before($subject, $search) { |
|
| 13 | + return $search === '' ? $subject : explode($search, $subject)[0]; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public static function camel($value) { |
|
| 17 | - if (isset(static::$camelCache[$value])) { |
|
| 18 | - return static::$camelCache[$value]; |
|
| 19 | - } |
|
| 16 | + public static function camel($value) { |
|
| 17 | + if (isset(static::$camelCache[$value])) { |
|
| 18 | + return static::$camelCache[$value]; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - return static::$camelCache[$value] = lcfirst(static::studly($value)); |
|
| 22 | - } |
|
| 21 | + return static::$camelCache[$value] = lcfirst(static::studly($value)); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public static function contains($haystack, $needles) { |
|
| 25 | - foreach ((array) $needles as $needle) { |
|
| 26 | - if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { |
|
| 27 | - return true; |
|
| 28 | - } |
|
| 29 | - } |
|
| 24 | + public static function contains($haystack, $needles) { |
|
| 25 | + foreach ((array) $needles as $needle) { |
|
| 26 | + if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { |
|
| 27 | + return true; |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return false; |
|
| 32 | - } |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public static function endsWith($haystack, $needles) { |
|
| 35 | - foreach ((array) $needles as $needle) { |
|
| 36 | - if (substr($haystack, -strlen($needle)) === (string) $needle) { |
|
| 37 | - return true; |
|
| 38 | - } |
|
| 39 | - } |
|
| 34 | + public static function endsWith($haystack, $needles) { |
|
| 35 | + foreach ((array) $needles as $needle) { |
|
| 36 | + if (substr($haystack, -strlen($needle)) === (string) $needle) { |
|
| 37 | + return true; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return false; |
|
| 42 | - } |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public static function finish($value, $cap) { |
|
| 45 | - $quoted = preg_quote($cap, '/'); |
|
| 44 | + public static function finish($value, $cap) { |
|
| 45 | + $quoted = preg_quote($cap, '/'); |
|
| 46 | 46 | |
| 47 | - return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; |
|
| 48 | - } |
|
| 47 | + return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public static function is($pattern, $value) { |
|
| 51 | - $patterns = is_array($pattern) ? $pattern : (array) $pattern; |
|
| 50 | + public static function is($pattern, $value) { |
|
| 51 | + $patterns = is_array($pattern) ? $pattern : (array) $pattern; |
|
| 52 | 52 | |
| 53 | - if (empty($patterns)) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 53 | + if (empty($patterns)) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - foreach ($patterns as $pattern) { |
|
| 58 | - if ($pattern == $value) { |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 57 | + foreach ($patterns as $pattern) { |
|
| 58 | + if ($pattern == $value) { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $pattern = preg_quote($pattern, '#'); |
|
| 63 | - $pattern = str_replace('\*', '.*', $pattern); |
|
| 62 | + $pattern = preg_quote($pattern, '#'); |
|
| 63 | + $pattern = str_replace('\*', '.*', $pattern); |
|
| 64 | 64 | |
| 65 | - if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 68 | - } |
|
| 65 | + if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - return false; |
|
| 71 | - } |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public static function kebab($value) { |
|
| 74 | - return static::snake($value, '-'); |
|
| 75 | - } |
|
| 73 | + public static function kebab($value) { |
|
| 74 | + return static::snake($value, '-'); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public static function length($value, $encoding = null) { |
|
| 78 | - if ($encoding) { |
|
| 79 | - return mb_strlen($value, $encoding); |
|
| 80 | - } |
|
| 77 | + public static function length($value, $encoding = null) { |
|
| 78 | + if ($encoding) { |
|
| 79 | + return mb_strlen($value, $encoding); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return mb_strlen($value); |
|
| 83 | - } |
|
| 82 | + return mb_strlen($value); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public static function limit($value, $limit = 100, $end = '...') { |
|
| 86 | - if (mb_strwidth($value, 'UTF-8') <= $limit) { |
|
| 87 | - return $value; |
|
| 88 | - } |
|
| 85 | + public static function limit($value, $limit = 100, $end = '...') { |
|
| 86 | + if (mb_strwidth($value, 'UTF-8') <= $limit) { |
|
| 87 | + return $value; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; |
|
| 91 | - } |
|
| 90 | + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public static function lower($value) { |
|
| 94 | - return mb_strtolower($value, 'UTF-8'); |
|
| 95 | - } |
|
| 93 | + public static function lower($value) { |
|
| 94 | + return mb_strtolower($value, 'UTF-8'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public static function words($value, $words = 100, $end = '...') { |
|
| 98 | - preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
|
| 97 | + public static function words($value, $words = 100, $end = '...') { |
|
| 98 | + preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
|
| 99 | 99 | |
| 100 | - if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
|
| 101 | - return $value; |
|
| 102 | - } |
|
| 100 | + if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
|
| 101 | + return $value; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return rtrim($matches[0]).$end; |
|
| 105 | - } |
|
| 104 | + return rtrim($matches[0]).$end; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public static function parseCallback($callback, $default = null) { |
|
| 108 | - return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
|
| 109 | - } |
|
| 107 | + public static function parseCallback($callback, $default = null) { |
|
| 108 | + return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public static function plural($value, $count = 2) { |
|
| 112 | - return Pluralizer::plural($value, $count); |
|
| 113 | - } |
|
| 111 | + public static function plural($value, $count = 2) { |
|
| 112 | + return Pluralizer::plural($value, $count); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - public static function random($length = 16) { |
|
| 116 | - $string = ''; |
|
| 115 | + public static function random($length = 16) { |
|
| 116 | + $string = ''; |
|
| 117 | 117 | |
| 118 | - while (($len = strlen($string)) < $length) { |
|
| 119 | - $size = $length - $len; |
|
| 120 | - $bytes = random_bytes($size); |
|
| 121 | - $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
| 122 | - } |
|
| 118 | + while (($len = strlen($string)) < $length) { |
|
| 119 | + $size = $length - $len; |
|
| 120 | + $bytes = random_bytes($size); |
|
| 121 | + $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - return $string; |
|
| 125 | - } |
|
| 124 | + return $string; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - public static function replaceArray($search, array $replace, $subject) { |
|
| 128 | - foreach ($replace as $value) { |
|
| 129 | - $subject = static::replaceFirst($search, $value, $subject); |
|
| 130 | - } |
|
| 127 | + public static function replaceArray($search, array $replace, $subject) { |
|
| 128 | + foreach ($replace as $value) { |
|
| 129 | + $subject = static::replaceFirst($search, $value, $subject); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - return $subject; |
|
| 133 | - } |
|
| 132 | + return $subject; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - public static function replaceFirst($search, $replace, $subject) { |
|
| 136 | - if ($search == '') { |
|
| 137 | - return $subject; |
|
| 138 | - } |
|
| 135 | + public static function replaceFirst($search, $replace, $subject) { |
|
| 136 | + if ($search == '') { |
|
| 137 | + return $subject; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - $position = strpos($subject, $search); |
|
| 140 | + $position = strpos($subject, $search); |
|
| 141 | 141 | |
| 142 | - if ($position !== false) { |
|
| 143 | - return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 144 | - } |
|
| 142 | + if ($position !== false) { |
|
| 143 | + return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return $subject; |
|
| 147 | - } |
|
| 146 | + return $subject; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - public static function replaceLast($search, $replace, $subject) { |
|
| 150 | - $position = strrpos($subject, $search); |
|
| 149 | + public static function replaceLast($search, $replace, $subject) { |
|
| 150 | + $position = strrpos($subject, $search); |
|
| 151 | 151 | |
| 152 | - if ($position !== false) { |
|
| 153 | - return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 154 | - } |
|
| 152 | + if ($position !== false) { |
|
| 153 | + return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $subject; |
|
| 157 | - } |
|
| 156 | + return $subject; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public static function start($value, $prefix) { |
|
| 160 | - $quoted = preg_quote($prefix, '/'); |
|
| 161 | - return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); |
|
| 162 | - } |
|
| 159 | + public static function start($value, $prefix) { |
|
| 160 | + $quoted = preg_quote($prefix, '/'); |
|
| 161 | + return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - public static function upper($value) { |
|
| 165 | - return mb_strtoupper($value, 'UTF-8'); |
|
| 166 | - } |
|
| 164 | + public static function upper($value) { |
|
| 165 | + return mb_strtoupper($value, 'UTF-8'); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - public static function title($value) { |
|
| 169 | - return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); |
|
| 170 | - } |
|
| 168 | + public static function title($value) { |
|
| 169 | + return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - public static function singular($value) { |
|
| 173 | - return Pluralizer::singular($value); |
|
| 174 | - } |
|
| 172 | + public static function singular($value) { |
|
| 173 | + return Pluralizer::singular($value); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - public static function slug($title, $separator = '-', $language = 'en') { |
|
| 177 | - $title = static::ascii($title, $language); |
|
| 176 | + public static function slug($title, $separator = '-', $language = 'en') { |
|
| 177 | + $title = static::ascii($title, $language); |
|
| 178 | 178 | |
| 179 | - $flip = $separator == '-' ? '_' : '-'; |
|
| 179 | + $flip = $separator == '-' ? '_' : '-'; |
|
| 180 | 180 | |
| 181 | - $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
|
| 182 | - $title = str_replace('@', $separator.'at'.$separator, $title); |
|
| 183 | - $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
| 184 | - $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); |
|
| 181 | + $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
|
| 182 | + $title = str_replace('@', $separator.'at'.$separator, $title); |
|
| 183 | + $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
| 184 | + $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); |
|
| 185 | 185 | |
| 186 | - return trim($title, $separator); |
|
| 187 | - } |
|
| 186 | + return trim($title, $separator); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - public static function snake($value, $delimiter = '_') { |
|
| 190 | - $key = $value; |
|
| 189 | + public static function snake($value, $delimiter = '_') { |
|
| 190 | + $key = $value; |
|
| 191 | 191 | |
| 192 | - if (isset(static::$snakeCache[$key][$delimiter])) { |
|
| 193 | - return static::$snakeCache[$key][$delimiter]; |
|
| 194 | - } |
|
| 192 | + if (isset(static::$snakeCache[$key][$delimiter])) { |
|
| 193 | + return static::$snakeCache[$key][$delimiter]; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - if (! ctype_lower($value)) { |
|
| 197 | - $value = preg_replace('/\s+/u', '', ucwords($value)); |
|
| 196 | + if (! ctype_lower($value)) { |
|
| 197 | + $value = preg_replace('/\s+/u', '', ucwords($value)); |
|
| 198 | 198 | |
| 199 | - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
| 200 | - } |
|
| 199 | + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return static::$snakeCache[$key][$delimiter] = $value; |
|
| 203 | - } |
|
| 202 | + return static::$snakeCache[$key][$delimiter] = $value; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - public static function startsWith($haystack, $needles) { |
|
| 206 | - foreach ((array) $needles as $needle) { |
|
| 207 | - if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) { |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - } |
|
| 205 | + public static function startsWith($haystack, $needles) { |
|
| 206 | + foreach ((array) $needles as $needle) { |
|
| 207 | + if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - return false; |
|
| 213 | - } |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - public static function studly($value) { |
|
| 216 | - $key = $value; |
|
| 215 | + public static function studly($value) { |
|
| 216 | + $key = $value; |
|
| 217 | 217 | |
| 218 | - if (isset(static::$studlyCache[$key])) { |
|
| 219 | - return static::$studlyCache[$key]; |
|
| 220 | - } |
|
| 218 | + if (isset(static::$studlyCache[$key])) { |
|
| 219 | + return static::$studlyCache[$key]; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
| 222 | + $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
| 223 | 223 | |
| 224 | - return static::$studlyCache[$key] = str_replace(' ', '', $value); |
|
| 225 | - } |
|
| 224 | + return static::$studlyCache[$key] = str_replace(' ', '', $value); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - public static function substr($string, $start, $length = null) { |
|
| 228 | - return mb_substr($string, $start, $length, 'UTF-8'); |
|
| 229 | - } |
|
| 227 | + public static function substr($string, $start, $length = null) { |
|
| 228 | + return mb_substr($string, $start, $length, 'UTF-8'); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - public static function ucfirst($string) { |
|
| 232 | - return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); |
|
| 233 | - } |
|
| 231 | + public static function ucfirst($string) { |
|
| 232 | + return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | \ No newline at end of file |
@@ -1,145 +1,145 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class App extends Prefab{ |
| 4 | - public $db; |
|
| 4 | + public $db; |
|
| 5 | 5 | public $app; |
| 6 | - public $session; |
|
| 7 | - public $authenticatedUser; |
|
| 6 | + public $session; |
|
| 7 | + public $authenticatedUser; |
|
| 8 | 8 | |
| 9 | 9 | public function __construct() { |
| 10 | - $this->app = $this->app ?: Base::instance(); |
|
| 10 | + $this->app = $this->app ?: Base::instance(); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - static public function singleton() { |
|
| 14 | - if (Registry::exists('APP')) |
|
| 15 | - $app = Registry::get('APP'); |
|
| 16 | - else { |
|
| 17 | - $app = new self; |
|
| 18 | - Registry::set('APP',$app); |
|
| 19 | - } |
|
| 20 | - return $app; |
|
| 21 | - } |
|
| 13 | + static public function singleton() { |
|
| 14 | + if (Registry::exists('APP')) |
|
| 15 | + $app = Registry::get('APP'); |
|
| 16 | + else { |
|
| 17 | + $app = new self; |
|
| 18 | + Registry::set('APP',$app); |
|
| 19 | + } |
|
| 20 | + return $app; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function db() { |
|
| 24 | - return $this->db ?: $this->app->DB; |
|
| 25 | - } |
|
| 23 | + public function db() { |
|
| 24 | + return $this->db ?: $this->app->DB; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function session() { |
|
| 28 | - return $this->session ?: $this->app->SESSION; |
|
| 29 | - } |
|
| 27 | + public function session() { |
|
| 28 | + return $this->session ?: $this->app->SESSION; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | public function user() { |
| 32 | 32 | return $this->authenticatedUser = $this->app->get('SESSION.USER')?:false; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function initialized($def = null) { |
|
| 36 | - return null !== $def ? $this->app->set('INITIALIZED', $def) : $this->app->get('INITIALIZED'); |
|
| 37 | - } |
|
| 35 | + public function initialized($def = null) { |
|
| 36 | + return null !== $def ? $this->app->set('INITIALIZED', $def) : $this->app->get('INITIALIZED'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function config($key = null) { |
|
| 40 | - return $this->app->get($key?:'CONFIG') ; |
|
| 41 | - } |
|
| 39 | + public function config($key = null) { |
|
| 40 | + return $this->app->get($key?:'CONFIG') ; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function status() { |
|
| 44 | - return $this->app->IS_LIVE; |
|
| 45 | - } |
|
| 43 | + public function status() { |
|
| 44 | + return $this->app->IS_LIVE; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function run() { |
|
| 48 | - $this->loadConfig(); |
|
| 49 | - $this->loadRoutes(); |
|
| 50 | - $this->checkForMaintenance(); |
|
| 51 | - $this->configureDebug(); |
|
| 52 | - $this->configureDB(); |
|
| 53 | - $this->configureSession(); |
|
| 54 | - $this->configureAssets(); |
|
| 47 | + public function run() { |
|
| 48 | + $this->loadConfig(); |
|
| 49 | + $this->loadRoutes(); |
|
| 50 | + $this->checkForMaintenance(); |
|
| 51 | + $this->configureDebug(); |
|
| 52 | + $this->configureDB(); |
|
| 53 | + $this->configureSession(); |
|
| 54 | + $this->configureAssets(); |
|
| 55 | 55 | $this->registerErrorHandler(); |
| 56 | - $this->initialized(true); |
|
| 56 | + $this->initialized(true); |
|
| 57 | 57 | $this->app->run(); |
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function loadRoutes($file = null){ |
|
| 61 | - $this->_load('routes', $file); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function loadConfig($file = null){ |
|
| 65 | - $this->_load('config', $file); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - private function _load($path, $file = null) { |
|
| 69 | - if($file) { |
|
| 70 | - $this->app->config(base_path("{path}/{$file}")); |
|
| 71 | - }else{ |
|
| 72 | - foreach(glob(base_path("{$path}/*.ini")) as $file) { |
|
| 73 | - $this->app->config($file); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function loadRoutes($file = null){ |
|
| 61 | + $this->_load('routes', $file); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function loadConfig($file = null){ |
|
| 65 | + $this->_load('config', $file); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + private function _load($path, $file = null) { |
|
| 69 | + if($file) { |
|
| 70 | + $this->app->config(base_path("{path}/{$file}")); |
|
| 71 | + }else{ |
|
| 72 | + foreach(glob(base_path("{$path}/*.ini")) as $file) { |
|
| 73 | + $this->app->config($file); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | public function checkForMaintenance() { |
| 79 | 79 | if(!$this->status()) { |
| 80 | - template('maintenance'); |
|
| 81 | - exit(); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function configureDebug() { |
|
| 86 | - if(!$this->app->DEV) { |
|
| 87 | - $this->app->set('DEBUG', 0); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function configureDB() { |
|
| 92 | - $type = strtolower($this->app->DB_TYPE); |
|
| 93 | - |
|
| 94 | - if($type == 'jig'){ |
|
| 95 | - $this->db = new DB\Jig($this->app->DB_PATH, DB\Jig::FORMAT_JSON); |
|
| 96 | - }else if($type == 'sql'){ |
|
| 97 | - $this->db = new DB\SQL($this->app->DB, $this->app->DB_USER, $this->app->DB_PSWD); |
|
| 98 | - }else if($type == 'mongo'){ |
|
| 99 | - $this->db = new DB\Mongo($this->app->DB, $this->app->DB_USER); |
|
| 100 | - } |
|
| 101 | - $this->app->set('DB', $this->db); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function configureSession() { |
|
| 105 | - $type = strtolower($this->app->SESSION); |
|
| 106 | - |
|
| 107 | - if($type) { |
|
| 108 | - if($this->app->CSRF && ('jig' == $type || 'sql' == $type || 'mongo' == $type)) { |
|
| 109 | - $this->configureCSRF($type); |
|
| 110 | - }else if($this->app->CSRF){ |
|
| 111 | - $this->session = new Session(null, 'CSRF'); |
|
| 112 | - }else{ |
|
| 113 | - if($type == 'jig' || $type == 'mongo' || $type == 'sql'){ |
|
| 114 | - $session = str_ireplace('/', '', 'DB\/'.$this->_getDBType($type).'\Session'); |
|
| 115 | - $this->session = new $session($this->app->DB); |
|
| 116 | - }else{ |
|
| 117 | - $this->session = new Session(); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $this->app->set('SESSION', $this->session); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function configureCSRF($type) { |
|
| 125 | - $session = str_ireplace('/', '', 'DB\/'.$this->_getDBType($type).'\Session'); |
|
| 126 | - $this->session = new $session($this->app->DB, 'sessions', null, 'CSRF'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - private function _getDBType($type) { |
|
| 130 | - if($type == 'jig' || $type == 'mongo'){ |
|
| 131 | - return ucfirst($type); |
|
| 132 | - }else if($type == 'sql') { |
|
| 133 | - return strtoupper($type); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function configureAssets() { |
|
| 138 | - $assets = Assets::instance(); |
|
| 139 | - $this->app->set('ASSETS.onFileNotFound',function($file) { |
|
| 140 | - echo 'file not found: '.$file; |
|
| 141 | - }); |
|
| 142 | - } |
|
| 80 | + template('maintenance'); |
|
| 81 | + exit(); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function configureDebug() { |
|
| 86 | + if(!$this->app->DEV) { |
|
| 87 | + $this->app->set('DEBUG', 0); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function configureDB() { |
|
| 92 | + $type = strtolower($this->app->DB_TYPE); |
|
| 93 | + |
|
| 94 | + if($type == 'jig'){ |
|
| 95 | + $this->db = new DB\Jig($this->app->DB_PATH, DB\Jig::FORMAT_JSON); |
|
| 96 | + }else if($type == 'sql'){ |
|
| 97 | + $this->db = new DB\SQL($this->app->DB, $this->app->DB_USER, $this->app->DB_PSWD); |
|
| 98 | + }else if($type == 'mongo'){ |
|
| 99 | + $this->db = new DB\Mongo($this->app->DB, $this->app->DB_USER); |
|
| 100 | + } |
|
| 101 | + $this->app->set('DB', $this->db); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function configureSession() { |
|
| 105 | + $type = strtolower($this->app->SESSION); |
|
| 106 | + |
|
| 107 | + if($type) { |
|
| 108 | + if($this->app->CSRF && ('jig' == $type || 'sql' == $type || 'mongo' == $type)) { |
|
| 109 | + $this->configureCSRF($type); |
|
| 110 | + }else if($this->app->CSRF){ |
|
| 111 | + $this->session = new Session(null, 'CSRF'); |
|
| 112 | + }else{ |
|
| 113 | + if($type == 'jig' || $type == 'mongo' || $type == 'sql'){ |
|
| 114 | + $session = str_ireplace('/', '', 'DB\/'.$this->_getDBType($type).'\Session'); |
|
| 115 | + $this->session = new $session($this->app->DB); |
|
| 116 | + }else{ |
|
| 117 | + $this->session = new Session(); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $this->app->set('SESSION', $this->session); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function configureCSRF($type) { |
|
| 125 | + $session = str_ireplace('/', '', 'DB\/'.$this->_getDBType($type).'\Session'); |
|
| 126 | + $this->session = new $session($this->app->DB, 'sessions', null, 'CSRF'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + private function _getDBType($type) { |
|
| 130 | + if($type == 'jig' || $type == 'mongo'){ |
|
| 131 | + return ucfirst($type); |
|
| 132 | + }else if($type == 'sql') { |
|
| 133 | + return strtoupper($type); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function configureAssets() { |
|
| 138 | + $assets = Assets::instance(); |
|
| 139 | + $this->app->set('ASSETS.onFileNotFound',function($file) { |
|
| 140 | + echo 'file not found: '.$file; |
|
| 141 | + }); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | public function registerErrorHandler() { |
| 145 | 145 | if($this->app->DEV) { |