@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class Application |
| 13 | 13 | { |
| 14 | - private $container = []; |
|
| 14 | + private $container = []; |
|
| 15 | 15 | |
| 16 | - private static $instance; |
|
| 16 | + private static $instance; |
|
| 17 | 17 | |
| 18 | - public function __construct(File $file) |
|
| 19 | - { |
|
| 18 | + public function __construct(File $file) |
|
| 19 | + { |
|
| 20 | 20 | $this->handleErrors(); |
| 21 | 21 | |
| 22 | 22 | $this->share('file', $file); |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | $this->share('alias', $this->file->call($this->file->to('config/alias', '.php'))); |
| 27 | 27 | |
| 28 | 28 | $this->loadHelpers(); |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - private function handleErrors() { |
|
| 31 | + private function handleErrors() { |
|
| 32 | 32 | |
| 33 | 33 | $run = new Whoops(); |
| 34 | 34 | |
@@ -36,23 +36,23 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | if (WhoopsMisc::isAjaxRequest()) { |
| 38 | 38 | |
| 39 | - $jsonHandler = new JsonResponseHandler(); |
|
| 39 | + $jsonHandler = new JsonResponseHandler(); |
|
| 40 | 40 | |
| 41 | - $jsonHandler->setJsonApi(true); |
|
| 41 | + $jsonHandler->setJsonApi(true); |
|
| 42 | 42 | |
| 43 | - $run->prependHandler($jsonHandler); |
|
| 43 | + $run->prependHandler($jsonHandler); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $run->register(); |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public static function getInstance($file = null) |
|
| 50 | - { |
|
| 49 | + public static function getInstance($file = null) |
|
| 50 | + { |
|
| 51 | 51 | return static::$instance = is_null(static::$instance) ? new static($file) : static::$instance; |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function run() |
|
| 55 | - { |
|
| 54 | + public function run() |
|
| 55 | + { |
|
| 56 | 56 | $this->session->start(); |
| 57 | 57 | |
| 58 | 58 | $this->request->prepareUrl(); |
@@ -66,63 +66,63 @@ discard block |
||
| 66 | 66 | $this->response->setOutput($output); |
| 67 | 67 | |
| 68 | 68 | $this->response->send(); |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - private function loadHelpers() |
|
| 72 | - { |
|
| 71 | + private function loadHelpers() |
|
| 72 | + { |
|
| 73 | 73 | $helpers = $this->file->to('Core/helpers', '.php'); |
| 74 | 74 | |
| 75 | 75 | $this->file->call($helpers); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function coreClasses() |
|
| 79 | - { |
|
| 78 | + public function coreClasses() |
|
| 79 | + { |
|
| 80 | 80 | return $this->alias['classes']; |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function share($key, $value) |
|
| 84 | - { |
|
| 83 | + public function share($key, $value) |
|
| 84 | + { |
|
| 85 | 85 | if ($value instanceof Closure) $value = call_user_func($value, $this); |
| 86 | 86 | |
| 87 | 87 | $this->container[$key] = $value; |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function get($key) |
|
| 91 | - { |
|
| 90 | + public function get($key) |
|
| 91 | + { |
|
| 92 | 92 | if (! $this->isSharing($key)) { |
| 93 | 93 | |
| 94 | - if ($this->isCoreAlias($key)) { |
|
| 94 | + if ($this->isCoreAlias($key)) { |
|
| 95 | 95 | |
| 96 | 96 | $this->share($key, $this->createObject($key)); |
| 97 | 97 | |
| 98 | - } else { |
|
| 98 | + } else { |
|
| 99 | 99 | |
| 100 | 100 | throw new Exception("$key is not found"); |
| 101 | 101 | exit(); |
| 102 | - } |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | return $this->container[$key]; |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function isSharing($key) |
|
| 108 | - { |
|
| 107 | + public function isSharing($key) |
|
| 108 | + { |
|
| 109 | 109 | return isset($this->container[$key]); |
| 110 | - } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - public function isCoreAlias($key) |
|
| 113 | - { |
|
| 112 | + public function isCoreAlias($key) |
|
| 113 | + { |
|
| 114 | 114 | return isset($this->coreClasses()[$key]); |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function createObject($key) |
|
| 118 | - { |
|
| 117 | + public function createObject($key) |
|
| 118 | + { |
|
| 119 | 119 | $object = $this->coreClasses()[$key]; |
| 120 | 120 | |
| 121 | 121 | return new $object($this); |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - public function __get($key) |
|
| 125 | - { |
|
| 124 | + public function __get($key) |
|
| 125 | + { |
|
| 126 | 126 | return $this->get($key); |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | } |
| 129 | 129 | \ No newline at end of file |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | |
| 90 | 90 | public function get($key) |
| 91 | 91 | { |
| 92 | - if (! $this->isSharing($key)) { |
|
| 92 | + if (!$this->isSharing($key)) { |
|
| 93 | 93 | |
| 94 | 94 | if ($this->isCoreAlias($key)) { |
| 95 | 95 | |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $this->file->call($this->file->to('config/constant.php')); |
| 61 | 61 | |
| 62 | - foreach (glob("routes/**/*.php") as $route) $this->file->call($this->file->to($route)); |
|
| 62 | + foreach (glob("routes/**/*.php") as $route) { |
|
| 63 | + $this->file->call($this->file->to($route)); |
|
| 64 | + } |
|
| 63 | 65 | |
| 64 | 66 | $output = $this->route->getProperRoute(); |
| 65 | 67 | |
@@ -82,7 +84,9 @@ discard block |
||
| 82 | 84 | |
| 83 | 85 | public function share($key, $value) |
| 84 | 86 | { |
| 85 | - if ($value instanceof Closure) $value = call_user_func($value, $this); |
|
| 87 | + if ($value instanceof Closure) { |
|
| 88 | + $value = call_user_func($value, $this); |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | $this->container[$key] = $value; |
| 88 | 92 | } |
@@ -4,15 +4,15 @@ |
||
| 4 | 4 | |
| 5 | 5 | abstract class Controller |
| 6 | 6 | { |
| 7 | - protected $app; |
|
| 7 | + protected $app; |
|
| 8 | 8 | |
| 9 | - public function __construct(Application $app) |
|
| 10 | - { |
|
| 9 | + public function __construct(Application $app) |
|
| 10 | + { |
|
| 11 | 11 | $this->app = $app; |
| 12 | - } |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function __get($key) |
|
| 15 | - { |
|
| 14 | + public function __get($key) |
|
| 15 | + { |
|
| 16 | 16 | return $this->app->get($key); |
| 17 | - } |
|
| 17 | + } |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -4,50 +4,50 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Cookie |
| 6 | 6 | { |
| 7 | - private $app; |
|
| 7 | + private $app; |
|
| 8 | 8 | |
| 9 | - private $path; |
|
| 9 | + private $path; |
|
| 10 | 10 | |
| 11 | - public function __construct(Application $app) |
|
| 12 | - { |
|
| 11 | + public function __construct(Application $app) |
|
| 12 | + { |
|
| 13 | 13 | $this->app = $app; |
| 14 | 14 | |
| 15 | 15 | $this->path = dirname($this->app->request->server('SCRIPT_NAME')) ?: '/'; |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function set($key, $value, $hours = 1800) |
|
| 19 | - { |
|
| 18 | + public function set($key, $value, $hours = 1800) |
|
| 19 | + { |
|
| 20 | 20 | $expireTime = $hours == -1 ? -1 : time() + $hours * 3600; |
| 21 | 21 | |
| 22 | 22 | setcookie($key, $value, $expireTime, $this->path, '', false, true); |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function get($key , $default = null) |
|
| 26 | - { |
|
| 25 | + public function get($key , $default = null) |
|
| 26 | + { |
|
| 27 | 27 | return array_get($_COOKIE, $key, $default); |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function has($key) |
|
| 31 | - { |
|
| 30 | + public function has($key) |
|
| 31 | + { |
|
| 32 | 32 | return array_key_exists($key, $_COOKIE); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function remove($key) |
|
| 36 | - { |
|
| 35 | + public function remove($key) |
|
| 36 | + { |
|
| 37 | 37 | $this->set($key, null, -1); |
| 38 | 38 | |
| 39 | 39 | unset($_COOKIE[$key]); |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function all() |
|
| 43 | - { |
|
| 42 | + public function all() |
|
| 43 | + { |
|
| 44 | 44 | return $_COOKIE; |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function destroy() |
|
| 48 | - { |
|
| 47 | + public function destroy() |
|
| 48 | + { |
|
| 49 | 49 | foreach (array_keys($this->all()) as $key) $this->remove($key); |
| 50 | 50 | |
| 51 | 51 | unset($_COOKIE); |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -46,7 +46,9 @@ |
||
| 46 | 46 | |
| 47 | 47 | public function destroy() |
| 48 | 48 | { |
| 49 | - foreach (array_keys($this->all()) as $key) $this->remove($key); |
|
| 49 | + foreach (array_keys($this->all()) as $key) { |
|
| 50 | + $this->remove($key); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | unset($_COOKIE); |
| 52 | 54 | } |