@@ -4,53 +4,53 @@ |
||
| 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) { |
| 50 | 50 | |
| 51 | - $this->remove($key); |
|
| 51 | + $this->remove($key); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | unset($_COOKIE); |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | setcookie($key, $value, $expireTime, $this->path, '', false, true); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function get($key , $default = null) |
|
| 25 | + public function get($key, $default = null) |
|
| 26 | 26 | { |
| 27 | 27 | return array_get($_COOKIE, $key, $default); |
| 28 | 28 | } |
@@ -4,62 +4,62 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | abstract class Model |
| 6 | 6 | { |
| 7 | - protected $app; |
|
| 7 | + protected $app; |
|
| 8 | 8 | |
| 9 | - protected $table; |
|
| 9 | + protected $table; |
|
| 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 | |
| 16 | - public function __get($key) |
|
| 17 | - { |
|
| 16 | + public function __get($key) |
|
| 17 | + { |
|
| 18 | 18 | return $this->app->get($key); |
| 19 | - } |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function __call($method, $args) |
|
| 22 | - { |
|
| 21 | + public function __call($method, $args) |
|
| 22 | + { |
|
| 23 | 23 | return call_user_func_array([$this->app->db, $method], $args); |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function all($limit = null) |
|
| 27 | - { |
|
| 26 | + public function all($limit = null) |
|
| 27 | + { |
|
| 28 | 28 | return $this->orderBy('id', 'DESC')->limit($limit)->fetchAll($this->table); |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function allEnable($limit = null) |
|
| 32 | - { |
|
| 31 | + public function allEnable($limit = null) |
|
| 32 | + { |
|
| 33 | 33 | return $this->orderBy('id', 'DESC')->where('enable = ?', 1)->limit($limit)->fetchAll($this->table); |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function get($value, $coulmn = 'id') |
|
| 37 | - { |
|
| 36 | + public function get($value, $coulmn = 'id') |
|
| 37 | + { |
|
| 38 | 38 | return $this->where($coulmn . ' = ?' , $value)->fetch($this->table); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function getEnable($value, $coulmn = 'id') |
|
| 42 | - { |
|
| 41 | + public function getEnable($value, $coulmn = 'id') |
|
| 42 | + { |
|
| 43 | 43 | return $this->where($coulmn . ' = ? AND enable = ?' , [$value, 1])->fetch($this->table); |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function selectTable($coulmn) |
|
| 47 | - { |
|
| 46 | + public function selectTable($coulmn) |
|
| 47 | + { |
|
| 48 | 48 | return $this->select($coulmn)->fetchAll($this->table); |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function exists($value, $key = 'id') |
|
| 52 | - { |
|
| 51 | + public function exists($value, $key = 'id') |
|
| 52 | + { |
|
| 53 | 53 | return (bool) $this->select($key)->where($key .'=?' , $value)->fetch($this->table); |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function delete($id) |
|
| 57 | - { |
|
| 56 | + public function delete($id) |
|
| 57 | + { |
|
| 58 | 58 | return $this->where('id = ?' , $id)->delete($this->table); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function hasOne($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 62 | - { |
|
| 61 | + public function hasOne($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 62 | + { |
|
| 63 | 63 | $join = rtrim($join, 'Model'); |
| 64 | 64 | |
| 65 | 65 | $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | $join = $this->load->model($join)->table; |
| 76 | 76 | |
| 77 | 77 | return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetch(); |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function hasMany($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 81 | - { |
|
| 80 | + public function hasMany($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 81 | + { |
|
| 82 | 82 | $join = rtrim($join, 'Model'); |
| 83 | 83 | |
| 84 | 84 | $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | $join = $this->load->model($join)->table; |
| 95 | 95 | |
| 96 | 96 | return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetchAll(); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function join($join, $limit = null, $enable = null, $localId = null, $forginId = null) |
|
| 100 | - { |
|
| 99 | + public function join($join, $limit = null, $enable = null, $localId = null, $forginId = null) |
|
| 100 | + { |
|
| 101 | 101 | $join = rtrim($join, 'Model'); |
| 102 | 102 | |
| 103 | 103 | $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
@@ -118,5 +118,5 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return $this->db->select()->from($table)->join($join, $localId, $forginId)->limit($limit)->fetchAll(); |
| 121 | - } |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | \ No newline at end of file |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function get($value, $coulmn = 'id') |
| 37 | 37 | { |
| 38 | - return $this->where($coulmn . ' = ?' , $value)->fetch($this->table); |
|
| 38 | + return $this->where($coulmn . ' = ?', $value)->fetch($this->table); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function getEnable($value, $coulmn = 'id') |
| 42 | 42 | { |
| 43 | - return $this->where($coulmn . ' = ? AND enable = ?' , [$value, 1])->fetch($this->table); |
|
| 43 | + return $this->where($coulmn . ' = ? AND enable = ?', [$value, 1])->fetch($this->table); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function selectTable($coulmn) |
@@ -50,23 +50,23 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | public function exists($value, $key = 'id') |
| 52 | 52 | { |
| 53 | - return (bool) $this->select($key)->where($key .'=?' , $value)->fetch($this->table); |
|
| 53 | + return (bool) $this->select($key)->where($key . '=?', $value)->fetch($this->table); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function delete($id) |
| 57 | 57 | { |
| 58 | - return $this->where('id = ?' , $id)->delete($this->table); |
|
| 58 | + return $this->where('id = ?', $id)->delete($this->table); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public function hasOne($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
| 62 | 62 | { |
| 63 | 63 | $join = rtrim($join, 'Model'); |
| 64 | 64 | |
| 65 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 65 | + $file = $this->app->file->to('App/Models/' . $join . 'Model', '.php'); |
|
| 66 | 66 | |
| 67 | 67 | $exists = $this->app->file->exists($file); |
| 68 | 68 | |
| 69 | - if (! $exists) return $join . ' Not Found'; |
|
| 69 | + if (!$exists) return $join . ' Not Found'; |
|
| 70 | 70 | |
| 71 | 71 | $trace = debug_backtrace(); |
| 72 | 72 | |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $join = rtrim($join, 'Model'); |
| 83 | 83 | |
| 84 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 84 | + $file = $this->app->file->to('App/Models/' . $join . 'Model', '.php'); |
|
| 85 | 85 | |
| 86 | 86 | $exists = $this->app->file->exists($file); |
| 87 | 87 | |
| 88 | - if (! $exists) return $join . ' Not Found'; |
|
| 88 | + if (!$exists) return $join . ' Not Found'; |
|
| 89 | 89 | |
| 90 | 90 | $trace = debug_backtrace(); |
| 91 | 91 | |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | $join = rtrim($join, 'Model'); |
| 102 | 102 | |
| 103 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 103 | + $file = $this->app->file->to('App/Models/' . $join . 'Model', '.php'); |
|
| 104 | 104 | |
| 105 | 105 | $exists = $this->app->file->exists($file); |
| 106 | 106 | |
| 107 | - if (! $exists) return $join . ' Not Found'; |
|
| 107 | + if (!$exists) return $join . ' Not Found'; |
|
| 108 | 108 | |
| 109 | 109 | $trace = debug_backtrace(); |
| 110 | 110 | |
@@ -66,7 +66,9 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | $exists = $this->app->file->exists($file); |
| 68 | 68 | |
| 69 | - if (! $exists) return $join . ' Not Found'; |
|
| 69 | + if (! $exists) { |
|
| 70 | + return $join . ' Not Found'; |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | $trace = debug_backtrace(); |
| 72 | 74 | |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | |
| 86 | 88 | $exists = $this->app->file->exists($file); |
| 87 | 89 | |
| 88 | - if (! $exists) return $join . ' Not Found'; |
|
| 90 | + if (! $exists) { |
|
| 91 | + return $join . ' Not Found'; |
|
| 92 | + } |
|
| 89 | 93 | |
| 90 | 94 | $trace = debug_backtrace(); |
| 91 | 95 | |
@@ -104,7 +108,9 @@ discard block |
||
| 104 | 108 | |
| 105 | 109 | $exists = $this->app->file->exists($file); |
| 106 | 110 | |
| 107 | - if (! $exists) return $join . ' Not Found'; |
|
| 111 | + if (! $exists) { |
|
| 112 | + return $join . ' Not Found'; |
|
| 113 | + } |
|
| 108 | 114 | |
| 109 | 115 | $trace = debug_backtrace(); |
| 110 | 116 | |
@@ -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 | - { |
|
| 13 | + public function __construct($root) |
|
| 14 | + { |
|
| 15 | 15 | $this->root = $root; |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function root() |
|
| 19 | - { |
|
| 18 | + public function root() |
|
| 19 | + { |
|
| 20 | 20 | return $this->root; |
| 21 | - } |
|
| 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 | - { |
|
| 28 | + public function call($file) |
|
| 29 | + { |
|
| 30 | 30 | if ($this->exists($file)) { |
| 31 | 31 | |
| 32 | - return require $file; |
|
| 32 | + return require $file; |
|
| 33 | 33 | |
| 34 | 34 | } else { |
| 35 | 35 | |
| 36 | - throw new Exception("$file is not found"); |
|
| 36 | + throw new Exception("$file is not found"); |
|
| 37 | + } |
|
| 37 | 38 | } |
| 38 | - } |
|
| 39 | 39 | |
| 40 | - public function to($path, $ext = null) |
|
| 41 | - { |
|
| 40 | + public function to($path, $ext = null) |
|
| 41 | + { |
|
| 42 | 42 | return $this->root . static::DS . str_replace('/', static::DS, $path . $ext); |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function toPublic($target = null) |
|
| 46 | - { |
|
| 45 | + public function toPublic($target = null) |
|
| 46 | + { |
|
| 47 | 47 | return $this->to('public/' . $target); |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function images() |
|
| 51 | - { |
|
| 50 | + public function images() |
|
| 51 | + { |
|
| 52 | 52 | return $this->toPublic('images'); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function js() |
|
| 56 | - { |
|
| 55 | + public function js() |
|
| 56 | + { |
|
| 57 | 57 | return $this->toPublic('js'); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function css() |
|
| 61 | - { |
|
| 60 | + public function css() |
|
| 61 | + { |
|
| 62 | 62 | return $this->toPublic('css'); |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -6,56 +6,56 @@ discard block |
||
| 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 | - private $middlewares = []; |
|
| 15 | + private $middlewares = []; |
|
| 16 | 16 | |
| 17 | - public function __construct(Application $app) |
|
| 18 | - { |
|
| 17 | + public function __construct(Application $app) |
|
| 18 | + { |
|
| 19 | 19 | $this->app = $app; |
| 20 | - } |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function action($controller, $method, array $arguments) |
|
| 23 | - { |
|
| 22 | + public function action($controller, $method, array $arguments) |
|
| 23 | + { |
|
| 24 | 24 | $object = $this->controller($controller); |
| 25 | 25 | |
| 26 | 26 | return call_user_func([$object, $method], $arguments); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function controller($controller) |
|
| 30 | - { |
|
| 29 | + public function controller($controller) |
|
| 30 | + { |
|
| 31 | 31 | $controller = $this->getControllerName($controller); |
| 32 | 32 | |
| 33 | 33 | if (! $this->hasController($controller)) { |
| 34 | - $this->addController($controller); |
|
| 34 | + $this->addController($controller); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | return $this->getController($controller); |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - private function hasController($controller) |
|
| 41 | - { |
|
| 40 | + private function hasController($controller) |
|
| 41 | + { |
|
| 42 | 42 | return array_key_exists($controller, $this->controllers); |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - private function addController($controller) |
|
| 46 | - { |
|
| 45 | + private function addController($controller) |
|
| 46 | + { |
|
| 47 | 47 | $object = new $controller($this->app); |
| 48 | 48 | |
| 49 | 49 | $this->controllers[$controller] = $object; |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - private function getController($controller) |
|
| 53 | - { |
|
| 52 | + private function getController($controller) |
|
| 53 | + { |
|
| 54 | 54 | return $this->controllers[$controller]; |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - private function getControllerName($controller) |
|
| 58 | - { |
|
| 57 | + private function getControllerName($controller) |
|
| 58 | + { |
|
| 59 | 59 | $controller .= strpos($controller, 'Controller') ? '' : 'Controller'; |
| 60 | 60 | |
| 61 | 61 | $controller = str_replace('/', DS, $controller); |
@@ -63,38 +63,38 @@ discard block |
||
| 63 | 63 | $controller = 'App' . DS .'Controllers' . DS . $controller; |
| 64 | 64 | |
| 65 | 65 | return $controller; |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function model($model) |
|
| 69 | - { |
|
| 68 | + public function model($model) |
|
| 69 | + { |
|
| 70 | 70 | $model = $this->getModelName($model); |
| 71 | 71 | |
| 72 | 72 | if (! $this->hasModel($model)) { |
| 73 | - $this->addModel($model); |
|
| 73 | + $this->addModel($model); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return $this->getModel($model); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - private function hasModel($model) |
|
| 80 | - { |
|
| 79 | + private function hasModel($model) |
|
| 80 | + { |
|
| 81 | 81 | return array_key_exists($model, $this->models); |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - private function addModel($model) |
|
| 85 | - { |
|
| 84 | + private function addModel($model) |
|
| 85 | + { |
|
| 86 | 86 | $object = new $model($this->app); |
| 87 | 87 | |
| 88 | 88 | $this->models[$model] = $object; |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - private function getModel($model) |
|
| 92 | - { |
|
| 91 | + private function getModel($model) |
|
| 92 | + { |
|
| 93 | 93 | return $this->models[$model]; |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - private function getModelName($model) |
|
| 97 | - { |
|
| 96 | + private function getModelName($model) |
|
| 97 | + { |
|
| 98 | 98 | $model .= strpos($model, 'Model') ? '' : 'Model'; |
| 99 | 99 | |
| 100 | 100 | $model = str_replace('/', DS, $model); |
@@ -102,5 +102,5 @@ discard block |
||
| 102 | 102 | $model = 'App' . DS . 'Models' . DS . $model; |
| 103 | 103 | |
| 104 | 104 | return $model; |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | } |
| 107 | 107 | \ No newline at end of file |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $controller = $this->getControllerName($controller); |
| 32 | 32 | |
| 33 | - if (! $this->hasController($controller)) { |
|
| 33 | + if (!$this->hasController($controller)) { |
|
| 34 | 34 | $this->addController($controller); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $controller = str_replace('/', DS, $controller); |
| 62 | 62 | |
| 63 | - $controller = 'App' . DS .'Controllers' . DS . $controller; |
|
| 63 | + $controller = 'App' . DS . 'Controllers' . DS . $controller; |
|
| 64 | 64 | |
| 65 | 65 | return $controller; |
| 66 | 66 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $model = $this->getModelName($model); |
| 71 | 71 | |
| 72 | - if (! $this->hasModel($model)) { |
|
| 72 | + if (!$this->hasModel($model)) { |
|
| 73 | 73 | $this->addModel($model); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -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 | |
@@ -44,15 +44,15 @@ discard block |
||
| 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,32 +66,32 @@ 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) { |
| 86 | 86 | |
| 87 | 87 | $value = call_user_func($value, $this); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $this->container[$key] = $value; |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function get($key) |
|
| 94 | - { |
|
| 93 | + public function get($key) |
|
| 94 | + { |
|
| 95 | 95 | if (! $this->isSharing($key)) { |
| 96 | 96 | if ($this->isCoreAlias($key)) { |
| 97 | 97 | |
@@ -103,27 +103,27 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | return $this->container[$key]; |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - public function isSharing($key) |
|
| 109 | - { |
|
| 108 | + public function isSharing($key) |
|
| 109 | + { |
|
| 110 | 110 | return isset($this->container[$key]); |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public function isCoreAlias($key) |
|
| 114 | - { |
|
| 113 | + public function isCoreAlias($key) |
|
| 114 | + { |
|
| 115 | 115 | return isset($this->coreClasses()[$key]); |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - public function createObject($key) |
|
| 119 | - { |
|
| 118 | + public function createObject($key) |
|
| 119 | + { |
|
| 120 | 120 | $object = $this->coreClasses()[$key]; |
| 121 | 121 | |
| 122 | 122 | return new $object($this); |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function __get($key) |
|
| 126 | - { |
|
| 125 | + public function __get($key) |
|
| 126 | + { |
|
| 127 | 127 | return $this->get($key); |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | } |
| 130 | 130 | \ No newline at end of file |
@@ -92,7 +92,7 @@ |
||
| 92 | 92 | |
| 93 | 93 | public function get($key) |
| 94 | 94 | { |
| 95 | - if (! $this->isSharing($key)) { |
|
| 95 | + if (!$this->isSharing($key)) { |
|
| 96 | 96 | if ($this->isCoreAlias($key)) { |
| 97 | 97 | |
| 98 | 98 | $this->share($key, $this->createObject($key)); |
@@ -59,7 +59,9 @@ |
||
| 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 | |
@@ -6,53 +6,53 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | class Route |
| 8 | 8 | { |
| 9 | - const NEXT = '_NEXT_'; |
|
| 9 | + const NEXT = '_NEXT_'; |
|
| 10 | 10 | |
| 11 | - private $app; |
|
| 11 | + private $app; |
|
| 12 | 12 | |
| 13 | - private $routes = []; |
|
| 13 | + private $routes = []; |
|
| 14 | 14 | |
| 15 | - public $current = []; |
|
| 15 | + public $current = []; |
|
| 16 | 16 | |
| 17 | - private $prefix; |
|
| 17 | + private $prefix; |
|
| 18 | 18 | |
| 19 | - private $basController; |
|
| 19 | + private $basController; |
|
| 20 | 20 | |
| 21 | - private $middlewareFrom; |
|
| 21 | + private $middlewareFrom; |
|
| 22 | 22 | |
| 23 | - private $groupMiddleware = []; |
|
| 23 | + private $groupMiddleware = []; |
|
| 24 | 24 | |
| 25 | - public function __construct(Application $app) |
|
| 26 | - { |
|
| 25 | + public function __construct(Application $app) |
|
| 26 | + { |
|
| 27 | 27 | $this->app = $app; |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function add($url, $action, $requestMethos = 'GET', $middleware = []) |
|
| 31 | - { |
|
| 30 | + public function add($url, $action, $requestMethos = 'GET', $middleware = []) |
|
| 31 | + { |
|
| 32 | 32 | if ($this->prefix) { |
| 33 | 33 | |
| 34 | - if ($this->prefix !== '/') { |
|
| 34 | + if ($this->prefix !== '/') { |
|
| 35 | 35 | |
| 36 | 36 | $url = $this->prefix . $url; |
| 37 | 37 | |
| 38 | 38 | $url = rtrim($url, '/'); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if ($this->basController) $action = $this->basController . '/' . $action; |
|
| 42 | + if ($this->basController) $action = $this->basController . '/' . $action; |
|
| 43 | 43 | |
| 44 | 44 | if ($this->groupMiddleware) { |
| 45 | 45 | |
| 46 | - if (is_array($middleware)) { |
|
| 46 | + if (is_array($middleware)) { |
|
| 47 | 47 | |
| 48 | 48 | $middleware = array_merge($this->groupMiddleware[0], $middleware); |
| 49 | 49 | |
| 50 | - } else { |
|
| 50 | + } else { |
|
| 51 | 51 | |
| 52 | 52 | array_push($this->groupMiddleware[0], $middleware); |
| 53 | 53 | |
| 54 | 54 | $middleware = $this->groupMiddleware[0]; |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $routes = [ |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | $this->routes[] = $routes; |
| 67 | 67 | |
| 68 | 68 | return $this; |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function group($groupOptions, callable $callback) |
|
| 72 | - { |
|
| 71 | + public function group($groupOptions, callable $callback) |
|
| 72 | + { |
|
| 73 | 73 | $prefix = $groupOptions['prefix']; |
| 74 | 74 | $controller = $groupOptions['controller']; |
| 75 | 75 | $middlewareFrom = array_shift($groupOptions['middleware']); |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | $callback($this); |
| 86 | 86 | |
| 87 | 87 | return $this; |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function package($url, $controller) |
|
| 91 | - { |
|
| 90 | + public function package($url, $controller) |
|
| 91 | + { |
|
| 92 | 92 | $this->add("$url", "$controller"); |
| 93 | 93 | $this->add("$url/add", "$controller@add", "POST"); |
| 94 | 94 | $this->add("$url/submit", "$controller@submit", "POST"); |
@@ -97,19 +97,19 @@ discard block |
||
| 97 | 97 | $this->add("$url/delete/:id", "$controller@delete", "POST"); |
| 98 | 98 | |
| 99 | 99 | return $this; |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - public function generatePattern($url) |
|
| 103 | - { |
|
| 102 | + public function generatePattern($url) |
|
| 103 | + { |
|
| 104 | 104 | $pattern = '#^'; |
| 105 | 105 | $pattern .= str_replace([':text', ':id'], ['([a-zA-Z0-9-]+)', '(\d+)'], $url); |
| 106 | 106 | $pattern .= '$#'; |
| 107 | 107 | |
| 108 | 108 | return $pattern; |
| 109 | - } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function getAction($action) |
|
| 112 | - { |
|
| 111 | + public function getAction($action) |
|
| 112 | + { |
|
| 113 | 113 | $action = str_replace('/', '\\', $action); |
| 114 | 114 | |
| 115 | 115 | $action = (strpos($action, '@') != 0) ? $action : $action . '@index'; |
@@ -117,49 +117,49 @@ discard block |
||
| 117 | 117 | $action = explode('@', $action); |
| 118 | 118 | |
| 119 | 119 | return $action; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - public function getProperRoute() |
|
| 123 | - { |
|
| 122 | + public function getProperRoute() |
|
| 123 | + { |
|
| 124 | 124 | foreach($this->routes as $route) { |
| 125 | 125 | |
| 126 | 126 | if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
| 127 | 127 | |
| 128 | - $this->current = $route; |
|
| 128 | + $this->current = $route; |
|
| 129 | 129 | |
| 130 | - $output = ''; |
|
| 130 | + $output = ''; |
|
| 131 | 131 | |
| 132 | - if ($route['middleware']) { |
|
| 132 | + if ($route['middleware']) { |
|
| 133 | 133 | |
| 134 | 134 | if (is_array($route['middleware'])) { |
| 135 | 135 | |
| 136 | - foreach($route['middleware'] as $middleware) { |
|
| 136 | + foreach($route['middleware'] as $middleware) { |
|
| 137 | 137 | |
| 138 | 138 | $output = $this->middleware($middleware); |
| 139 | 139 | |
| 140 | 140 | if ($output != '') break; |
| 141 | - } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | } else { |
| 144 | 144 | |
| 145 | - $output = $this->middleware($route['middleware']); |
|
| 145 | + $output = $this->middleware($route['middleware']); |
|
| 146 | 146 | |
| 147 | - if ($output != '') break; |
|
| 147 | + if ($output != '') break; |
|
| 148 | + } |
|
| 148 | 149 | } |
| 149 | - } |
|
| 150 | 150 | |
| 151 | 151 | if ($output == '') { |
| 152 | 152 | |
| 153 | - list($controller, $method) = $route['action']; |
|
| 153 | + list($controller, $method) = $route['action']; |
|
| 154 | 154 | |
| 155 | - $arguments = $this->getArgumentsFor($route['pattern']); |
|
| 155 | + $arguments = $this->getArgumentsFor($route['pattern']); |
|
| 156 | 156 | |
| 157 | - $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
| 157 | + $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
| 158 | 158 | |
| 159 | - return $output; |
|
| 159 | + return $output; |
|
| 160 | 160 | |
| 161 | 161 | } else { |
| 162 | - break; |
|
| 162 | + break; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | $output = (string) $this->app->load->action('notFound', 'index', []); |
| 168 | 168 | |
| 169 | 169 | return $output; |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - public function isMatching($pattern) |
|
| 173 | - { |
|
| 172 | + public function isMatching($pattern) |
|
| 173 | + { |
|
| 174 | 174 | $url = $this->app->request->url(); |
| 175 | 175 | |
| 176 | 176 | return preg_match($pattern, $url); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - private function isMatchingRequestMethod($method) |
|
| 180 | - { |
|
| 179 | + private function isMatchingRequestMethod($method) |
|
| 180 | + { |
|
| 181 | 181 | $methods = ['GET', 'POST']; |
| 182 | 182 | |
| 183 | 183 | if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
@@ -186,23 +186,23 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | if (count($method) == 1) { |
| 188 | 188 | |
| 189 | - $method = $method[0]; |
|
| 189 | + $method = $method[0]; |
|
| 190 | 190 | |
| 191 | 191 | } else if (count($method) == 2) { |
| 192 | 192 | |
| 193 | - if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
|
| 193 | + if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
|
| 194 | 194 | |
| 195 | 195 | } else { |
| 196 | 196 | |
| 197 | - return false; |
|
| 197 | + return false; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return $this->app->request->method() == $method; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - public function getArgumentsFor($pattern) |
|
| 205 | - { |
|
| 204 | + public function getArgumentsFor($pattern) |
|
| 205 | + { |
|
| 206 | 206 | $url = $this->app->request->url(); |
| 207 | 207 | |
| 208 | 208 | preg_match($pattern, $url, $matches); |
@@ -210,15 +210,15 @@ discard block |
||
| 210 | 210 | array_shift($matches); |
| 211 | 211 | |
| 212 | 212 | return $matches; |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - public function getCurrent($key) |
|
| 216 | - { |
|
| 215 | + public function getCurrent($key) |
|
| 216 | + { |
|
| 217 | 217 | return $this->current[$key]; |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - private function middleware($middleware, $from = 'admin') |
|
| 221 | - { |
|
| 220 | + private function middleware($middleware, $from = 'admin') |
|
| 221 | + { |
|
| 222 | 222 | $middlewareInterface = 'App\\Middleware\\MiddlewaresInterface'; |
| 223 | 223 | |
| 224 | 224 | $middlewares = $this->app->alias['middlewares'][$from]; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $middlewareClass = $middlewares[$middleware]; |
| 227 | 227 | |
| 228 | 228 | if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
| 229 | - throw new Exception("$middlewareClass not Implement"); |
|
| 229 | + throw new Exception("$middlewareClass not Implement"); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | $middlewareObject = new $middlewareClass; |
@@ -236,5 +236,5 @@ discard block |
||
| 236 | 236 | if ($output && $output === static::NEXT) $output = ''; |
| 237 | 237 | |
| 238 | 238 | return $output; |
| 239 | - } |
|
| 239 | + } |
|
| 240 | 240 | } |
| 241 | 241 | \ No newline at end of file |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function getProperRoute() |
| 123 | 123 | { |
| 124 | - foreach($this->routes as $route) { |
|
| 124 | + foreach ($this->routes as $route) { |
|
| 125 | 125 | |
| 126 | 126 | if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
| 127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | if (is_array($route['middleware'])) { |
| 135 | 135 | |
| 136 | - foreach($route['middleware'] as $middleware) { |
|
| 136 | + foreach ($route['middleware'] as $middleware) { |
|
| 137 | 137 | |
| 138 | 138 | $output = $this->middleware($middleware); |
| 139 | 139 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | $middlewareClass = $middlewares[$middleware]; |
| 227 | 227 | |
| 228 | - if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
| 228 | + if (!in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
| 229 | 229 | throw new Exception("$middlewareClass not Implement"); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -39,7 +39,9 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if ($this->basController) $action = $this->basController . '/' . $action; |
|
| 42 | + if ($this->basController) { |
|
| 43 | + $action = $this->basController . '/' . $action; |
|
| 44 | + } |
|
| 43 | 45 | |
| 44 | 46 | if ($this->groupMiddleware) { |
| 45 | 47 | |
@@ -75,7 +77,9 @@ discard block |
||
| 75 | 77 | $middlewareFrom = array_shift($groupOptions['middleware']); |
| 76 | 78 | $middleware = $groupOptions['middleware']; |
| 77 | 79 | |
| 78 | - if ($this->app->request->url() !== $prefix) return $this; |
|
| 80 | + if ($this->app->request->url() !== $prefix) { |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | $this->prefix = $prefix; |
| 81 | 85 | $this->basController = $controller; |
@@ -137,14 +141,18 @@ discard block |
||
| 137 | 141 | |
| 138 | 142 | $output = $this->middleware($middleware); |
| 139 | 143 | |
| 140 | - if ($output != '') break; |
|
| 144 | + if ($output != '') { |
|
| 145 | + break; |
|
| 146 | + } |
|
| 141 | 147 | } |
| 142 | 148 | |
| 143 | 149 | } else { |
| 144 | 150 | |
| 145 | 151 | $output = $this->middleware($route['middleware']); |
| 146 | 152 | |
| 147 | - if ($output != '') break; |
|
| 153 | + if ($output != '') { |
|
| 154 | + break; |
|
| 155 | + } |
|
| 148 | 156 | } |
| 149 | 157 | } |
| 150 | 158 | |
@@ -180,7 +188,9 @@ discard block |
||
| 180 | 188 | { |
| 181 | 189 | $methods = ['GET', 'POST']; |
| 182 | 190 | |
| 183 | - if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
|
| 191 | + if (($method == 'both') && in_array($this->app->request->method(), $methods)) { |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 184 | 194 | |
| 185 | 195 | if (is_array($method)) { |
| 186 | 196 | |
@@ -190,7 +200,9 @@ discard block |
||
| 190 | 200 | |
| 191 | 201 | } else if (count($method) == 2) { |
| 192 | 202 | |
| 193 | - if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
|
| 203 | + if (in_array($method[0], $methods) && in_array($method[1], $methods)) { |
|
| 204 | + return true; |
|
| 205 | + } |
|
| 194 | 206 | |
| 195 | 207 | } else { |
| 196 | 208 | |
@@ -233,7 +245,9 @@ discard block |
||
| 233 | 245 | |
| 234 | 246 | $output = $middlewareObject->handle($this->app, static::NEXT); |
| 235 | 247 | |
| 236 | - if ($output && $output === static::NEXT) $output = ''; |
|
| 248 | + if ($output && $output === static::NEXT) { |
|
| 249 | + $output = ''; |
|
| 250 | + } |
|
| 237 | 251 | |
| 238 | 252 | return $output; |
| 239 | 253 | } |
@@ -6,15 +6,15 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | class PugView |
| 8 | 8 | { |
| 9 | - private $app; |
|
| 9 | + private $app; |
|
| 10 | 10 | |
| 11 | - public function __construct(Application $app) |
|
| 12 | - { |
|
| 13 | - $this->app = $app; |
|
| 14 | - } |
|
| 11 | + public function __construct(Application $app) |
|
| 12 | + { |
|
| 13 | + $this->app = $app; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function render($path, array $context) |
|
| 17 | - { |
|
| 16 | + public function render($path, array $context) |
|
| 17 | + { |
|
| 18 | 18 | |
| 19 | 19 | $this->app->file->css(); |
| 20 | 20 | $pug = new Pug(array( |
@@ -49,5 +49,5 @@ discard block |
||
| 49 | 49 | ]; |
| 50 | 50 | |
| 51 | 51 | return $pug->render($file, $context); |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | //File Path |
| 31 | 31 | $file = str_replace('/', DS, $path); |
| 32 | - $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
| 32 | + $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
| 33 | 33 | |
| 34 | 34 | //Css Path |
| 35 | 35 | $css = $this->app->file->css(); |
@@ -4,25 +4,25 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Pagination |
| 6 | 6 | { |
| 7 | - private $app; |
|
| 7 | + private $app; |
|
| 8 | 8 | |
| 9 | - private $totalItems; |
|
| 9 | + private $totalItems; |
|
| 10 | 10 | |
| 11 | - private $itemsPerPage = 10; |
|
| 11 | + private $itemsPerPage = 10; |
|
| 12 | 12 | |
| 13 | - private $lastPage; |
|
| 13 | + private $lastPage; |
|
| 14 | 14 | |
| 15 | - private $page = 1; |
|
| 15 | + private $page = 1; |
|
| 16 | 16 | |
| 17 | - public function __construct(Application $app) |
|
| 18 | - { |
|
| 17 | + public function __construct(Application $app) |
|
| 18 | + { |
|
| 19 | 19 | $this->app = $app; |
| 20 | 20 | |
| 21 | 21 | $this->setCurrentPage(); |
| 22 | - } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - private function setCurrentPage() |
|
| 25 | - { |
|
| 24 | + private function setCurrentPage() |
|
| 25 | + { |
|
| 26 | 26 | $page = $this->app->request->get('page'); |
| 27 | 27 | |
| 28 | 28 | if (! is_numeric($page) || $page < 1) { |
@@ -30,61 +30,61 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $this->page = $page; |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function page() |
|
| 36 | - { |
|
| 35 | + public function page() |
|
| 36 | + { |
|
| 37 | 37 | return $this->page; |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function itemsPerPage() |
|
| 41 | - { |
|
| 40 | + public function itemsPerPage() |
|
| 41 | + { |
|
| 42 | 42 | return $this->itemsPerPage; |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function totalItems() |
|
| 46 | - { |
|
| 45 | + public function totalItems() |
|
| 46 | + { |
|
| 47 | 47 | return $this->totalItems; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function last() |
|
| 51 | - { |
|
| 50 | + public function last() |
|
| 51 | + { |
|
| 52 | 52 | return $this->lastPage; |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function next() |
|
| 56 | - { |
|
| 55 | + public function next() |
|
| 56 | + { |
|
| 57 | 57 | return $this->page + 1; |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function prev() |
|
| 61 | - { |
|
| 60 | + public function prev() |
|
| 61 | + { |
|
| 62 | 62 | return $this->page - 1; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function setTotalItems($totalItems) |
|
| 66 | - { |
|
| 65 | + public function setTotalItems($totalItems) |
|
| 66 | + { |
|
| 67 | 67 | $this->totalItems = $totalItems; |
| 68 | 68 | |
| 69 | 69 | return $this; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function setItemsPerPage($itemsPerPage) |
|
| 73 | - { |
|
| 72 | + public function setItemsPerPage($itemsPerPage) |
|
| 73 | + { |
|
| 74 | 74 | $this->itemsPerPage = $itemsPerPage; |
| 75 | 75 | |
| 76 | 76 | return $this; |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function paginate() |
|
| 80 | - { |
|
| 79 | + public function paginate() |
|
| 80 | + { |
|
| 81 | 81 | $this->setLastPage(); |
| 82 | 82 | |
| 83 | 83 | return $this; |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - private function setLastPage() |
|
| 87 | - { |
|
| 86 | + private function setLastPage() |
|
| 87 | + { |
|
| 88 | 88 | $this->lastPage = ceil($this->totalItems / $this->itemsPerPage); |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | \ No newline at end of file |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $page = $this->app->request->get('page'); |
| 27 | 27 | |
| 28 | - if (! is_numeric($page) || $page < 1) { |
|
| 28 | + if (!is_numeric($page) || $page < 1) { |
|
| 29 | 29 | $page = 1; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -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 |