@@ -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 |
@@ -4,60 +4,60 @@ |
||
4 | 4 | |
5 | 5 | class Session |
6 | 6 | { |
7 | - private $app; |
|
8 | - |
|
9 | - public function __construct(Application $app) |
|
10 | - { |
|
11 | - $this->app = $app; |
|
12 | - } |
|
13 | - |
|
14 | - public function start() |
|
15 | - { |
|
16 | - ini_set('session.use_only_cookies', 1); |
|
17 | - |
|
18 | - if (!session_id()) { |
|
19 | - session_start(); |
|
20 | - } |
|
21 | - } |
|
22 | - |
|
23 | - public function set($key, $value) |
|
24 | - { |
|
25 | - $_SESSION[$key] = $value; |
|
26 | - } |
|
27 | - |
|
28 | - public function get($key, $default = null) |
|
29 | - { |
|
30 | - return array_get($_SESSION, $key, $default); |
|
31 | - } |
|
32 | - |
|
33 | - public function pull($key) |
|
34 | - { |
|
35 | - $value = $this->get($key); |
|
36 | - |
|
37 | - $this->remove($key); |
|
38 | - |
|
39 | - return $value; |
|
40 | - } |
|
41 | - |
|
42 | - public function has($key) |
|
43 | - { |
|
44 | - return isset($_SESSION[$key]); |
|
45 | - } |
|
46 | - |
|
47 | - public function all() |
|
48 | - { |
|
49 | - return $_SESSION; |
|
50 | - } |
|
51 | - |
|
52 | - public function remove($key) |
|
53 | - { |
|
54 | - unset($_SESSION[$key]); |
|
55 | - } |
|
56 | - |
|
57 | - public function destroy() |
|
58 | - { |
|
59 | - session_destroy(); |
|
60 | - |
|
61 | - unset($_SESSION); |
|
62 | - } |
|
7 | + private $app; |
|
8 | + |
|
9 | + public function __construct(Application $app) |
|
10 | + { |
|
11 | + $this->app = $app; |
|
12 | + } |
|
13 | + |
|
14 | + public function start() |
|
15 | + { |
|
16 | + ini_set('session.use_only_cookies', 1); |
|
17 | + |
|
18 | + if (!session_id()) { |
|
19 | + session_start(); |
|
20 | + } |
|
21 | + } |
|
22 | + |
|
23 | + public function set($key, $value) |
|
24 | + { |
|
25 | + $_SESSION[$key] = $value; |
|
26 | + } |
|
27 | + |
|
28 | + public function get($key, $default = null) |
|
29 | + { |
|
30 | + return array_get($_SESSION, $key, $default); |
|
31 | + } |
|
32 | + |
|
33 | + public function pull($key) |
|
34 | + { |
|
35 | + $value = $this->get($key); |
|
36 | + |
|
37 | + $this->remove($key); |
|
38 | + |
|
39 | + return $value; |
|
40 | + } |
|
41 | + |
|
42 | + public function has($key) |
|
43 | + { |
|
44 | + return isset($_SESSION[$key]); |
|
45 | + } |
|
46 | + |
|
47 | + public function all() |
|
48 | + { |
|
49 | + return $_SESSION; |
|
50 | + } |
|
51 | + |
|
52 | + public function remove($key) |
|
53 | + { |
|
54 | + unset($_SESSION[$key]); |
|
55 | + } |
|
56 | + |
|
57 | + public function destroy() |
|
58 | + { |
|
59 | + session_destroy(); |
|
60 | + |
|
61 | + unset($_SESSION); |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -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 |
@@ -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 |
@@ -6,99 +6,99 @@ |
||
6 | 6 | |
7 | 7 | class Loader |
8 | 8 | { |
9 | - private $app; |
|
9 | + private $app; |
|
10 | 10 | |
11 | - private $controllers = []; |
|
11 | + private $controllers = []; |
|
12 | 12 | |
13 | - private $models = []; |
|
13 | + private $models = []; |
|
14 | 14 | |
15 | - public function __construct(Application $app) |
|
16 | - { |
|
17 | - $this->app = $app; |
|
18 | - } |
|
15 | + public function __construct(Application $app) |
|
16 | + { |
|
17 | + $this->app = $app; |
|
18 | + } |
|
19 | 19 | |
20 | - public function action($controller, $method, array $arguments) |
|
21 | - { |
|
22 | - $object = $this->controller($controller); |
|
20 | + public function action($controller, $method, array $arguments) |
|
21 | + { |
|
22 | + $object = $this->controller($controller); |
|
23 | 23 | |
24 | - return call_user_func([$object, $method], $arguments); |
|
25 | - } |
|
24 | + return call_user_func([$object, $method], $arguments); |
|
25 | + } |
|
26 | 26 | |
27 | - public function controller($controller) |
|
28 | - { |
|
29 | - $controller = $this->getControllerName($controller); |
|
27 | + public function controller($controller) |
|
28 | + { |
|
29 | + $controller = $this->getControllerName($controller); |
|
30 | 30 | |
31 | - if (!$this->hasController($controller)) { |
|
32 | - $this->addController($controller); |
|
33 | - } |
|
31 | + if (!$this->hasController($controller)) { |
|
32 | + $this->addController($controller); |
|
33 | + } |
|
34 | 34 | |
35 | - return $this->getController($controller); |
|
36 | - } |
|
35 | + return $this->getController($controller); |
|
36 | + } |
|
37 | 37 | |
38 | - private function hasController($controller) |
|
39 | - { |
|
40 | - return array_key_exists($controller, $this->controllers); |
|
41 | - } |
|
38 | + private function hasController($controller) |
|
39 | + { |
|
40 | + return array_key_exists($controller, $this->controllers); |
|
41 | + } |
|
42 | 42 | |
43 | - private function addController($controller) |
|
44 | - { |
|
45 | - $object = new $controller($this->app); |
|
43 | + private function addController($controller) |
|
44 | + { |
|
45 | + $object = new $controller($this->app); |
|
46 | 46 | |
47 | - $this->controllers[$controller] = $object; |
|
48 | - } |
|
47 | + $this->controllers[$controller] = $object; |
|
48 | + } |
|
49 | 49 | |
50 | - private function getController($controller) |
|
51 | - { |
|
52 | - return $this->controllers[$controller]; |
|
53 | - } |
|
50 | + private function getController($controller) |
|
51 | + { |
|
52 | + return $this->controllers[$controller]; |
|
53 | + } |
|
54 | 54 | |
55 | - private function getControllerName($controller) |
|
56 | - { |
|
57 | - $controller .= strpos($controller, 'Controller') ? '' : 'Controller'; |
|
55 | + private function getControllerName($controller) |
|
56 | + { |
|
57 | + $controller .= strpos($controller, 'Controller') ? '' : 'Controller'; |
|
58 | 58 | |
59 | - $controller = str_replace('/', DS, $controller); |
|
59 | + $controller = str_replace('/', DS, $controller); |
|
60 | 60 | |
61 | - $controller = 'App' . DS . 'Controllers' . DS . $controller; |
|
61 | + $controller = 'App' . DS . 'Controllers' . DS . $controller; |
|
62 | 62 | |
63 | - return $controller; |
|
64 | - } |
|
63 | + return $controller; |
|
64 | + } |
|
65 | 65 | |
66 | - public function model($model) |
|
67 | - { |
|
68 | - $model = $this->getModelName($model); |
|
66 | + public function model($model) |
|
67 | + { |
|
68 | + $model = $this->getModelName($model); |
|
69 | 69 | |
70 | - if (!$this->hasModel($model)) { |
|
71 | - $this->addModel($model); |
|
72 | - } |
|
70 | + if (!$this->hasModel($model)) { |
|
71 | + $this->addModel($model); |
|
72 | + } |
|
73 | 73 | |
74 | - return $this->getModel($model); |
|
75 | - } |
|
74 | + return $this->getModel($model); |
|
75 | + } |
|
76 | 76 | |
77 | - private function hasModel($model) |
|
78 | - { |
|
79 | - return array_key_exists($model, $this->models); |
|
80 | - } |
|
77 | + private function hasModel($model) |
|
78 | + { |
|
79 | + return array_key_exists($model, $this->models); |
|
80 | + } |
|
81 | 81 | |
82 | - private function addModel($model) |
|
83 | - { |
|
84 | - $object = new $model($this->app); |
|
82 | + private function addModel($model) |
|
83 | + { |
|
84 | + $object = new $model($this->app); |
|
85 | 85 | |
86 | - $this->models[$model] = $object; |
|
87 | - } |
|
86 | + $this->models[$model] = $object; |
|
87 | + } |
|
88 | 88 | |
89 | - private function getModel($model) |
|
90 | - { |
|
91 | - return $this->models[$model]; |
|
92 | - } |
|
89 | + private function getModel($model) |
|
90 | + { |
|
91 | + return $this->models[$model]; |
|
92 | + } |
|
93 | 93 | |
94 | - private function getModelName($model) |
|
95 | - { |
|
96 | - $model .= strpos($model, 'Model') ? '' : 'Model'; |
|
94 | + private function getModelName($model) |
|
95 | + { |
|
96 | + $model .= strpos($model, 'Model') ? '' : 'Model'; |
|
97 | 97 | |
98 | - $model = str_replace('/', DS, $model); |
|
98 | + $model = str_replace('/', DS, $model); |
|
99 | 99 | |
100 | - $model = 'App' . DS . 'Models' . DS . $model; |
|
100 | + $model = 'App' . DS . 'Models' . DS . $model; |
|
101 | 101 | |
102 | - return $model; |
|
103 | - } |
|
102 | + return $model; |
|
103 | + } |
|
104 | 104 | } |
105 | 105 | \ No newline at end of file |
@@ -6,47 +6,47 @@ |
||
6 | 6 | |
7 | 7 | class PugView |
8 | 8 | { |
9 | - private $app; |
|
10 | - |
|
11 | - public function __construct(Application $app) |
|
12 | - { |
|
13 | - $this->app = $app; |
|
14 | - } |
|
15 | - |
|
16 | - public function render($path, array $context) |
|
17 | - { |
|
18 | - $this->app->file->css(); |
|
19 | - $pug = new Pug(array( |
|
20 | - 'pretty' => true, |
|
21 | - 'cache' => 'var/cache/pug', |
|
22 | - 'basedir' => 'template/', |
|
23 | - 'upToDateCheck' => false, |
|
24 | - )); |
|
25 | - |
|
26 | - $link = $this->app->request->link(); |
|
27 | - $dir = $this->app->file->root(); |
|
28 | - |
|
29 | - //File Path |
|
30 | - $file = str_replace('/', DS, $path); |
|
31 | - $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
32 | - |
|
33 | - //Css Path |
|
34 | - $css = $this->app->file->css(); |
|
35 | - $css = str_replace($dir, $link, $css); |
|
36 | - $css = str_replace('\\', '/', $css); |
|
37 | - |
|
38 | - //Js Path |
|
39 | - $js = $this->app->file->js(); |
|
40 | - $js = str_replace($dir, $link, $js); |
|
41 | - $js = str_replace('\\', '/', $js); |
|
42 | - |
|
43 | - $context += $this->app->config['website']; |
|
44 | - |
|
45 | - $context += [ |
|
46 | - 'css' => $css, |
|
47 | - 'js' => $js |
|
48 | - ]; |
|
49 | - |
|
50 | - return $pug->render($file, $context); |
|
51 | - } |
|
9 | + private $app; |
|
10 | + |
|
11 | + public function __construct(Application $app) |
|
12 | + { |
|
13 | + $this->app = $app; |
|
14 | + } |
|
15 | + |
|
16 | + public function render($path, array $context) |
|
17 | + { |
|
18 | + $this->app->file->css(); |
|
19 | + $pug = new Pug(array( |
|
20 | + 'pretty' => true, |
|
21 | + 'cache' => 'var/cache/pug', |
|
22 | + 'basedir' => 'template/', |
|
23 | + 'upToDateCheck' => false, |
|
24 | + )); |
|
25 | + |
|
26 | + $link = $this->app->request->link(); |
|
27 | + $dir = $this->app->file->root(); |
|
28 | + |
|
29 | + //File Path |
|
30 | + $file = str_replace('/', DS, $path); |
|
31 | + $file = $dir . DS . 'template' . DS . $file . '.pug'; |
|
32 | + |
|
33 | + //Css Path |
|
34 | + $css = $this->app->file->css(); |
|
35 | + $css = str_replace($dir, $link, $css); |
|
36 | + $css = str_replace('\\', '/', $css); |
|
37 | + |
|
38 | + //Js Path |
|
39 | + $js = $this->app->file->js(); |
|
40 | + $js = str_replace($dir, $link, $js); |
|
41 | + $js = str_replace('\\', '/', $js); |
|
42 | + |
|
43 | + $context += $this->app->config['website']; |
|
44 | + |
|
45 | + $context += [ |
|
46 | + 'css' => $css, |
|
47 | + 'js' => $js |
|
48 | + ]; |
|
49 | + |
|
50 | + return $pug->render($file, $context); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -6,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 |