@@ -3,23 +3,23 @@ |
||
| 3 | 3 | $app = app(); |
| 4 | 4 | |
| 5 | 5 | $adminOptions = [ |
| 6 | - 'prefix' => '/admin', |
|
| 7 | - 'controller' => 'Admin', |
|
| 8 | - 'middleware' => ['admin'] |
|
| 6 | + 'prefix' => '/admin', |
|
| 7 | + 'controller' => 'Admin', |
|
| 8 | + 'middleware' => ['admin'] |
|
| 9 | 9 | ]; |
| 10 | 10 | |
| 11 | 11 | $app->route->group($adminOptions, function ($route) { |
| 12 | 12 | |
| 13 | - $route->add('/', 'Home'); |
|
| 13 | + $route->add('/', 'Home'); |
|
| 14 | 14 | |
| 15 | - //Login |
|
| 16 | - $route->add('/login', 'Login'); |
|
| 17 | - $route->add('/submit', 'Login@submit', 'POST'); |
|
| 18 | - $route->add('/logout', 'Logout'); |
|
| 15 | + //Login |
|
| 16 | + $route->add('/login', 'Login'); |
|
| 17 | + $route->add('/submit', 'Login@submit', 'POST'); |
|
| 18 | + $route->add('/logout', 'Logout'); |
|
| 19 | 19 | |
| 20 | - //Profile |
|
| 21 | - $route->add('/profile', 'Profile', 'GET'); |
|
| 20 | + //Profile |
|
| 21 | + $route->add('/profile', 'Profile', 'GET'); |
|
| 22 | 22 | |
| 23 | - //Settings |
|
| 24 | - $route->add('/settings', 'Settings'); |
|
| 23 | + //Settings |
|
| 24 | + $route->add('/settings', 'Settings'); |
|
| 25 | 25 | }); |
| 26 | 26 | \ No newline at end of file |
@@ -11,117 +11,117 @@ |
||
| 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 | - { |
|
| 20 | - $this->handleErrors(); |
|
| 18 | + public function __construct(File $file) |
|
| 19 | + { |
|
| 20 | + $this->handleErrors(); |
|
| 21 | 21 | |
| 22 | - $this->share('file', $file); |
|
| 22 | + $this->share('file', $file); |
|
| 23 | 23 | |
| 24 | - $this->share('config', $this->file->call($this->file->to('config', '.php'))); |
|
| 24 | + $this->share('config', $this->file->call($this->file->to('config', '.php'))); |
|
| 25 | 25 | |
| 26 | - $this->share('alias', $this->file->call($this->file->to('config/alias', '.php'))); |
|
| 26 | + $this->share('alias', $this->file->call($this->file->to('config/alias', '.php'))); |
|
| 27 | 27 | |
| 28 | - $this->loadHelpers(); |
|
| 29 | - } |
|
| 28 | + $this->loadHelpers(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - private function handleErrors() { |
|
| 31 | + private function handleErrors() { |
|
| 32 | 32 | |
| 33 | - $run = new Whoops(); |
|
| 33 | + $run = new Whoops(); |
|
| 34 | 34 | |
| 35 | - $run->prependHandler(new PrettyPageHandler()); |
|
| 35 | + $run->prependHandler(new PrettyPageHandler()); |
|
| 36 | 36 | |
| 37 | - if (WhoopsMisc::isAjaxRequest()) { |
|
| 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); |
|
| 44 | - } |
|
| 43 | + $run->prependHandler($jsonHandler); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $run->register(); |
|
| 47 | - } |
|
| 46 | + $run->register(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public static function getInstance($file = null) |
|
| 50 | - { |
|
| 51 | - return static::$instance = is_null(static::$instance) ? new static($file) : static::$instance; |
|
| 52 | - } |
|
| 49 | + public static function getInstance($file = null) |
|
| 50 | + { |
|
| 51 | + return static::$instance = is_null(static::$instance) ? new static($file) : static::$instance; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function run() |
|
| 55 | - { |
|
| 56 | - $this->session->start(); |
|
| 54 | + public function run() |
|
| 55 | + { |
|
| 56 | + $this->session->start(); |
|
| 57 | 57 | |
| 58 | - $this->request->prepareUrl(); |
|
| 58 | + $this->request->prepareUrl(); |
|
| 59 | 59 | |
| 60 | - $this->file->call($this->file->to('config/constant.php')); |
|
| 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) $this->file->call($this->file->to($route)); |
|
| 63 | 63 | |
| 64 | - $output = $this->route->getProperRoute(); |
|
| 64 | + $output = $this->route->getProperRoute(); |
|
| 65 | 65 | |
| 66 | - $this->response->setOutput($output); |
|
| 66 | + $this->response->setOutput($output); |
|
| 67 | 67 | |
| 68 | - $this->response->send(); |
|
| 69 | - } |
|
| 68 | + $this->response->send(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - private function loadHelpers() |
|
| 72 | - { |
|
| 73 | - $helpers = $this->file->to('Core/helpers', '.php'); |
|
| 71 | + private function loadHelpers() |
|
| 72 | + { |
|
| 73 | + $helpers = $this->file->to('Core/helpers', '.php'); |
|
| 74 | 74 | |
| 75 | - $this->file->call($helpers); |
|
| 76 | - } |
|
| 75 | + $this->file->call($helpers); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function coreClasses() |
|
| 79 | - { |
|
| 80 | - return $this->alias['classes']; |
|
| 81 | - } |
|
| 78 | + public function coreClasses() |
|
| 79 | + { |
|
| 80 | + return $this->alias['classes']; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function share($key, $value) |
|
| 84 | - { |
|
| 85 | - if ($value instanceof Closure) $value = call_user_func($value, $this); |
|
| 83 | + public function share($key, $value) |
|
| 84 | + { |
|
| 85 | + if ($value instanceof Closure) $value = call_user_func($value, $this); |
|
| 86 | 86 | |
| 87 | - $this->container[$key] = $value; |
|
| 88 | - } |
|
| 87 | + $this->container[$key] = $value; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function get($key) |
|
| 91 | - { |
|
| 92 | - if (! $this->isSharing($key)) { |
|
| 90 | + public function get($key) |
|
| 91 | + { |
|
| 92 | + if (! $this->isSharing($key)) { |
|
| 93 | 93 | |
| 94 | - if ($this->isCoreAlias($key)) { |
|
| 94 | + if ($this->isCoreAlias($key)) { |
|
| 95 | 95 | |
| 96 | - $this->share($key, $this->createObject($key)); |
|
| 96 | + $this->share($key, $this->createObject($key)); |
|
| 97 | 97 | |
| 98 | - } else { |
|
| 98 | + } else { |
|
| 99 | 99 | |
| 100 | - throw new Exception("$key is not found"); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - return $this->container[$key]; |
|
| 104 | - } |
|
| 100 | + throw new Exception("$key is not found"); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + return $this->container[$key]; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function isSharing($key) |
|
| 107 | - { |
|
| 108 | - return isset($this->container[$key]); |
|
| 109 | - } |
|
| 106 | + public function isSharing($key) |
|
| 107 | + { |
|
| 108 | + return isset($this->container[$key]); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function isCoreAlias($key) |
|
| 112 | - { |
|
| 113 | - return isset($this->coreClasses()[$key]); |
|
| 114 | - } |
|
| 111 | + public function isCoreAlias($key) |
|
| 112 | + { |
|
| 113 | + return isset($this->coreClasses()[$key]); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - public function createObject($key) |
|
| 117 | - { |
|
| 118 | - $object = $this->coreClasses()[$key]; |
|
| 116 | + public function createObject($key) |
|
| 117 | + { |
|
| 118 | + $object = $this->coreClasses()[$key]; |
|
| 119 | 119 | |
| 120 | - return new $object($this); |
|
| 121 | - } |
|
| 120 | + return new $object($this); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - public function __get($key) |
|
| 124 | - { |
|
| 125 | - return $this->get($key); |
|
| 126 | - } |
|
| 123 | + public function __get($key) |
|
| 124 | + { |
|
| 125 | + return $this->get($key); |
|
| 126 | + } |
|
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -4,211 +4,211 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Validation |
| 6 | 6 | { |
| 7 | - private $app; |
|
| 7 | + private $app; |
|
| 8 | 8 | |
| 9 | - private $input; |
|
| 9 | + private $input; |
|
| 10 | 10 | |
| 11 | - private $errors = []; |
|
| 11 | + private $errors = []; |
|
| 12 | 12 | |
| 13 | - public function __construct(Application $app) |
|
| 14 | - { |
|
| 15 | - $this->app = $app; |
|
| 16 | - } |
|
| 13 | + public function __construct(Application $app) |
|
| 14 | + { |
|
| 15 | + $this->app = $app; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function input($input) |
|
| 19 | - { |
|
| 20 | - $this->input = $input; |
|
| 18 | + public function input($input) |
|
| 19 | + { |
|
| 20 | + $this->input = $input; |
|
| 21 | 21 | |
| 22 | - return $this; |
|
| 23 | - } |
|
| 22 | + return $this; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function require($input = null, $msg = null) |
|
| 26 | - { |
|
| 27 | - if (! $this->input) $this->input = $input; |
|
| 25 | + public function require($input = null, $msg = null) |
|
| 26 | + { |
|
| 27 | + if (! $this->input) $this->input = $input; |
|
| 28 | 28 | |
| 29 | - $value = $this->value($this->input); |
|
| 29 | + $value = $this->value($this->input); |
|
| 30 | 30 | |
| 31 | - if (! $value) { |
|
| 31 | + if (! $value) { |
|
| 32 | 32 | |
| 33 | - $msg = $msg ?: 'This input is required'; |
|
| 33 | + $msg = $msg ?: 'This input is required'; |
|
| 34 | 34 | |
| 35 | - $this->addError($this->input, $msg); |
|
| 36 | - } |
|
| 37 | - return $this; |
|
| 38 | - } |
|
| 35 | + $this->addError($this->input, $msg); |
|
| 36 | + } |
|
| 37 | + return $this; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function email($input = null, $msg = null) |
|
| 41 | - { |
|
| 42 | - if (! $this->input) $this->input = $input; |
|
| 40 | + public function email($input = null, $msg = null) |
|
| 41 | + { |
|
| 42 | + if (! $this->input) $this->input = $input; |
|
| 43 | 43 | |
| 44 | - $value = $this->value($this->input); |
|
| 44 | + $value = $this->value($this->input); |
|
| 45 | 45 | |
| 46 | - if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
| 46 | + if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
| 47 | 47 | |
| 48 | - $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
| 48 | + $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
| 49 | 49 | |
| 50 | - $this->addError($this->input, $msg); |
|
| 51 | - } |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 50 | + $this->addError($this->input, $msg); |
|
| 51 | + } |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function number($input = null, $msg = null) |
|
| 56 | - { |
|
| 57 | - if (! $this->input) $this->input = $input; |
|
| 55 | + public function number($input = null, $msg = null) |
|
| 56 | + { |
|
| 57 | + if (! $this->input) $this->input = $input; |
|
| 58 | 58 | |
| 59 | - $value = $this->value($this->input); |
|
| 59 | + $value = $this->value($this->input); |
|
| 60 | 60 | |
| 61 | - if ($value) { |
|
| 61 | + if ($value) { |
|
| 62 | 62 | |
| 63 | - if (! is_numeric($value)) { |
|
| 63 | + if (! is_numeric($value)) { |
|
| 64 | 64 | |
| 65 | - $msg = $msg ?: 'the Input must be number'; |
|
| 65 | + $msg = $msg ?: 'the Input must be number'; |
|
| 66 | 66 | |
| 67 | - $this->addError($this->input, $msg); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return $this; |
|
| 71 | - } |
|
| 67 | + $this->addError($this->input, $msg); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return $this; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function text($input = null, $msg = null) |
|
| 74 | - { |
|
| 75 | - if (! $this->input) $this->input = $input; |
|
| 73 | + public function text($input = null, $msg = null) |
|
| 74 | + { |
|
| 75 | + if (! $this->input) $this->input = $input; |
|
| 76 | 76 | |
| 77 | - $value = $this->value($this->input); |
|
| 77 | + $value = $this->value($this->input); |
|
| 78 | 78 | |
| 79 | - if ($value) { |
|
| 79 | + if ($value) { |
|
| 80 | 80 | |
| 81 | - if (is_numeric($value)) { |
|
| 81 | + if (is_numeric($value)) { |
|
| 82 | 82 | |
| 83 | - $msg = $msg ?: 'the Input must be Text'; |
|
| 83 | + $msg = $msg ?: 'the Input must be Text'; |
|
| 84 | 84 | |
| 85 | - $this->addError($this->input, $msg); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 85 | + $this->addError($this->input, $msg); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + return $this; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - public function minLen($length, $msg = null) |
|
| 92 | - { |
|
| 93 | - $value = $this->value($this->input); |
|
| 91 | + public function minLen($length, $msg = null) |
|
| 92 | + { |
|
| 93 | + $value = $this->value($this->input); |
|
| 94 | 94 | |
| 95 | - if ($value) { |
|
| 95 | + if ($value) { |
|
| 96 | 96 | |
| 97 | - if (strlen($value) < $length) { |
|
| 97 | + if (strlen($value) < $length) { |
|
| 98 | 98 | |
| 99 | - $msg = $msg ?: 'This input must be at least ' . $length; |
|
| 99 | + $msg = $msg ?: 'This input must be at least ' . $length; |
|
| 100 | 100 | |
| 101 | - $this->addError($this->input, $msg); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - return $this; |
|
| 105 | - } |
|
| 101 | + $this->addError($this->input, $msg); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + return $this; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function maxLen($length, $msg = null) |
|
| 108 | - { |
|
| 109 | - $value = $this->value($this->input); |
|
| 107 | + public function maxLen($length, $msg = null) |
|
| 108 | + { |
|
| 109 | + $value = $this->value($this->input); |
|
| 110 | 110 | |
| 111 | - if ($value) { |
|
| 111 | + if ($value) { |
|
| 112 | 112 | |
| 113 | - if (strlen($value) > $length) { |
|
| 113 | + if (strlen($value) > $length) { |
|
| 114 | 114 | |
| 115 | - $msg = $msg ?: 'This must be ' . $length . ' or fewer'; |
|
| 115 | + $msg = $msg ?: 'This must be ' . $length . ' or fewer'; |
|
| 116 | 116 | |
| 117 | - $this->addError($this->input, $msg); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return $this; |
|
| 121 | - } |
|
| 117 | + $this->addError($this->input, $msg); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - public function match($input, $msg = null) |
|
| 124 | - { |
|
| 125 | - $valuePassword = $this->value($this->input); |
|
| 123 | + public function match($input, $msg = null) |
|
| 124 | + { |
|
| 125 | + $valuePassword = $this->value($this->input); |
|
| 126 | 126 | |
| 127 | - $valueConfirm = $this->value($input); |
|
| 127 | + $valueConfirm = $this->value($input); |
|
| 128 | 128 | |
| 129 | - if ($valuePassword && $valueConfirm ) { |
|
| 129 | + if ($valuePassword && $valueConfirm ) { |
|
| 130 | 130 | |
| 131 | - if ($valuePassword !== $valueConfirm) { |
|
| 131 | + if ($valuePassword !== $valueConfirm) { |
|
| 132 | 132 | |
| 133 | - $msg = $msg ?: 'Passwords does not match'; |
|
| 133 | + $msg = $msg ?: 'Passwords does not match'; |
|
| 134 | 134 | |
| 135 | - $this->addError('match', $msg); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 135 | + $this->addError('match', $msg); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - public function unique(array $data, $msg = null) |
|
| 142 | - { |
|
| 143 | - $value = $this->value($this->input); |
|
| 141 | + public function unique(array $data, $msg = null) |
|
| 142 | + { |
|
| 143 | + $value = $this->value($this->input); |
|
| 144 | 144 | |
| 145 | - $table = null; |
|
| 146 | - $column = null; |
|
| 145 | + $table = null; |
|
| 146 | + $column = null; |
|
| 147 | 147 | |
| 148 | - $id = null; |
|
| 149 | - $userId = null; |
|
| 148 | + $id = null; |
|
| 149 | + $userId = null; |
|
| 150 | 150 | |
| 151 | - if (count($data) == 2) { |
|
| 151 | + if (count($data) == 2) { |
|
| 152 | 152 | |
| 153 | - list($table, $column) = $data; |
|
| 153 | + list($table, $column) = $data; |
|
| 154 | 154 | |
| 155 | - } elseif (count($data) == 4) { |
|
| 155 | + } elseif (count($data) == 4) { |
|
| 156 | 156 | |
| 157 | - list($table, $column, $id, $userId) = $data; |
|
| 158 | - } |
|
| 157 | + list($table, $column, $id, $userId) = $data; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $sql = $userId ? $column . ' = ? AND ' . $id . ' != ? ' : $column . ' = ?'; |
|
| 160 | + $sql = $userId ? $column . ' = ? AND ' . $id . ' != ? ' : $column . ' = ?'; |
|
| 161 | 161 | |
| 162 | - $valueSql = $userId ? [$value, $userId] : $value; |
|
| 162 | + $valueSql = $userId ? [$value, $userId] : $value; |
|
| 163 | 163 | |
| 164 | - $result = $this->app->db->select($column)->from($table)->where($sql, $valueSql)->fetch(); |
|
| 164 | + $result = $this->app->db->select($column)->from($table)->where($sql, $valueSql)->fetch(); |
|
| 165 | 165 | |
| 166 | - if ($result) { |
|
| 166 | + if ($result) { |
|
| 167 | 167 | |
| 168 | - $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
| 168 | + $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
| 169 | 169 | |
| 170 | - $this->addError($this->input, $msg); |
|
| 171 | - } |
|
| 172 | - return $this; |
|
| 173 | - } |
|
| 170 | + $this->addError($this->input, $msg); |
|
| 171 | + } |
|
| 172 | + return $this; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - public function message($msg = null) |
|
| 176 | - { |
|
| 177 | - $this->errors[] = $msg; |
|
| 175 | + public function message($msg = null) |
|
| 176 | + { |
|
| 177 | + $this->errors[] = $msg; |
|
| 178 | 178 | |
| 179 | - return $this; |
|
| 180 | - } |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public function passes() |
|
| 183 | - { |
|
| 184 | - return empty($this->errors); |
|
| 185 | - } |
|
| 182 | + public function passes() |
|
| 183 | + { |
|
| 184 | + return empty($this->errors); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - public function fails() |
|
| 188 | - { |
|
| 189 | - return ! empty($this->errors); |
|
| 190 | - } |
|
| 187 | + public function fails() |
|
| 188 | + { |
|
| 189 | + return ! empty($this->errors); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - public function getMsgs() |
|
| 193 | - { |
|
| 194 | - return $this->errors; |
|
| 195 | - } |
|
| 192 | + public function getMsgs() |
|
| 193 | + { |
|
| 194 | + return $this->errors; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - private function value($input) |
|
| 198 | - { |
|
| 199 | - return $this->app->request->post($input); |
|
| 200 | - } |
|
| 197 | + private function value($input) |
|
| 198 | + { |
|
| 199 | + return $this->app->request->post($input); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - public function addError($input, $msg) |
|
| 203 | - { |
|
| 204 | - if (! $this->checkError($input)) { |
|
| 202 | + public function addError($input, $msg) |
|
| 203 | + { |
|
| 204 | + if (! $this->checkError($input)) { |
|
| 205 | 205 | |
| 206 | - $this->errors[$input] = $msg; |
|
| 207 | - } |
|
| 208 | - } |
|
| 206 | + $this->errors[$input] = $msg; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - private function checkError($input) |
|
| 211 | - { |
|
| 212 | - return array_key_exists($input, $this->errors); |
|
| 213 | - } |
|
| 210 | + private function checkError($input) |
|
| 211 | + { |
|
| 212 | + return array_key_exists($input, $this->errors); |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | \ No newline at end of file |
@@ -6,47 +6,47 @@ |
||
| 6 | 6 | |
| 7 | 7 | class PugView |
| 8 | 8 | { |
| 9 | - private $app; |
|
| 10 | - |
|
| 11 | - public function __construct(Application $app) |
|
| 12 | - { |
|
| 13 | - $this->app = $app; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function render($path, array $context) |
|
| 17 | - { |
|
| 18 | - $this->app->file->css(); |
|
| 19 | - $pug = new Pug(array( |
|
| 20 | - 'pretty' => true, |
|
| 21 | - 'cache' => 'var/cache/pug', |
|
| 22 | - 'basedir' => 'template/', |
|
| 23 | - 'upToDateCheck' => false, |
|
| 24 | - )); |
|
| 25 | - |
|
| 26 | - $link = $this->app->request->link(); |
|
| 27 | - $dir = $this->app->file->root(); |
|
| 28 | - |
|
| 29 | - //File Path |
|
| 30 | - $file = str_replace('/', DS, $path); |
|
| 31 | - $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
| 32 | - |
|
| 33 | - //Css Path |
|
| 34 | - $css = $this->app->file->css(); |
|
| 35 | - $css = str_replace($dir, $link, $css); |
|
| 36 | - $css = str_replace('\\', '/', $css); |
|
| 37 | - |
|
| 38 | - //Js Path |
|
| 39 | - $js = $this->app->file->js(); |
|
| 40 | - $js = str_replace($dir, $link, $js); |
|
| 41 | - $js = str_replace('\\', '/', $js); |
|
| 42 | - |
|
| 43 | - $context += $this->app->config['website']; |
|
| 44 | - |
|
| 45 | - $context += [ |
|
| 46 | - 'css' => $css, |
|
| 47 | - 'js' => $js |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - return $pug->render($file, $context); |
|
| 51 | - } |
|
| 9 | + private $app; |
|
| 10 | + |
|
| 11 | + public function __construct(Application $app) |
|
| 12 | + { |
|
| 13 | + $this->app = $app; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function render($path, array $context) |
|
| 17 | + { |
|
| 18 | + $this->app->file->css(); |
|
| 19 | + $pug = new Pug(array( |
|
| 20 | + 'pretty' => true, |
|
| 21 | + 'cache' => 'var/cache/pug', |
|
| 22 | + 'basedir' => 'template/', |
|
| 23 | + 'upToDateCheck' => false, |
|
| 24 | + )); |
|
| 25 | + |
|
| 26 | + $link = $this->app->request->link(); |
|
| 27 | + $dir = $this->app->file->root(); |
|
| 28 | + |
|
| 29 | + //File Path |
|
| 30 | + $file = str_replace('/', DS, $path); |
|
| 31 | + $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
| 32 | + |
|
| 33 | + //Css Path |
|
| 34 | + $css = $this->app->file->css(); |
|
| 35 | + $css = str_replace($dir, $link, $css); |
|
| 36 | + $css = str_replace('\\', '/', $css); |
|
| 37 | + |
|
| 38 | + //Js Path |
|
| 39 | + $js = $this->app->file->js(); |
|
| 40 | + $js = str_replace($dir, $link, $js); |
|
| 41 | + $js = str_replace('\\', '/', $js); |
|
| 42 | + |
|
| 43 | + $context += $this->app->config['website']; |
|
| 44 | + |
|
| 45 | + $context += [ |
|
| 46 | + 'css' => $css, |
|
| 47 | + 'js' => $js |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + return $pug->render($file, $context); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -6,59 +6,59 @@ |
||
| 6 | 6 | |
| 7 | 7 | class File |
| 8 | 8 | { |
| 9 | - const DS = DIRECTORY_SEPARATOR; |
|
| 9 | + const DS = DIRECTORY_SEPARATOR; |
|
| 10 | 10 | |
| 11 | - private $root; |
|
| 11 | + private $root; |
|
| 12 | 12 | |
| 13 | - public function __construct($root) |
|
| 14 | - { |
|
| 15 | - $this->root = $root; |
|
| 16 | - } |
|
| 13 | + public function __construct($root) |
|
| 14 | + { |
|
| 15 | + $this->root = $root; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function root() |
|
| 19 | - { |
|
| 20 | - return $this->root; |
|
| 21 | - } |
|
| 18 | + public function root() |
|
| 19 | + { |
|
| 20 | + return $this->root; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function exists($file) |
|
| 24 | - { |
|
| 25 | - return file_exists($file); |
|
| 26 | - } |
|
| 23 | + public function exists($file) |
|
| 24 | + { |
|
| 25 | + return file_exists($file); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function call($file) |
|
| 29 | - { |
|
| 30 | - if ($this->exists($file)) { |
|
| 28 | + public function call($file) |
|
| 29 | + { |
|
| 30 | + if ($this->exists($file)) { |
|
| 31 | 31 | |
| 32 | - return require $file; |
|
| 32 | + return require $file; |
|
| 33 | 33 | |
| 34 | - } else { |
|
| 34 | + } else { |
|
| 35 | 35 | |
| 36 | - throw new Exception("$file is not found"); |
|
| 37 | - } |
|
| 38 | - } |
|
| 36 | + throw new Exception("$file is not found"); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function to($path, $ext = null) |
|
| 41 | - { |
|
| 42 | - return $this->root . static::DS . str_replace('/', static::DS, $path . $ext); |
|
| 43 | - } |
|
| 40 | + public function to($path, $ext = null) |
|
| 41 | + { |
|
| 42 | + return $this->root . static::DS . str_replace('/', static::DS, $path . $ext); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function toPublic($target = null) |
|
| 46 | - { |
|
| 47 | - return $this->to('public/' . $target); |
|
| 48 | - } |
|
| 45 | + public function toPublic($target = null) |
|
| 46 | + { |
|
| 47 | + return $this->to('public/' . $target); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function images() |
|
| 51 | - { |
|
| 52 | - return $this->toPublic('images'); |
|
| 53 | - } |
|
| 50 | + public function images() |
|
| 51 | + { |
|
| 52 | + return $this->toPublic('images'); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function js() |
|
| 56 | - { |
|
| 57 | - return $this->toPublic('js'); |
|
| 58 | - } |
|
| 55 | + public function js() |
|
| 56 | + { |
|
| 57 | + return $this->toPublic('js'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function css() |
|
| 61 | - { |
|
| 62 | - return $this->toPublic('css'); |
|
| 63 | - } |
|
| 60 | + public function css() |
|
| 61 | + { |
|
| 62 | + return $this->toPublic('css'); |
|
| 63 | + } |
|
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -6,99 +6,99 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Loader |
| 8 | 8 | { |
| 9 | - private $app; |
|
| 9 | + private $app; |
|
| 10 | 10 | |
| 11 | - private $controllers = []; |
|
| 11 | + private $controllers = []; |
|
| 12 | 12 | |
| 13 | - private $models = []; |
|
| 13 | + private $models = []; |
|
| 14 | 14 | |
| 15 | - public function __construct(Application $app) |
|
| 16 | - { |
|
| 17 | - $this->app = $app; |
|
| 18 | - } |
|
| 15 | + public function __construct(Application $app) |
|
| 16 | + { |
|
| 17 | + $this->app = $app; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function action($controller, $method, array $arguments) |
|
| 21 | - { |
|
| 22 | - $object = $this->controller($controller); |
|
| 20 | + public function action($controller, $method, array $arguments) |
|
| 21 | + { |
|
| 22 | + $object = $this->controller($controller); |
|
| 23 | 23 | |
| 24 | - return call_user_func([$object, $method], $arguments); |
|
| 25 | - } |
|
| 24 | + return call_user_func([$object, $method], $arguments); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function controller($controller) |
|
| 28 | - { |
|
| 29 | - $controller = $this->getControllerName($controller); |
|
| 27 | + public function controller($controller) |
|
| 28 | + { |
|
| 29 | + $controller = $this->getControllerName($controller); |
|
| 30 | 30 | |
| 31 | - if (! $this->hasController($controller)) { |
|
| 32 | - $this->addController($controller); |
|
| 33 | - } |
|
| 31 | + if (! $this->hasController($controller)) { |
|
| 32 | + $this->addController($controller); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - return $this->getController($controller); |
|
| 36 | - } |
|
| 35 | + return $this->getController($controller); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - private function hasController($controller) |
|
| 39 | - { |
|
| 40 | - return array_key_exists($controller, $this->controllers); |
|
| 41 | - } |
|
| 38 | + private function hasController($controller) |
|
| 39 | + { |
|
| 40 | + return array_key_exists($controller, $this->controllers); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - private function addController($controller) |
|
| 44 | - { |
|
| 45 | - $object = new $controller($this->app); |
|
| 43 | + private function addController($controller) |
|
| 44 | + { |
|
| 45 | + $object = new $controller($this->app); |
|
| 46 | 46 | |
| 47 | - $this->controllers[$controller] = $object; |
|
| 48 | - } |
|
| 47 | + $this->controllers[$controller] = $object; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - private function getController($controller) |
|
| 51 | - { |
|
| 52 | - return $this->controllers[$controller]; |
|
| 53 | - } |
|
| 50 | + private function getController($controller) |
|
| 51 | + { |
|
| 52 | + return $this->controllers[$controller]; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - private function getControllerName($controller) |
|
| 56 | - { |
|
| 57 | - $controller .= strpos($controller, 'Controller') ? '' : 'Controller'; |
|
| 55 | + private function getControllerName($controller) |
|
| 56 | + { |
|
| 57 | + $controller .= strpos($controller, 'Controller') ? '' : 'Controller'; |
|
| 58 | 58 | |
| 59 | - $controller = str_replace('/', DS, $controller); |
|
| 59 | + $controller = str_replace('/', DS, $controller); |
|
| 60 | 60 | |
| 61 | - $controller = 'App' . DS .'Controllers' . DS . $controller; |
|
| 61 | + $controller = 'App' . DS .'Controllers' . DS . $controller; |
|
| 62 | 62 | |
| 63 | - return $controller; |
|
| 64 | - } |
|
| 63 | + return $controller; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function model($model) |
|
| 67 | - { |
|
| 68 | - $model = $this->getModelName($model); |
|
| 66 | + public function model($model) |
|
| 67 | + { |
|
| 68 | + $model = $this->getModelName($model); |
|
| 69 | 69 | |
| 70 | - if (! $this->hasModel($model)) { |
|
| 71 | - $this->addModel($model); |
|
| 72 | - } |
|
| 70 | + if (! $this->hasModel($model)) { |
|
| 71 | + $this->addModel($model); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $this->getModel($model); |
|
| 75 | - } |
|
| 74 | + return $this->getModel($model); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - private function hasModel($model) |
|
| 78 | - { |
|
| 79 | - return array_key_exists($model, $this->models); |
|
| 80 | - } |
|
| 77 | + private function hasModel($model) |
|
| 78 | + { |
|
| 79 | + return array_key_exists($model, $this->models); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function addModel($model) |
|
| 83 | - { |
|
| 84 | - $object = new $model($this->app); |
|
| 82 | + private function addModel($model) |
|
| 83 | + { |
|
| 84 | + $object = new $model($this->app); |
|
| 85 | 85 | |
| 86 | - $this->models[$model] = $object; |
|
| 87 | - } |
|
| 86 | + $this->models[$model] = $object; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - private function getModel($model) |
|
| 90 | - { |
|
| 91 | - return $this->models[$model]; |
|
| 92 | - } |
|
| 89 | + private function getModel($model) |
|
| 90 | + { |
|
| 91 | + return $this->models[$model]; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - private function getModelName($model) |
|
| 95 | - { |
|
| 96 | - $model .= strpos($model, 'Model') ? '' : 'Model'; |
|
| 94 | + private function getModelName($model) |
|
| 95 | + { |
|
| 96 | + $model .= strpos($model, 'Model') ? '' : 'Model'; |
|
| 97 | 97 | |
| 98 | - $model = str_replace('/', DS, $model); |
|
| 98 | + $model = str_replace('/', DS, $model); |
|
| 99 | 99 | |
| 100 | - $model = 'App' . DS . 'Models' . DS . $model; |
|
| 100 | + $model = 'App' . DS . 'Models' . DS . $model; |
|
| 101 | 101 | |
| 102 | - return $model; |
|
| 103 | - } |
|
| 102 | + return $model; |
|
| 103 | + } |
|
| 104 | 104 | } |
| 105 | 105 | \ No newline at end of file |
@@ -4,28 +4,28 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Url |
| 6 | 6 | { |
| 7 | - protected $app; |
|
| 7 | + protected $app; |
|
| 8 | 8 | |
| 9 | - public function __construct(Application $app) |
|
| 10 | - { |
|
| 11 | - $this->app = $app; |
|
| 12 | - } |
|
| 9 | + public function __construct(Application $app) |
|
| 10 | + { |
|
| 11 | + $this->app = $app; |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function link($path) |
|
| 15 | - { |
|
| 16 | - $link = $this->app->request->link(); |
|
| 14 | + public function link($path) |
|
| 15 | + { |
|
| 16 | + $link = $this->app->request->link(); |
|
| 17 | 17 | |
| 18 | - $path = rtrim($path, '/'); |
|
| 19 | - $path = ltrim($path, '/'); |
|
| 18 | + $path = rtrim($path, '/'); |
|
| 19 | + $path = ltrim($path, '/'); |
|
| 20 | 20 | |
| 21 | - return $link . '/' . $path; |
|
| 22 | - } |
|
| 21 | + return $link . '/' . $path; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function redirectTo($path, $num = 0) |
|
| 25 | - { |
|
| 26 | - if ($path == 'error') $this->app->session->set('error', true); |
|
| 24 | + public function redirectTo($path, $num = 0) |
|
| 25 | + { |
|
| 26 | + if ($path == 'error') $this->app->session->set('error', true); |
|
| 27 | 27 | |
| 28 | - header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
|
| 29 | - exit; |
|
| 30 | - } |
|
| 28 | + header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
|
| 29 | + exit; |
|
| 30 | + } |
|
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -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 | - { |
|
| 11 | - $this->app = $app; |
|
| 12 | - } |
|
| 9 | + public function __construct(Application $app) |
|
| 10 | + { |
|
| 11 | + $this->app = $app; |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function __get($key) |
|
| 15 | - { |
|
| 16 | - return $this->app->get($key); |
|
| 17 | - } |
|
| 14 | + public function __get($key) |
|
| 15 | + { |
|
| 16 | + return $this->app->get($key); |
|
| 17 | + } |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -4,60 +4,60 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Session |
| 6 | 6 | { |
| 7 | - private $app; |
|
| 8 | - |
|
| 9 | - public function __construct(Application $app) |
|
| 10 | - { |
|
| 11 | - $this->app = $app; |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - public function start() |
|
| 15 | - { |
|
| 16 | - ini_set('session.use_only_cookies', 1); |
|
| 17 | - |
|
| 18 | - if (! session_id()) { |
|
| 19 | - session_start(); |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function set($key, $value) |
|
| 24 | - { |
|
| 25 | - $_SESSION[$key] = $value; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function get($key, $default = null) |
|
| 29 | - { |
|
| 30 | - return array_get($_SESSION, $key, $default); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function pull($key) |
|
| 34 | - { |
|
| 35 | - $value = $this->get($key); |
|
| 36 | - |
|
| 37 | - $this->remove($key); |
|
| 38 | - |
|
| 39 | - return $value; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function has($key) |
|
| 43 | - { |
|
| 44 | - return isset($_SESSION[$key]); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function all() |
|
| 48 | - { |
|
| 49 | - return $_SESSION; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function remove($key) |
|
| 53 | - { |
|
| 54 | - unset($_SESSION[$key]); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function destroy() |
|
| 58 | - { |
|
| 59 | - session_destroy(); |
|
| 60 | - |
|
| 61 | - unset($_SESSION); |
|
| 62 | - } |
|
| 7 | + private $app; |
|
| 8 | + |
|
| 9 | + public function __construct(Application $app) |
|
| 10 | + { |
|
| 11 | + $this->app = $app; |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + public function start() |
|
| 15 | + { |
|
| 16 | + ini_set('session.use_only_cookies', 1); |
|
| 17 | + |
|
| 18 | + if (! session_id()) { |
|
| 19 | + session_start(); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function set($key, $value) |
|
| 24 | + { |
|
| 25 | + $_SESSION[$key] = $value; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function get($key, $default = null) |
|
| 29 | + { |
|
| 30 | + return array_get($_SESSION, $key, $default); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function pull($key) |
|
| 34 | + { |
|
| 35 | + $value = $this->get($key); |
|
| 36 | + |
|
| 37 | + $this->remove($key); |
|
| 38 | + |
|
| 39 | + return $value; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function has($key) |
|
| 43 | + { |
|
| 44 | + return isset($_SESSION[$key]); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function all() |
|
| 48 | + { |
|
| 49 | + return $_SESSION; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function remove($key) |
|
| 53 | + { |
|
| 54 | + unset($_SESSION[$key]); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function destroy() |
|
| 58 | + { |
|
| 59 | + session_destroy(); |
|
| 60 | + |
|
| 61 | + unset($_SESSION); |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | \ No newline at end of file |