@@ -11,123 +11,123 @@ |
||
| 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) { |
|
| 62 | + foreach (glob("routes/**/*.php") as $route) { |
|
| 63 | 63 | |
| 64 | - $this->file->call($this->file->to($route)); |
|
| 65 | - } |
|
| 64 | + $this->file->call($this->file->to($route)); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $output = $this->route->getProperRoute(); |
|
| 67 | + $output = $this->route->getProperRoute(); |
|
| 68 | 68 | |
| 69 | - $this->response->setOutput($output); |
|
| 69 | + $this->response->setOutput($output); |
|
| 70 | 70 | |
| 71 | - $this->response->send(); |
|
| 72 | - } |
|
| 71 | + $this->response->send(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - private function loadHelpers() |
|
| 75 | - { |
|
| 76 | - $helpers = $this->file->to('Core/helpers', '.php'); |
|
| 74 | + private function loadHelpers() |
|
| 75 | + { |
|
| 76 | + $helpers = $this->file->to('Core/helpers', '.php'); |
|
| 77 | 77 | |
| 78 | - $this->file->call($helpers); |
|
| 79 | - } |
|
| 78 | + $this->file->call($helpers); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function coreClasses() |
|
| 82 | - { |
|
| 83 | - return $this->alias['classes']; |
|
| 84 | - } |
|
| 81 | + public function coreClasses() |
|
| 82 | + { |
|
| 83 | + return $this->alias['classes']; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function share($key, $value) |
|
| 87 | - { |
|
| 88 | - if ($value instanceof Closure) { |
|
| 86 | + public function share($key, $value) |
|
| 87 | + { |
|
| 88 | + if ($value instanceof Closure) { |
|
| 89 | 89 | |
| 90 | - $value = call_user_func($value, $this); |
|
| 91 | - } |
|
| 90 | + $value = call_user_func($value, $this); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $this->container[$key] = $value; |
|
| 94 | - } |
|
| 93 | + $this->container[$key] = $value; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function get($key) |
|
| 97 | - { |
|
| 98 | - if (! $this->isSharing($key)) { |
|
| 96 | + public function get($key) |
|
| 97 | + { |
|
| 98 | + if (! $this->isSharing($key)) { |
|
| 99 | 99 | |
| 100 | - if ($this->isCoreAlias($key)) { |
|
| 100 | + if ($this->isCoreAlias($key)) { |
|
| 101 | 101 | |
| 102 | - $this->share($key, $this->createObject($key)); |
|
| 102 | + $this->share($key, $this->createObject($key)); |
|
| 103 | 103 | |
| 104 | - } else { |
|
| 104 | + } else { |
|
| 105 | 105 | |
| 106 | - throw new Exception("$key is not found"); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - return $this->container[$key]; |
|
| 110 | - } |
|
| 106 | + throw new Exception("$key is not found"); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + return $this->container[$key]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - public function isSharing($key) |
|
| 113 | - { |
|
| 114 | - return isset($this->container[$key]); |
|
| 115 | - } |
|
| 112 | + public function isSharing($key) |
|
| 113 | + { |
|
| 114 | + return isset($this->container[$key]); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function isCoreAlias($key) |
|
| 118 | - { |
|
| 119 | - return isset($this->coreClasses()[$key]); |
|
| 120 | - } |
|
| 117 | + public function isCoreAlias($key) |
|
| 118 | + { |
|
| 119 | + return isset($this->coreClasses()[$key]); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - public function createObject($key) |
|
| 123 | - { |
|
| 124 | - $object = $this->coreClasses()[$key]; |
|
| 122 | + public function createObject($key) |
|
| 123 | + { |
|
| 124 | + $object = $this->coreClasses()[$key]; |
|
| 125 | 125 | |
| 126 | - return new $object($this); |
|
| 127 | - } |
|
| 126 | + return new $object($this); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public function __get($key) |
|
| 130 | - { |
|
| 131 | - return $this->get($key); |
|
| 132 | - } |
|
| 129 | + public function __get($key) |
|
| 130 | + { |
|
| 131 | + return $this->get($key); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | \ No newline at end of file |
@@ -4,31 +4,31 @@ |
||
| 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') { |
|
| 24 | + public function redirectTo($path, $num = 0) |
|
| 25 | + { |
|
| 26 | + if ($path == 'error') { |
|
| 27 | 27 | |
| 28 | - $this->app->session->set('error', true); |
|
| 29 | - } |
|
| 28 | + $this->app->session->set('error', true); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
|
| 32 | - exit; |
|
| 33 | - } |
|
| 31 | + header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
|
| 32 | + exit; |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -4,125 +4,125 @@ |
||
| 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 | - { |
|
| 13 | - $this->app = $app; |
|
| 14 | - } |
|
| 11 | + public function __construct(Application $app) |
|
| 12 | + { |
|
| 13 | + $this->app = $app; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function __get($key) |
|
| 17 | - { |
|
| 18 | - return $this->app->get($key); |
|
| 19 | - } |
|
| 16 | + public function __get($key) |
|
| 17 | + { |
|
| 18 | + return $this->app->get($key); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function __call($method, $args) |
|
| 22 | - { |
|
| 23 | - return call_user_func_array([$this->app->db, $method], $args); |
|
| 24 | - } |
|
| 21 | + public function __call($method, $args) |
|
| 22 | + { |
|
| 23 | + return call_user_func_array([$this->app->db, $method], $args); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function all($limit = null) |
|
| 27 | - { |
|
| 28 | - return $this->orderBy('id', 'DESC')->limit($limit)->fetchAll($this->table); |
|
| 29 | - } |
|
| 26 | + public function all($limit = null) |
|
| 27 | + { |
|
| 28 | + return $this->orderBy('id', 'DESC')->limit($limit)->fetchAll($this->table); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function allEnable($limit = null) |
|
| 32 | - { |
|
| 33 | - return $this->orderBy('id', 'DESC')->where('enable = ?', 1)->limit($limit)->fetchAll($this->table); |
|
| 34 | - } |
|
| 31 | + public function allEnable($limit = null) |
|
| 32 | + { |
|
| 33 | + return $this->orderBy('id', 'DESC')->where('enable = ?', 1)->limit($limit)->fetchAll($this->table); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function get($value, $coulmn = 'id') |
|
| 37 | - { |
|
| 38 | - return $this->where($coulmn . ' = ?' , $value)->fetch($this->table); |
|
| 39 | - } |
|
| 36 | + public function get($value, $coulmn = 'id') |
|
| 37 | + { |
|
| 38 | + return $this->where($coulmn . ' = ?' , $value)->fetch($this->table); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function getEnable($value, $coulmn = 'id') |
|
| 42 | - { |
|
| 43 | - return $this->where($coulmn . ' = ? AND enable = ?' , [$value, 1])->fetch($this->table); |
|
| 44 | - } |
|
| 41 | + public function getEnable($value, $coulmn = 'id') |
|
| 42 | + { |
|
| 43 | + return $this->where($coulmn . ' = ? AND enable = ?' , [$value, 1])->fetch($this->table); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function selectTable($coulmn) |
|
| 47 | - { |
|
| 48 | - return $this->select($coulmn)->fetchAll($this->table); |
|
| 49 | - } |
|
| 46 | + public function selectTable($coulmn) |
|
| 47 | + { |
|
| 48 | + return $this->select($coulmn)->fetchAll($this->table); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function exists($value, $key = 'id') |
|
| 52 | - { |
|
| 53 | - return (bool) $this->select($key)->where($key .'=?' , $value)->fetch($this->table); |
|
| 54 | - } |
|
| 51 | + public function exists($value, $key = 'id') |
|
| 52 | + { |
|
| 53 | + return (bool) $this->select($key)->where($key .'=?' , $value)->fetch($this->table); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function delete($id) |
|
| 57 | - { |
|
| 58 | - return $this->where('id = ?' , $id)->delete($this->table); |
|
| 59 | - } |
|
| 56 | + public function delete($id) |
|
| 57 | + { |
|
| 58 | + return $this->where('id = ?' , $id)->delete($this->table); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function hasOne($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 62 | - { |
|
| 63 | - $join = rtrim($join, 'Model'); |
|
| 61 | + public function hasOne($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 62 | + { |
|
| 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 | - $exists = $this->app->file->exists($file); |
|
| 67 | + $exists = $this->app->file->exists($file); |
|
| 68 | 68 | |
| 69 | - if (! $exists) { |
|
| 70 | - return $join . ' Not Found'; |
|
| 71 | - } |
|
| 69 | + if (! $exists) { |
|
| 70 | + return $join . ' Not Found'; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $trace = debug_backtrace(); |
|
| 73 | + $trace = debug_backtrace(); |
|
| 74 | 74 | |
| 75 | - $table = $trace[1]['object']->table; |
|
| 75 | + $table = $trace[1]['object']->table; |
|
| 76 | 76 | |
| 77 | - $join = $this->load->model($join)->table; |
|
| 77 | + $join = $this->load->model($join)->table; |
|
| 78 | 78 | |
| 79 | - return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetch(); |
|
| 80 | - } |
|
| 79 | + return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetch(); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function hasMany($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 83 | - { |
|
| 84 | - $join = rtrim($join, 'Model'); |
|
| 82 | + public function hasMany($join, $id = null, $select = '*', $limit = null, $localId = null, $forginId = null) |
|
| 83 | + { |
|
| 84 | + $join = rtrim($join, 'Model'); |
|
| 85 | 85 | |
| 86 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 86 | + $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 87 | 87 | |
| 88 | - $exists = $this->app->file->exists($file); |
|
| 88 | + $exists = $this->app->file->exists($file); |
|
| 89 | 89 | |
| 90 | - if (! $exists) { |
|
| 91 | - return $join . ' Not Found'; |
|
| 92 | - } |
|
| 90 | + if (! $exists) { |
|
| 91 | + return $join . ' Not Found'; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $trace = debug_backtrace(); |
|
| 94 | + $trace = debug_backtrace(); |
|
| 95 | 95 | |
| 96 | - $table = $trace[1]['object']->table; |
|
| 96 | + $table = $trace[1]['object']->table; |
|
| 97 | 97 | |
| 98 | - $join = $this->load->model($join)->table; |
|
| 98 | + $join = $this->load->model($join)->table; |
|
| 99 | 99 | |
| 100 | - return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetchAll(); |
|
| 101 | - } |
|
| 100 | + return $this->db->select($select)->from($table)->join($join, $localId, $forginId)->where($table . '.id = ?', $id)->limit($limit)->fetchAll(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - public function join($join, $limit = null, $enable = null, $localId = null, $forginId = null) |
|
| 104 | - { |
|
| 105 | - $join = rtrim($join, 'Model'); |
|
| 103 | + public function join($join, $limit = null, $enable = null, $localId = null, $forginId = null) |
|
| 104 | + { |
|
| 105 | + $join = rtrim($join, 'Model'); |
|
| 106 | 106 | |
| 107 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 107 | + $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 108 | 108 | |
| 109 | - $exists = $this->app->file->exists($file); |
|
| 109 | + $exists = $this->app->file->exists($file); |
|
| 110 | 110 | |
| 111 | - if (! $exists) { |
|
| 112 | - return $join . ' Not Found'; |
|
| 113 | - } |
|
| 111 | + if (! $exists) { |
|
| 112 | + return $join . ' Not Found'; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - $trace = debug_backtrace(); |
|
| 115 | + $trace = debug_backtrace(); |
|
| 116 | 116 | |
| 117 | - $table = $trace[1]['object']->table; |
|
| 117 | + $table = $trace[1]['object']->table; |
|
| 118 | 118 | |
| 119 | - $join = $this->load->model($join)->table; |
|
| 119 | + $join = $this->load->model($join)->table; |
|
| 120 | 120 | |
| 121 | - if ($enable) { |
|
| 121 | + if ($enable) { |
|
| 122 | 122 | |
| 123 | - return $this->db->select()->from($table)->join($join, $localId, $forginId)->where('enable = ?', 1)->limit($limit)->fetchAll(); |
|
| 124 | - } |
|
| 123 | + return $this->db->select()->from($table)->join($join, $localId, $forginId)->where('enable = ?', 1)->limit($limit)->fetchAll(); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $this->db->select()->from($table)->join($join, $localId, $forginId)->limit($limit)->fetchAll(); |
|
| 127 | - } |
|
| 126 | + return $this->db->select()->from($table)->join($join, $localId, $forginId)->limit($limit)->fetchAll(); |
|
| 127 | + } |
|
| 128 | 128 | } |
| 129 | 129 | \ 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) { |
|
| 69 | + if (!$exists) { |
|
| 70 | 70 | return $join . ' Not Found'; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $join = rtrim($join, 'Model'); |
| 85 | 85 | |
| 86 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 86 | + $file = $this->app->file->to('App/Models/' . $join . 'Model', '.php'); |
|
| 87 | 87 | |
| 88 | 88 | $exists = $this->app->file->exists($file); |
| 89 | 89 | |
| 90 | - if (! $exists) { |
|
| 90 | + if (!$exists) { |
|
| 91 | 91 | return $join . ' Not Found'; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | { |
| 105 | 105 | $join = rtrim($join, 'Model'); |
| 106 | 106 | |
| 107 | - $file = $this->app->file->to( 'App/Models/' . $join . 'Model', '.php'); |
|
| 107 | + $file = $this->app->file->to('App/Models/' . $join . 'Model', '.php'); |
|
| 108 | 108 | |
| 109 | 109 | $exists = $this->app->file->exists($file); |
| 110 | 110 | |
| 111 | - if (! $exists) { |
|
| 111 | + if (!$exists) { |
|
| 112 | 112 | return $join . ' Not Found'; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -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 | - { |
|
| 13 | - $this->app = $app; |
|
| 11 | + public function __construct(Application $app) |
|
| 12 | + { |
|
| 13 | + $this->app = $app; |
|
| 14 | 14 | |
| 15 | - $this->path = dirname($this->app->request->server('SCRIPT_NAME')) ?: '/'; |
|
| 16 | - } |
|
| 15 | + $this->path = dirname($this->app->request->server('SCRIPT_NAME')) ?: '/'; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function set($key, $value, $hours = 1800) |
|
| 19 | - { |
|
| 20 | - $expireTime = $hours == -1 ? -1 : time() + $hours * 3600; |
|
| 18 | + public function set($key, $value, $hours = 1800) |
|
| 19 | + { |
|
| 20 | + $expireTime = $hours == -1 ? -1 : time() + $hours * 3600; |
|
| 21 | 21 | |
| 22 | - setcookie($key, $value, $expireTime, $this->path, '', false, true); |
|
| 23 | - } |
|
| 22 | + setcookie($key, $value, $expireTime, $this->path, '', false, true); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function get($key , $default = null) |
|
| 26 | - { |
|
| 27 | - return array_get($_COOKIE, $key, $default); |
|
| 28 | - } |
|
| 25 | + public function get($key , $default = null) |
|
| 26 | + { |
|
| 27 | + return array_get($_COOKIE, $key, $default); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function has($key) |
|
| 31 | - { |
|
| 32 | - return array_key_exists($key, $_COOKIE); |
|
| 33 | - } |
|
| 30 | + public function has($key) |
|
| 31 | + { |
|
| 32 | + return array_key_exists($key, $_COOKIE); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function remove($key) |
|
| 36 | - { |
|
| 37 | - $this->set($key, null, -1); |
|
| 35 | + public function remove($key) |
|
| 36 | + { |
|
| 37 | + $this->set($key, null, -1); |
|
| 38 | 38 | |
| 39 | - unset($_COOKIE[$key]); |
|
| 40 | - } |
|
| 39 | + unset($_COOKIE[$key]); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function all() |
|
| 43 | - { |
|
| 44 | - return $_COOKIE; |
|
| 45 | - } |
|
| 42 | + public function all() |
|
| 43 | + { |
|
| 44 | + return $_COOKIE; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function destroy() |
|
| 48 | - { |
|
| 49 | - foreach (array_keys($this->all()) as $key) { |
|
| 47 | + public function destroy() |
|
| 48 | + { |
|
| 49 | + foreach (array_keys($this->all()) as $key) { |
|
| 50 | 50 | |
| 51 | - $this->remove($key); |
|
| 52 | - } |
|
| 51 | + $this->remove($key); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - unset($_COOKIE); |
|
| 55 | - } |
|
| 54 | + unset($_COOKIE); |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -6,144 +6,144 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Request |
| 8 | 8 | { |
| 9 | - private $app; |
|
| 9 | + private $app; |
|
| 10 | 10 | |
| 11 | - private $url; |
|
| 11 | + private $url; |
|
| 12 | 12 | |
| 13 | - private $baseUrl; |
|
| 13 | + private $baseUrl; |
|
| 14 | 14 | |
| 15 | - private $files = []; |
|
| 15 | + private $files = []; |
|
| 16 | 16 | |
| 17 | - private $link; |
|
| 17 | + private $link; |
|
| 18 | 18 | |
| 19 | - public function __construct(Application $app) |
|
| 20 | - { |
|
| 21 | - $this->app = $app; |
|
| 22 | - } |
|
| 19 | + public function __construct(Application $app) |
|
| 20 | + { |
|
| 21 | + $this->app = $app; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function prepareUrl() |
|
| 25 | - { |
|
| 26 | - $script = dirname($this->server('SCRIPT_NAME')); |
|
| 24 | + public function prepareUrl() |
|
| 25 | + { |
|
| 26 | + $script = dirname($this->server('SCRIPT_NAME')); |
|
| 27 | 27 | |
| 28 | - $requestUri = $this->server('REQUEST_URI'); |
|
| 28 | + $requestUri = $this->server('REQUEST_URI'); |
|
| 29 | 29 | |
| 30 | - if (strpos($requestUri, '?')) { |
|
| 30 | + if (strpos($requestUri, '?')) { |
|
| 31 | 31 | |
| 32 | - list($requestUri, $queryString) = explode('?', $requestUri); |
|
| 33 | - } |
|
| 32 | + list($requestUri, $queryString) = explode('?', $requestUri); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - if (! in_array($script, ['/', '\\'])) { |
|
| 35 | + if (! in_array($script, ['/', '\\'])) { |
|
| 36 | 36 | |
| 37 | - $this->url = preg_replace('#^' . $script . '#', '', $requestUri); |
|
| 38 | - } else { |
|
| 37 | + $this->url = preg_replace('#^' . $script . '#', '', $requestUri); |
|
| 38 | + } else { |
|
| 39 | 39 | |
| 40 | - $this->url = $requestUri; |
|
| 41 | - } |
|
| 40 | + $this->url = $requestUri; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if ($this->url !== '/') { |
|
| 43 | + if ($this->url !== '/') { |
|
| 44 | 44 | |
| 45 | - $this->url = rtrim($this->url, '/'); |
|
| 46 | - } |
|
| 45 | + $this->url = rtrim($this->url, '/'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $isSecure = false; |
|
| 48 | + $isSecure = false; |
|
| 49 | 49 | |
| 50 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 50 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 51 | 51 | |
| 52 | - $isSecure = true; |
|
| 52 | + $isSecure = true; |
|
| 53 | 53 | |
| 54 | - } elseif ((! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) || (! empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')) { |
|
| 55 | - $isSecure = true; |
|
| 56 | - } |
|
| 54 | + } elseif ((! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) || (! empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')) { |
|
| 55 | + $isSecure = true; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $REQUEST_PROTOCOL = $isSecure ? 'https' : 'http'; |
|
| 58 | + $REQUEST_PROTOCOL = $isSecure ? 'https' : 'http'; |
|
| 59 | 59 | |
| 60 | - $this->link = $REQUEST_PROTOCOL . '://' . $this->server('HTTP_HOST'); |
|
| 60 | + $this->link = $REQUEST_PROTOCOL . '://' . $this->server('HTTP_HOST'); |
|
| 61 | 61 | |
| 62 | - $this->baseUrl = $this->link . $requestUri; |
|
| 63 | - } |
|
| 62 | + $this->baseUrl = $this->link . $requestUri; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function get($key) |
|
| 66 | - { |
|
| 67 | - $value = array_get($_GET, $key); |
|
| 65 | + public function get($key) |
|
| 66 | + { |
|
| 67 | + $value = array_get($_GET, $key); |
|
| 68 | 68 | |
| 69 | - if (is_array($value)) { |
|
| 70 | - $value = array_filter($value); |
|
| 71 | - } else { |
|
| 72 | - $value = trim($value); |
|
| 73 | - } |
|
| 69 | + if (is_array($value)) { |
|
| 70 | + $value = array_filter($value); |
|
| 71 | + } else { |
|
| 72 | + $value = trim($value); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $value; |
|
| 76 | - } |
|
| 75 | + return $value; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function post($key) |
|
| 79 | - { |
|
| 80 | - $value = array_get($_POST, $key); |
|
| 78 | + public function post($key) |
|
| 79 | + { |
|
| 80 | + $value = array_get($_POST, $key); |
|
| 81 | 81 | |
| 82 | - if (is_array($value)) { |
|
| 83 | - $value = array_filter($value); |
|
| 84 | - } else { |
|
| 85 | - $value = trim($value); |
|
| 86 | - } |
|
| 82 | + if (is_array($value)) { |
|
| 83 | + $value = array_filter($value); |
|
| 84 | + } else { |
|
| 85 | + $value = trim($value); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return $value; |
|
| 89 | - } |
|
| 88 | + return $value; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - public function setPost($key, $value) |
|
| 92 | - { |
|
| 93 | - $_POST[$key] = $value; |
|
| 94 | - } |
|
| 91 | + public function setPost($key, $value) |
|
| 92 | + { |
|
| 93 | + $_POST[$key] = $value; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function posts() |
|
| 97 | - { |
|
| 98 | - return $_POST; |
|
| 99 | - } |
|
| 96 | + public function posts() |
|
| 97 | + { |
|
| 98 | + return $_POST; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function files() |
|
| 102 | - { |
|
| 103 | - return $_FILES; |
|
| 104 | - } |
|
| 101 | + public function files() |
|
| 102 | + { |
|
| 103 | + return $_FILES; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function file($input) |
|
| 107 | - { |
|
| 108 | - if (isset($this->files[$input])) { |
|
| 106 | + public function file($input) |
|
| 107 | + { |
|
| 108 | + if (isset($this->files[$input])) { |
|
| 109 | 109 | |
| 110 | - return $this->files[$input]; |
|
| 111 | - } |
|
| 110 | + return $this->files[$input]; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - $upoadedFile = new UploadeFile($this->app, $input); |
|
| 113 | + $upoadedFile = new UploadeFile($this->app, $input); |
|
| 114 | 114 | |
| 115 | - $this->files[$input] = $upoadedFile; |
|
| 115 | + $this->files[$input] = $upoadedFile; |
|
| 116 | 116 | |
| 117 | - return $this->files[$input]; |
|
| 118 | - } |
|
| 117 | + return $this->files[$input]; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - public function server($key) |
|
| 121 | - { |
|
| 122 | - return array_get($_SERVER, $key); |
|
| 123 | - } |
|
| 120 | + public function server($key) |
|
| 121 | + { |
|
| 122 | + return array_get($_SERVER, $key); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function method() |
|
| 126 | - { |
|
| 127 | - return $this->server('REQUEST_METHOD'); |
|
| 128 | - } |
|
| 125 | + public function method() |
|
| 126 | + { |
|
| 127 | + return $this->server('REQUEST_METHOD'); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - public function referer() |
|
| 131 | - { |
|
| 132 | - return $this->server('HTTP_REFERER'); |
|
| 133 | - } |
|
| 130 | + public function referer() |
|
| 131 | + { |
|
| 132 | + return $this->server('HTTP_REFERER'); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - public function baseUrl() |
|
| 136 | - { |
|
| 137 | - return $this->baseUrl; |
|
| 138 | - } |
|
| 135 | + public function baseUrl() |
|
| 136 | + { |
|
| 137 | + return $this->baseUrl; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public function url() |
|
| 141 | - { |
|
| 142 | - return $this->url; |
|
| 143 | - } |
|
| 140 | + public function url() |
|
| 141 | + { |
|
| 142 | + return $this->url; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - public function link() |
|
| 146 | - { |
|
| 147 | - return $this->link; |
|
| 148 | - } |
|
| 145 | + public function link() |
|
| 146 | + { |
|
| 147 | + return $this->link; |
|
| 148 | + } |
|
| 149 | 149 | } |
| 150 | 150 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | list($requestUri, $queryString) = explode('?', $requestUri); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if (! in_array($script, ['/', '\\'])) { |
|
| 35 | + if (!in_array($script, ['/', '\\'])) { |
|
| 36 | 36 | |
| 37 | 37 | $this->url = preg_replace('#^' . $script . '#', '', $requestUri); |
| 38 | 38 | } else { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $isSecure = true; |
| 53 | 53 | |
| 54 | - } elseif ((! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) || (! empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')) { |
|
| 54 | + } elseif ((!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')) { |
|
| 55 | 55 | $isSecure = true; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -6,122 +6,122 @@ |
||
| 6 | 6 | |
| 7 | 7 | class UploadeFile |
| 8 | 8 | { |
| 9 | - private $app; |
|
| 9 | + private $app; |
|
| 10 | 10 | |
| 11 | - private $file = []; |
|
| 11 | + private $file = []; |
|
| 12 | 12 | |
| 13 | - private $fileName; |
|
| 13 | + private $fileName; |
|
| 14 | 14 | |
| 15 | - private $nameOnly; |
|
| 15 | + private $nameOnly; |
|
| 16 | 16 | |
| 17 | - private $extension; |
|
| 17 | + private $extension; |
|
| 18 | 18 | |
| 19 | - private $minetype; |
|
| 19 | + private $minetype; |
|
| 20 | 20 | |
| 21 | - private $tempFile; |
|
| 21 | + private $tempFile; |
|
| 22 | 22 | |
| 23 | - private $size; |
|
| 23 | + private $size; |
|
| 24 | 24 | |
| 25 | - private $error; |
|
| 25 | + private $error; |
|
| 26 | 26 | |
| 27 | - private const AllOW_EXTENSION = ['png', 'jpg', 'jpeg', 'gif', 'webp']; |
|
| 27 | + private const AllOW_EXTENSION = ['png', 'jpg', 'jpeg', 'gif', 'webp']; |
|
| 28 | 28 | |
| 29 | - public function __construct(Application $app, $input) |
|
| 30 | - { |
|
| 31 | - $this->app = $app; |
|
| 29 | + public function __construct(Application $app, $input) |
|
| 30 | + { |
|
| 31 | + $this->app = $app; |
|
| 32 | 32 | |
| 33 | - $this->getFileInfo($input); |
|
| 34 | - } |
|
| 33 | + $this->getFileInfo($input); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - private function getFileInfo($input) |
|
| 37 | - { |
|
| 38 | - if (empty($_FILES[$input])) { |
|
| 39 | - return; |
|
| 40 | - } |
|
| 36 | + private function getFileInfo($input) |
|
| 37 | + { |
|
| 38 | + if (empty($_FILES[$input])) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $file = $_FILES[$input]; |
|
| 42 | + $file = $_FILES[$input]; |
|
| 43 | 43 | |
| 44 | - $this->error = $file['error']; |
|
| 44 | + $this->error = $file['error']; |
|
| 45 | 45 | |
| 46 | - if ($this->error != UPLOAD_ERR_OK) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 46 | + if ($this->error != UPLOAD_ERR_OK) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $this->file = $file; |
|
| 50 | + $this->file = $file; |
|
| 51 | 51 | |
| 52 | - $this->fileName = $this->file['name']; |
|
| 52 | + $this->fileName = $this->file['name']; |
|
| 53 | 53 | |
| 54 | - $this->minetype = $this->file['type']; |
|
| 54 | + $this->minetype = $this->file['type']; |
|
| 55 | 55 | |
| 56 | - $this->size = $this->file['size']; |
|
| 56 | + $this->size = $this->file['size']; |
|
| 57 | 57 | |
| 58 | - $this->tempFile = $this->file['tmp_name']; |
|
| 58 | + $this->tempFile = $this->file['tmp_name']; |
|
| 59 | 59 | |
| 60 | - $fileInfo = pathinfo($this->fileName); |
|
| 60 | + $fileInfo = pathinfo($this->fileName); |
|
| 61 | 61 | |
| 62 | - $this->nameOnly = $fileInfo['filename']; |
|
| 62 | + $this->nameOnly = $fileInfo['filename']; |
|
| 63 | 63 | |
| 64 | - $this->extension = $fileInfo['extension']; |
|
| 65 | - } |
|
| 64 | + $this->extension = $fileInfo['extension']; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function exists() |
|
| 68 | - { |
|
| 69 | - return ! empty($this->file); |
|
| 70 | - } |
|
| 67 | + public function exists() |
|
| 68 | + { |
|
| 69 | + return ! empty($this->file); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function getFileName() |
|
| 73 | - { |
|
| 74 | - return $this->fileName; |
|
| 75 | - } |
|
| 72 | + public function getFileName() |
|
| 73 | + { |
|
| 74 | + return $this->fileName; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function getNameOnly() |
|
| 78 | - { |
|
| 79 | - return $this->nameOnly; |
|
| 80 | - } |
|
| 77 | + public function getNameOnly() |
|
| 78 | + { |
|
| 79 | + return $this->nameOnly; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function getExtension() |
|
| 83 | - { |
|
| 84 | - return $this->extension; |
|
| 85 | - } |
|
| 82 | + public function getExtension() |
|
| 83 | + { |
|
| 84 | + return $this->extension; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function getMinetype() |
|
| 88 | - { |
|
| 89 | - return $this->minetype; |
|
| 90 | - } |
|
| 87 | + public function getMinetype() |
|
| 88 | + { |
|
| 89 | + return $this->minetype; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function getSize() |
|
| 93 | - { |
|
| 94 | - return $this->size; |
|
| 95 | - } |
|
| 92 | + public function getSize() |
|
| 93 | + { |
|
| 94 | + return $this->size; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function getTempFile() |
|
| 98 | - { |
|
| 99 | - return $this->tempFile; |
|
| 100 | - } |
|
| 97 | + public function getTempFile() |
|
| 98 | + { |
|
| 99 | + return $this->tempFile; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - public function isImage() |
|
| 103 | - { |
|
| 104 | - return strpos($this->minetype, 'image/') === 0 && in_array($this->extension, self::AllOW_EXTENSION); |
|
| 105 | - } |
|
| 102 | + public function isImage() |
|
| 103 | + { |
|
| 104 | + return strpos($this->minetype, 'image/') === 0 && in_array($this->extension, self::AllOW_EXTENSION); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function moveTo($target, $newName = null) |
|
| 108 | - { |
|
| 109 | - $newName = $newName ?: sha1(rand()) . sha1(rand()); |
|
| 107 | + public function moveTo($target, $newName = null) |
|
| 108 | + { |
|
| 109 | + $newName = $newName ?: sha1(rand()) . sha1(rand()); |
|
| 110 | 110 | |
| 111 | - $newName .= '.' . $this->extension; |
|
| 111 | + $newName .= '.' . $this->extension; |
|
| 112 | 112 | |
| 113 | - if (! is_dir($target)) { |
|
| 113 | + if (! is_dir($target)) { |
|
| 114 | 114 | |
| 115 | - mkdir($target, 0777, true); |
|
| 116 | - } |
|
| 115 | + mkdir($target, 0777, true); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - $filePath = $target . $newName; |
|
| 118 | + $filePath = $target . $newName; |
|
| 119 | 119 | |
| 120 | - $filePath = rtrim($filePath, '/'); |
|
| 121 | - $filePath = ltrim($filePath, '/'); |
|
| 120 | + $filePath = rtrim($filePath, '/'); |
|
| 121 | + $filePath = ltrim($filePath, '/'); |
|
| 122 | 122 | |
| 123 | - $uploade = move_uploaded_file($this->tempFile, $filePath); |
|
| 123 | + $uploade = move_uploaded_file($this->tempFile, $filePath); |
|
| 124 | 124 | |
| 125 | - return $uploade; |
|
| 126 | - } |
|
| 125 | + return $uploade; |
|
| 126 | + } |
|
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | public function exists() |
| 68 | 68 | { |
| 69 | - return ! empty($this->file); |
|
| 69 | + return !empty($this->file); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function getFileName() |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $newName .= '.' . $this->extension; |
| 112 | 112 | |
| 113 | - if (! is_dir($target)) { |
|
| 113 | + if (!is_dir($target)) { |
|
| 114 | 114 | |
| 115 | 115 | mkdir($target, 0777, true); |
| 116 | 116 | } |
@@ -8,403 +8,403 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Database |
| 10 | 10 | { |
| 11 | - private $app; |
|
| 11 | + private $app; |
|
| 12 | 12 | |
| 13 | - private static $connection; |
|
| 13 | + private static $connection; |
|
| 14 | 14 | |
| 15 | - private $table; |
|
| 15 | + private $table; |
|
| 16 | 16 | |
| 17 | - private $rows; |
|
| 17 | + private $rows; |
|
| 18 | 18 | |
| 19 | - private $lastId; |
|
| 19 | + private $lastId; |
|
| 20 | 20 | |
| 21 | - private $data = []; |
|
| 21 | + private $data = []; |
|
| 22 | 22 | |
| 23 | - private $bindings = []; |
|
| 23 | + private $bindings = []; |
|
| 24 | 24 | |
| 25 | - private $selects = []; |
|
| 25 | + private $selects = []; |
|
| 26 | 26 | |
| 27 | - private $joins = []; |
|
| 27 | + private $joins = []; |
|
| 28 | 28 | |
| 29 | - private $wheres = []; |
|
| 29 | + private $wheres = []; |
|
| 30 | 30 | |
| 31 | - private $havings = []; |
|
| 31 | + private $havings = []; |
|
| 32 | 32 | |
| 33 | - private $orderBy = []; |
|
| 33 | + private $orderBy = []; |
|
| 34 | 34 | |
| 35 | - private $limit; |
|
| 35 | + private $limit; |
|
| 36 | 36 | |
| 37 | - private $offset; |
|
| 37 | + private $offset; |
|
| 38 | 38 | |
| 39 | - private $groupBy = []; |
|
| 39 | + private $groupBy = []; |
|
| 40 | 40 | |
| 41 | - public function __construct(Application $app) |
|
| 42 | - { |
|
| 43 | - $this->app = $app; |
|
| 41 | + public function __construct(Application $app) |
|
| 42 | + { |
|
| 43 | + $this->app = $app; |
|
| 44 | 44 | |
| 45 | - if (! $this->isConnected()) { |
|
| 46 | - $this->connect(); |
|
| 47 | - } |
|
| 48 | - } |
|
| 45 | + if (! $this->isConnected()) { |
|
| 46 | + $this->connect(); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - private function isConnected() |
|
| 51 | - { |
|
| 52 | - return self::$connection instanceof PDO; |
|
| 53 | - } |
|
| 50 | + private function isConnected() |
|
| 51 | + { |
|
| 52 | + return self::$connection instanceof PDO; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - private function connect() |
|
| 56 | - { |
|
| 57 | - $data = $this->app->config['db']; |
|
| 55 | + private function connect() |
|
| 56 | + { |
|
| 57 | + $data = $this->app->config['db']; |
|
| 58 | 58 | |
| 59 | - extract($data); |
|
| 59 | + extract($data); |
|
| 60 | 60 | |
| 61 | - try { |
|
| 62 | - self::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
| 61 | + try { |
|
| 62 | + self::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
| 63 | 63 | |
| 64 | - self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 64 | + self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 65 | 65 | |
| 66 | - self::$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
| 66 | + self::$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
| 67 | 67 | |
| 68 | - self::$connection->exec('SET NAMES utf8'); |
|
| 68 | + self::$connection->exec('SET NAMES utf8'); |
|
| 69 | 69 | |
| 70 | - } catch (PDOException $e) { |
|
| 70 | + } catch (PDOException $e) { |
|
| 71 | 71 | |
| 72 | - throw new Exception($e->getMessage()); |
|
| 73 | - } |
|
| 74 | - } |
|
| 72 | + throw new Exception($e->getMessage()); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - public function connection() |
|
| 77 | - { |
|
| 78 | - return self::$connection; |
|
| 79 | - } |
|
| 76 | + public function connection() |
|
| 77 | + { |
|
| 78 | + return self::$connection; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function table($table) |
|
| 82 | - { |
|
| 83 | - $this->table = $table; |
|
| 81 | + public function table($table) |
|
| 82 | + { |
|
| 83 | + $this->table = $table; |
|
| 84 | 84 | |
| 85 | - return $this; |
|
| 86 | - } |
|
| 85 | + return $this; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function select(...$select) |
|
| 89 | - { |
|
| 90 | - $this->selects = array_merge($this->selects, $select); |
|
| 88 | + public function select(...$select) |
|
| 89 | + { |
|
| 90 | + $this->selects = array_merge($this->selects, $select); |
|
| 91 | 91 | |
| 92 | - return $this; |
|
| 93 | - } |
|
| 92 | + return $this; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function join($join, $localId = null, $forginId = null) |
|
| 96 | - { |
|
| 97 | - if (! $localId) { |
|
| 95 | + public function join($join, $localId = null, $forginId = null) |
|
| 96 | + { |
|
| 97 | + if (! $localId) { |
|
| 98 | 98 | |
| 99 | - $localId = trim($join, 's' ). '_id'; |
|
| 100 | - } |
|
| 99 | + $localId = trim($join, 's' ). '_id'; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - if (! $forginId) { |
|
| 102 | + if (! $forginId) { |
|
| 103 | 103 | |
| 104 | - $forginId = 'id'; |
|
| 105 | - } |
|
| 104 | + $forginId = 'id'; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - $sql = $join . ' ON ' . $this->table . '.' . $localId . ' = ' . $join . '.' . $forginId; |
|
| 107 | + $sql = $join . ' ON ' . $this->table . '.' . $localId . ' = ' . $join . '.' . $forginId; |
|
| 108 | 108 | |
| 109 | - $this->joins[] = $sql; |
|
| 109 | + $this->joins[] = $sql; |
|
| 110 | 110 | |
| 111 | - return $this; |
|
| 112 | - } |
|
| 111 | + return $this; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - public function where(...$bindings) |
|
| 115 | - { |
|
| 116 | - $sql = array_shift($bindings); |
|
| 114 | + public function where(...$bindings) |
|
| 115 | + { |
|
| 116 | + $sql = array_shift($bindings); |
|
| 117 | 117 | |
| 118 | - if (is_array($bindings[0])) { |
|
| 118 | + if (is_array($bindings[0])) { |
|
| 119 | 119 | |
| 120 | - $bindings = $bindings[0]; |
|
| 121 | - } |
|
| 120 | + $bindings = $bindings[0]; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - $this->addToBindings($bindings); |
|
| 123 | + $this->addToBindings($bindings); |
|
| 124 | 124 | |
| 125 | - $this->wheres[] = $sql; |
|
| 125 | + $this->wheres[] = $sql; |
|
| 126 | 126 | |
| 127 | - return $this; |
|
| 128 | - } |
|
| 127 | + return $this; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - public function having() |
|
| 131 | - { |
|
| 132 | - $bindings = func_get_args(); |
|
| 130 | + public function having() |
|
| 131 | + { |
|
| 132 | + $bindings = func_get_args(); |
|
| 133 | 133 | |
| 134 | - $sql = array_shift($bindings); |
|
| 134 | + $sql = array_shift($bindings); |
|
| 135 | 135 | |
| 136 | - $this->addToBindings($bindings); |
|
| 136 | + $this->addToBindings($bindings); |
|
| 137 | 137 | |
| 138 | - $this->havings[] = $sql; |
|
| 138 | + $this->havings[] = $sql; |
|
| 139 | 139 | |
| 140 | - return $this; |
|
| 141 | - } |
|
| 140 | + return $this; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - public function groupBy(...$arguments) |
|
| 144 | - { |
|
| 145 | - $this->groupBy = $arguments; |
|
| 143 | + public function groupBy(...$arguments) |
|
| 144 | + { |
|
| 145 | + $this->groupBy = $arguments; |
|
| 146 | 146 | |
| 147 | - return $this; |
|
| 148 | - } |
|
| 147 | + return $this; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - public function limit($limit, $offset = 0) |
|
| 151 | - { |
|
| 152 | - $this->limit = $limit; |
|
| 150 | + public function limit($limit, $offset = 0) |
|
| 151 | + { |
|
| 152 | + $this->limit = $limit; |
|
| 153 | 153 | |
| 154 | - $this->offset = $offset; |
|
| 154 | + $this->offset = $offset; |
|
| 155 | 155 | |
| 156 | - return $this; |
|
| 157 | - } |
|
| 156 | + return $this; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public function rows() |
|
| 160 | - { |
|
| 161 | - return $this->rows; |
|
| 162 | - } |
|
| 159 | + public function rows() |
|
| 160 | + { |
|
| 161 | + return $this->rows; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - public function orderBy($orderBy, $sort = 'ASC') |
|
| 165 | - { |
|
| 166 | - $this->orderBy = [$orderBy, $sort]; |
|
| 164 | + public function orderBy($orderBy, $sort = 'ASC') |
|
| 165 | + { |
|
| 166 | + $this->orderBy = [$orderBy, $sort]; |
|
| 167 | 167 | |
| 168 | - return $this; |
|
| 169 | - } |
|
| 168 | + return $this; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - public function fetch($table = null) |
|
| 172 | - { |
|
| 173 | - if ($table) { |
|
| 174 | - $this->table($table); |
|
| 175 | - } |
|
| 171 | + public function fetch($table = null) |
|
| 172 | + { |
|
| 173 | + if ($table) { |
|
| 174 | + $this->table($table); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - $sql = $this->fetchStatment(); |
|
| 177 | + $sql = $this->fetchStatment(); |
|
| 178 | 178 | |
| 179 | - $query = $this->query($sql, $this->bindings); |
|
| 179 | + $query = $this->query($sql, $this->bindings); |
|
| 180 | 180 | |
| 181 | - $result = $query->fetch(); |
|
| 181 | + $result = $query->fetch(); |
|
| 182 | 182 | |
| 183 | - $this->rows = $query->rowCount(); |
|
| 183 | + $this->rows = $query->rowCount(); |
|
| 184 | 184 | |
| 185 | - return $result; |
|
| 186 | - } |
|
| 185 | + return $result; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - public function fetchAll($table = null) |
|
| 189 | - { |
|
| 190 | - if ($table) { |
|
| 191 | - $this->table($table); |
|
| 192 | - } |
|
| 188 | + public function fetchAll($table = null) |
|
| 189 | + { |
|
| 190 | + if ($table) { |
|
| 191 | + $this->table($table); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - $sql = $this->fetchStatment(); |
|
| 194 | + $sql = $this->fetchStatment(); |
|
| 195 | 195 | |
| 196 | - $query = $this->query($sql, $this->bindings); |
|
| 196 | + $query = $this->query($sql, $this->bindings); |
|
| 197 | 197 | |
| 198 | - $results = $query->fetchall(); |
|
| 198 | + $results = $query->fetchall(); |
|
| 199 | 199 | |
| 200 | - $this->rows = $query->rowCount(); |
|
| 200 | + $this->rows = $query->rowCount(); |
|
| 201 | 201 | |
| 202 | - return $results; |
|
| 203 | - } |
|
| 202 | + return $results; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - private function fetchStatment() |
|
| 206 | - { |
|
| 207 | - $sql = 'SELECT '; |
|
| 205 | + private function fetchStatment() |
|
| 206 | + { |
|
| 207 | + $sql = 'SELECT '; |
|
| 208 | 208 | |
| 209 | - $sql .= $this->selects ? implode(', ', $this->selects) : '*'; |
|
| 209 | + $sql .= $this->selects ? implode(', ', $this->selects) : '*'; |
|
| 210 | 210 | |
| 211 | - $sql .= ' FROM ' . $this->table . ' '; |
|
| 211 | + $sql .= ' FROM ' . $this->table . ' '; |
|
| 212 | 212 | |
| 213 | - if (!empty($this->joins)) { |
|
| 213 | + if (!empty($this->joins)) { |
|
| 214 | 214 | |
| 215 | - $sql .= 'LEFT JOIN ' . implode(' ', $this->joins); |
|
| 216 | - } |
|
| 215 | + $sql .= 'LEFT JOIN ' . implode(' ', $this->joins); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - if (!empty($this->wheres)) { |
|
| 218 | + if (!empty($this->wheres)) { |
|
| 219 | 219 | |
| 220 | - $sql .= ' WHERE ' . implode(' ', $this->wheres); |
|
| 221 | - } |
|
| 220 | + $sql .= ' WHERE ' . implode(' ', $this->wheres); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - if (!empty($this->havings)) { |
|
| 223 | + if (!empty($this->havings)) { |
|
| 224 | 224 | |
| 225 | - $sql .= ' HAVING ' . implode(' ', $this->havings) . ' '; |
|
| 226 | - } |
|
| 225 | + $sql .= ' HAVING ' . implode(' ', $this->havings) . ' '; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if (!empty($this->orderBy)) { |
|
| 228 | + if (!empty($this->orderBy)) { |
|
| 229 | 229 | |
| 230 | - $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
| 231 | - } |
|
| 230 | + $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - if ($this->limit) { |
|
| 233 | + if ($this->limit) { |
|
| 234 | 234 | |
| 235 | - $sql .= ' LIMIT ' . $this->limit; |
|
| 236 | - } |
|
| 235 | + $sql .= ' LIMIT ' . $this->limit; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - if ($this->offset) { |
|
| 238 | + if ($this->offset) { |
|
| 239 | 239 | |
| 240 | - $sql .= ' OFFSET ' . $this->offset; |
|
| 241 | - } |
|
| 240 | + $sql .= ' OFFSET ' . $this->offset; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - if (!empty($this->groupBy)) { |
|
| 244 | - $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
| 245 | - } |
|
| 243 | + if (!empty($this->groupBy)) { |
|
| 244 | + $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $sql; |
|
| 248 | - } |
|
| 247 | + return $sql; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - public function lastId() |
|
| 251 | - { |
|
| 252 | - return $this->lastId; |
|
| 253 | - } |
|
| 250 | + public function lastId() |
|
| 251 | + { |
|
| 252 | + return $this->lastId; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - public function from($table) |
|
| 256 | - { |
|
| 257 | - return $this->table($table); |
|
| 258 | - } |
|
| 255 | + public function from($table) |
|
| 256 | + { |
|
| 257 | + return $this->table($table); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - public function data($key, $value = null) |
|
| 261 | - { |
|
| 262 | - if (is_array($key)) { |
|
| 260 | + public function data($key, $value = null) |
|
| 261 | + { |
|
| 262 | + if (is_array($key)) { |
|
| 263 | 263 | |
| 264 | - $this->data = array_merge($this->data, $key); |
|
| 264 | + $this->data = array_merge($this->data, $key); |
|
| 265 | 265 | |
| 266 | - $this->addToBindings($key); |
|
| 266 | + $this->addToBindings($key); |
|
| 267 | 267 | |
| 268 | - } else { |
|
| 268 | + } else { |
|
| 269 | 269 | |
| 270 | - $this->data[$key] = $value; |
|
| 270 | + $this->data[$key] = $value; |
|
| 271 | 271 | |
| 272 | - $this->addToBindings($value); |
|
| 272 | + $this->addToBindings($value); |
|
| 273 | 273 | |
| 274 | - } |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - return $this; |
|
| 277 | - } |
|
| 276 | + return $this; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - public function insert($table = null) |
|
| 280 | - { |
|
| 281 | - if ($table) { |
|
| 282 | - $this->table($table); |
|
| 283 | - } |
|
| 279 | + public function insert($table = null) |
|
| 280 | + { |
|
| 281 | + if ($table) { |
|
| 282 | + $this->table($table); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - $sql = 'INSERT INTO ' . $this->table . ' SET '; |
|
| 285 | + $sql = 'INSERT INTO ' . $this->table . ' SET '; |
|
| 286 | 286 | |
| 287 | - $sql .= $this->setField(); |
|
| 287 | + $sql .= $this->setField(); |
|
| 288 | 288 | |
| 289 | - $this->query($sql, $this->bindings); |
|
| 289 | + $this->query($sql, $this->bindings); |
|
| 290 | 290 | |
| 291 | - $this->lastId = $this->connection()->lastInsertId(); |
|
| 291 | + $this->lastId = $this->connection()->lastInsertId(); |
|
| 292 | 292 | |
| 293 | - return $this; |
|
| 294 | - } |
|
| 293 | + return $this; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - public function update($table = null) |
|
| 297 | - { |
|
| 298 | - if ($table) { |
|
| 299 | - $this->table($table); |
|
| 300 | - } |
|
| 296 | + public function update($table = null) |
|
| 297 | + { |
|
| 298 | + if ($table) { |
|
| 299 | + $this->table($table); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - $sql = 'UPDATE ' . $this->table . ' SET '; |
|
| 302 | + $sql = 'UPDATE ' . $this->table . ' SET '; |
|
| 303 | 303 | |
| 304 | - $sql .= $this->setField(); |
|
| 304 | + $sql .= $this->setField(); |
|
| 305 | 305 | |
| 306 | - if (!empty($this->wheres)) { |
|
| 307 | - $sql .= ' WHERE ' . implode('', $this->wheres); |
|
| 308 | - } |
|
| 306 | + if (!empty($this->wheres)) { |
|
| 307 | + $sql .= ' WHERE ' . implode('', $this->wheres); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $this->query($sql, $this->bindings); |
|
| 310 | + $this->query($sql, $this->bindings); |
|
| 311 | 311 | |
| 312 | - return $this; |
|
| 313 | - } |
|
| 312 | + return $this; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - public function delete($table = null) |
|
| 316 | - { |
|
| 317 | - if ($table) { |
|
| 318 | - $this->table($table); |
|
| 319 | - } |
|
| 315 | + public function delete($table = null) |
|
| 316 | + { |
|
| 317 | + if ($table) { |
|
| 318 | + $this->table($table); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - $sql = 'DELETE FROM ' . $this->table . ' '; |
|
| 321 | + $sql = 'DELETE FROM ' . $this->table . ' '; |
|
| 322 | 322 | |
| 323 | - if (!empty($this->wheres)) { |
|
| 324 | - $sql .= ' WHERE ' . implode('', $this->wheres); |
|
| 325 | - } |
|
| 323 | + if (!empty($this->wheres)) { |
|
| 324 | + $sql .= ' WHERE ' . implode('', $this->wheres); |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - $this->query($sql, $this->bindings); |
|
| 327 | + $this->query($sql, $this->bindings); |
|
| 328 | 328 | |
| 329 | - return $this; |
|
| 330 | - } |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - private function setField() |
|
| 333 | - { |
|
| 334 | - $sql = ''; |
|
| 332 | + private function setField() |
|
| 333 | + { |
|
| 334 | + $sql = ''; |
|
| 335 | 335 | |
| 336 | - foreach($this->data as $key => $value) { |
|
| 336 | + foreach($this->data as $key => $value) { |
|
| 337 | 337 | |
| 338 | - $sql .= '`' . $key . '` = ? ,'; |
|
| 339 | - } |
|
| 338 | + $sql .= '`' . $key . '` = ? ,'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $sql = rtrim($sql, ' ,'); |
|
| 341 | + $sql = rtrim($sql, ' ,'); |
|
| 342 | 342 | |
| 343 | - return $sql; |
|
| 344 | - } |
|
| 343 | + return $sql; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - private function addToBindings($value) |
|
| 347 | - { |
|
| 348 | - if (is_array($value)) { |
|
| 346 | + private function addToBindings($value) |
|
| 347 | + { |
|
| 348 | + if (is_array($value)) { |
|
| 349 | 349 | |
| 350 | - $this->bindings = array_merge($this->bindings, array_values($value)); |
|
| 351 | - } else { |
|
| 350 | + $this->bindings = array_merge($this->bindings, array_values($value)); |
|
| 351 | + } else { |
|
| 352 | 352 | |
| 353 | - $this->bindings[] = $value; |
|
| 354 | - } |
|
| 355 | - } |
|
| 353 | + $this->bindings[] = $value; |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - public function query(...$bindings) |
|
| 358 | - { |
|
| 359 | - $sql = array_shift($bindings); |
|
| 357 | + public function query(...$bindings) |
|
| 358 | + { |
|
| 359 | + $sql = array_shift($bindings); |
|
| 360 | 360 | |
| 361 | - if (count($bindings) == 1 AND is_array($bindings[0])) { |
|
| 362 | - $bindings = $bindings[0]; |
|
| 363 | - } |
|
| 361 | + if (count($bindings) == 1 AND is_array($bindings[0])) { |
|
| 362 | + $bindings = $bindings[0]; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - try { |
|
| 366 | - $query = $this->connection()->prepare($sql); |
|
| 365 | + try { |
|
| 366 | + $query = $this->connection()->prepare($sql); |
|
| 367 | 367 | |
| 368 | - foreach ($bindings as $key => $value) { |
|
| 369 | - $query->bindValue($key + 1, _e($value)); |
|
| 370 | - } |
|
| 368 | + foreach ($bindings as $key => $value) { |
|
| 369 | + $query->bindValue($key + 1, _e($value)); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - $query->execute(); |
|
| 372 | + $query->execute(); |
|
| 373 | 373 | |
| 374 | - $this->reset(); |
|
| 374 | + $this->reset(); |
|
| 375 | 375 | |
| 376 | - return $query; |
|
| 376 | + return $query; |
|
| 377 | 377 | |
| 378 | - } catch (PDOException $e) { |
|
| 378 | + } catch (PDOException $e) { |
|
| 379 | 379 | |
| 380 | - throw new Exception($e->getMessage()); |
|
| 381 | - } |
|
| 382 | - } |
|
| 380 | + throw new Exception($e->getMessage()); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - private function reset() |
|
| 385 | - { |
|
| 386 | - $this->table = null; |
|
| 384 | + private function reset() |
|
| 385 | + { |
|
| 386 | + $this->table = null; |
|
| 387 | 387 | |
| 388 | - $this->rows = 0; |
|
| 388 | + $this->rows = 0; |
|
| 389 | 389 | |
| 390 | - $this->data = []; |
|
| 390 | + $this->data = []; |
|
| 391 | 391 | |
| 392 | - $this->bindings = []; |
|
| 392 | + $this->bindings = []; |
|
| 393 | 393 | |
| 394 | - $this->selects = []; |
|
| 394 | + $this->selects = []; |
|
| 395 | 395 | |
| 396 | - $this->joins = []; |
|
| 396 | + $this->joins = []; |
|
| 397 | 397 | |
| 398 | - $this->wheres = []; |
|
| 398 | + $this->wheres = []; |
|
| 399 | 399 | |
| 400 | - $this->havings = []; |
|
| 400 | + $this->havings = []; |
|
| 401 | 401 | |
| 402 | - $this->orderBy = []; |
|
| 402 | + $this->orderBy = []; |
|
| 403 | 403 | |
| 404 | - $this->limit = null; |
|
| 404 | + $this->limit = null; |
|
| 405 | 405 | |
| 406 | - $this->offset = 0; |
|
| 406 | + $this->offset = 0; |
|
| 407 | 407 | |
| 408 | - $this->groupBy = []; |
|
| 409 | - } |
|
| 408 | + $this->groupBy = []; |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | \ No newline at end of file |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $this->app = $app; |
| 44 | 44 | |
| 45 | - if (! $this->isConnected()) { |
|
| 45 | + if (!$this->isConnected()) { |
|
| 46 | 46 | $this->connect(); |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | extract($data); |
| 60 | 60 | |
| 61 | 61 | try { |
| 62 | - self::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
| 62 | + self::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
| 63 | 63 | |
| 64 | 64 | self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 65 | 65 | |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | public function join($join, $localId = null, $forginId = null) |
| 96 | 96 | { |
| 97 | - if (! $localId) { |
|
| 97 | + if (!$localId) { |
|
| 98 | 98 | |
| 99 | - $localId = trim($join, 's' ). '_id'; |
|
| 99 | + $localId = trim($join, 's') . '_id'; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if (! $forginId) { |
|
| 102 | + if (!$forginId) { |
|
| 103 | 103 | |
| 104 | - $forginId = 'id'; |
|
| 104 | + $forginId = 'id'; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $sql = $join . ' ON ' . $this->table . '.' . $localId . ' = ' . $join . '.' . $forginId; |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | if (!empty($this->orderBy)) { |
| 229 | 229 | |
| 230 | - $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
| 230 | + $sql .= ' ORDER BY ' . implode(' ', $this->orderBy); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | if ($this->limit) { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (!empty($this->groupBy)) { |
| 244 | - $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
| 244 | + $sql .= ' GROUP BY ' . implode(' ', $this->groupBy); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | return $sql; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | { |
| 334 | 334 | $sql = ''; |
| 335 | 335 | |
| 336 | - foreach($this->data as $key => $value) { |
|
| 336 | + foreach ($this->data as $key => $value) { |
|
| 337 | 337 | |
| 338 | 338 | $sql .= '`' . $key . '` = ? ,'; |
| 339 | 339 | } |
@@ -7,32 +7,32 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AuthenticateMiddleware implements Middleware |
| 9 | 9 | { |
| 10 | - public function handle(Application $app, $next) |
|
| 11 | - { |
|
| 12 | - $request = $app->request->url(); |
|
| 10 | + public function handle(Application $app, $next) |
|
| 11 | + { |
|
| 12 | + $request = $app->request->url(); |
|
| 13 | 13 | |
| 14 | - $login = $app->load->model('Login'); |
|
| 14 | + $login = $app->load->model('Login'); |
|
| 15 | 15 | |
| 16 | - $pagesWhenLogout = [ |
|
| 17 | - '/login', |
|
| 18 | - '/login/submit', |
|
| 19 | - '/registration', |
|
| 20 | - '/registration/submit' |
|
| 21 | - ]; |
|
| 16 | + $pagesWhenLogout = [ |
|
| 17 | + '/login', |
|
| 18 | + '/login/submit', |
|
| 19 | + '/registration', |
|
| 20 | + '/registration/submit' |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - if ($login->isLogged()) { |
|
| 23 | + if ($login->isLogged()) { |
|
| 24 | 24 | |
| 25 | - if (in_array($request, $pagesWhenLogout)) { |
|
| 26 | - $app->url->redirectTo('/'); |
|
| 27 | - } |
|
| 25 | + if (in_array($request, $pagesWhenLogout)) { |
|
| 26 | + $app->url->redirectTo('/'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - } else { |
|
| 29 | + } else { |
|
| 30 | 30 | |
| 31 | - if (! in_array($request, $pagesWhenLogout)) { |
|
| 32 | - $app->url->redirectTo('/'); |
|
| 33 | - } |
|
| 34 | - } |
|
| 31 | + if (! in_array($request, $pagesWhenLogout)) { |
|
| 32 | + $app->url->redirectTo('/'); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return $next; |
|
| 37 | - } |
|
| 36 | + return $next; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | |
| 29 | 29 | } else { |
| 30 | 30 | |
| 31 | - if (! in_array($request, $pagesWhenLogout)) { |
|
| 31 | + if (!in_array($request, $pagesWhenLogout)) { |
|
| 32 | 32 | $app->url->redirectTo('/'); |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -6,52 +6,52 @@ |
||
| 6 | 6 | |
| 7 | 7 | class LoginModel extends Model |
| 8 | 8 | { |
| 9 | - protected $table = 'users'; |
|
| 9 | + protected $table = 'users'; |
|
| 10 | 10 | |
| 11 | - private $user; |
|
| 11 | + private $user; |
|
| 12 | 12 | |
| 13 | - public function isValidLogin($email, $password) |
|
| 14 | - { |
|
| 15 | - $user = $this->where('email=?' , $email)->fetch($this->table); |
|
| 13 | + public function isValidLogin($email, $password) |
|
| 14 | + { |
|
| 15 | + $user = $this->where('email=?' , $email)->fetch($this->table); |
|
| 16 | 16 | |
| 17 | - if (! $user) { |
|
| 17 | + if (! $user) { |
|
| 18 | 18 | |
| 19 | - return false; |
|
| 20 | - } |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - $this->user = $user; |
|
| 22 | + $this->user = $user; |
|
| 23 | 23 | |
| 24 | - return password_verify($password, $user->password); |
|
| 25 | - } |
|
| 24 | + return password_verify($password, $user->password); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function user() |
|
| 28 | - { |
|
| 29 | - return $this->user; |
|
| 30 | - } |
|
| 27 | + public function user() |
|
| 28 | + { |
|
| 29 | + return $this->user; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function isLogged() |
|
| 33 | - { |
|
| 34 | - if ($this->cookie->has('login')) { |
|
| 32 | + public function isLogged() |
|
| 33 | + { |
|
| 34 | + if ($this->cookie->has('login')) { |
|
| 35 | 35 | |
| 36 | - $code = $this->cookie->get('login'); |
|
| 36 | + $code = $this->cookie->get('login'); |
|
| 37 | 37 | |
| 38 | - } elseif ($this->session->has('login')) { |
|
| 38 | + } elseif ($this->session->has('login')) { |
|
| 39 | 39 | |
| 40 | - $code = $this->session->get('login'); |
|
| 40 | + $code = $this->session->get('login'); |
|
| 41 | 41 | |
| 42 | - } else { |
|
| 42 | + } else { |
|
| 43 | 43 | |
| 44 | - return false; |
|
| 45 | - } |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - $user = $this->where('code=?' , $code)->fetch($this->table); |
|
| 47 | + $user = $this->where('code=?' , $code)->fetch($this->table); |
|
| 48 | 48 | |
| 49 | - if (! $user) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 49 | + if (! $user) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $this->user = $user; |
|
| 53 | + $this->user = $user; |
|
| 54 | 54 | |
| 55 | - return true; |
|
| 56 | - } |
|
| 55 | + return true; |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function isValidLogin($email, $password) |
| 14 | 14 | { |
| 15 | - $user = $this->where('email=?' , $email)->fetch($this->table); |
|
| 15 | + $user = $this->where('email=?', $email)->fetch($this->table); |
|
| 16 | 16 | |
| 17 | - if (! $user) { |
|
| 17 | + if (!$user) { |
|
| 18 | 18 | |
| 19 | 19 | return false; |
| 20 | 20 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - $user = $this->where('code=?' , $code)->fetch($this->table); |
|
| 47 | + $user = $this->where('code=?', $code)->fetch($this->table); |
|
| 48 | 48 | |
| 49 | - if (! $user) { |
|
| 49 | + if (!$user) { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |