@@ -11,12 +11,12 @@ discard block |
||
11 | 11 | |
12 | 12 | class Application |
13 | 13 | { |
14 | - private $container = []; |
|
14 | + private $container = []; |
|
15 | 15 | |
16 | - private static $instance; |
|
16 | + private static $instance; |
|
17 | 17 | |
18 | - public function __construct(File $file) |
|
19 | - { |
|
18 | + public function __construct(File $file) |
|
19 | + { |
|
20 | 20 | $this->handleErrors(); |
21 | 21 | |
22 | 22 | $this->share('file', $file); |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | $this->share('alias', $this->file->call($this->file->to('config/alias', '.php'))); |
27 | 27 | |
28 | 28 | $this->loadHelpers(); |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - private function handleErrors() { |
|
31 | + private function handleErrors() { |
|
32 | 32 | |
33 | 33 | $run = new Whoops(); |
34 | 34 | |
@@ -36,23 +36,23 @@ discard block |
||
36 | 36 | |
37 | 37 | if (WhoopsMisc::isAjaxRequest()) { |
38 | 38 | |
39 | - $jsonHandler = new JsonResponseHandler(); |
|
39 | + $jsonHandler = new JsonResponseHandler(); |
|
40 | 40 | |
41 | - $jsonHandler->setJsonApi(true); |
|
41 | + $jsonHandler->setJsonApi(true); |
|
42 | 42 | |
43 | - $run->prependHandler($jsonHandler); |
|
43 | + $run->prependHandler($jsonHandler); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $run->register(); |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public static function getInstance($file = null) |
|
50 | - { |
|
49 | + public static function getInstance($file = null) |
|
50 | + { |
|
51 | 51 | return static::$instance = is_null(static::$instance) ? new static($file) : static::$instance; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - public function run() |
|
55 | - { |
|
54 | + public function run() |
|
55 | + { |
|
56 | 56 | $this->session->start(); |
57 | 57 | |
58 | 58 | $this->request->prepareUrl(); |
@@ -66,63 +66,63 @@ discard block |
||
66 | 66 | $this->response->setOutput($output); |
67 | 67 | |
68 | 68 | $this->response->send(); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - private function loadHelpers() |
|
72 | - { |
|
71 | + private function loadHelpers() |
|
72 | + { |
|
73 | 73 | $helpers = $this->file->to('Core/helpers', '.php'); |
74 | 74 | |
75 | 75 | $this->file->call($helpers); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - public function coreClasses() |
|
79 | - { |
|
78 | + public function coreClasses() |
|
79 | + { |
|
80 | 80 | return $this->alias['classes']; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - public function share($key, $value) |
|
84 | - { |
|
83 | + public function share($key, $value) |
|
84 | + { |
|
85 | 85 | if ($value instanceof Closure) $value = call_user_func($value, $this); |
86 | 86 | |
87 | 87 | $this->container[$key] = $value; |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - public function get($key) |
|
91 | - { |
|
90 | + public function get($key) |
|
91 | + { |
|
92 | 92 | if (! $this->isSharing($key)) { |
93 | 93 | |
94 | - if ($this->isCoreAlias($key)) { |
|
94 | + if ($this->isCoreAlias($key)) { |
|
95 | 95 | |
96 | 96 | $this->share($key, $this->createObject($key)); |
97 | 97 | |
98 | - } else { |
|
98 | + } else { |
|
99 | 99 | |
100 | 100 | throw new Exception("$key is not found"); |
101 | 101 | exit(); |
102 | - } |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | return $this->container[$key]; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - public function isSharing($key) |
|
108 | - { |
|
107 | + public function isSharing($key) |
|
108 | + { |
|
109 | 109 | return isset($this->container[$key]); |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - public function isCoreAlias($key) |
|
113 | - { |
|
112 | + public function isCoreAlias($key) |
|
113 | + { |
|
114 | 114 | return isset($this->coreClasses()[$key]); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - public function createObject($key) |
|
118 | - { |
|
117 | + public function createObject($key) |
|
118 | + { |
|
119 | 119 | $object = $this->coreClasses()[$key]; |
120 | 120 | |
121 | 121 | return new $object($this); |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - public function __get($key) |
|
125 | - { |
|
124 | + public function __get($key) |
|
125 | + { |
|
126 | 126 | return $this->get($key); |
127 | - } |
|
127 | + } |
|
128 | 128 | } |
129 | 129 | \ No newline at end of file |
@@ -89,7 +89,7 @@ |
||
89 | 89 | |
90 | 90 | public function get($key) |
91 | 91 | { |
92 | - if (! $this->isSharing($key)) { |
|
92 | + if (!$this->isSharing($key)) { |
|
93 | 93 | |
94 | 94 | if ($this->isCoreAlias($key)) { |
95 | 95 |
@@ -59,7 +59,9 @@ discard block |
||
59 | 59 | |
60 | 60 | $this->file->call($this->file->to('config/constant.php')); |
61 | 61 | |
62 | - foreach (glob("routes/**/*.php") as $route) $this->file->call($this->file->to($route)); |
|
62 | + foreach (glob("routes/**/*.php") as $route) { |
|
63 | + $this->file->call($this->file->to($route)); |
|
64 | + } |
|
63 | 65 | |
64 | 66 | $output = $this->route->getProperRoute(); |
65 | 67 | |
@@ -82,7 +84,9 @@ discard block |
||
82 | 84 | |
83 | 85 | public function share($key, $value) |
84 | 86 | { |
85 | - if ($value instanceof Closure) $value = call_user_func($value, $this); |
|
87 | + if ($value instanceof Closure) { |
|
88 | + $value = call_user_func($value, $this); |
|
89 | + } |
|
86 | 90 | |
87 | 91 | $this->container[$key] = $value; |
88 | 92 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | abstract class Controller |
6 | 6 | { |
7 | - protected $app; |
|
7 | + protected $app; |
|
8 | 8 | |
9 | - public function __construct(Application $app) |
|
10 | - { |
|
9 | + public function __construct(Application $app) |
|
10 | + { |
|
11 | 11 | $this->app = $app; |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | - public function __get($key) |
|
15 | - { |
|
14 | + public function __get($key) |
|
15 | + { |
|
16 | 16 | return $this->app->get($key); |
17 | - } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -6,27 +6,27 @@ discard block |
||
6 | 6 | |
7 | 7 | class File |
8 | 8 | { |
9 | - const DS = DIRECTORY_SEPARATOR; |
|
9 | + const DS = DIRECTORY_SEPARATOR; |
|
10 | 10 | |
11 | - private $root; |
|
11 | + private $root; |
|
12 | 12 | |
13 | - public function __construct($root) |
|
14 | - { |
|
13 | + public function __construct($root) |
|
14 | + { |
|
15 | 15 | $this->root = $root; |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - public function root() |
|
19 | - { |
|
18 | + public function root() |
|
19 | + { |
|
20 | 20 | return $this->root; |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - public function exists($file) |
|
24 | - { |
|
23 | + public function exists($file) |
|
24 | + { |
|
25 | 25 | return file_exists($file); |
26 | - } |
|
26 | + } |
|
27 | 27 | |
28 | - public function call($file) |
|
29 | - { |
|
28 | + public function call($file) |
|
29 | + { |
|
30 | 30 | if ($this->exists($file)) { |
31 | 31 | |
32 | 32 | return require $file; |
@@ -35,30 +35,30 @@ discard block |
||
35 | 35 | |
36 | 36 | throw new Exception("$file is not found"); |
37 | 37 | } |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function to($path, $ext = null) |
|
41 | - { |
|
40 | + public function to($path, $ext = null) |
|
41 | + { |
|
42 | 42 | return $this->root . static::DS . str_replace('/', static::DS, $path . $ext); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - public function toPublic($target = null) |
|
46 | - { |
|
45 | + public function toPublic($target = null) |
|
46 | + { |
|
47 | 47 | return $this->to('public/' . $target); |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - public function images() |
|
51 | - { |
|
50 | + public function images() |
|
51 | + { |
|
52 | 52 | return $this->toPublic('images'); |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function js() |
|
56 | - { |
|
55 | + public function js() |
|
56 | + { |
|
57 | 57 | return $this->toPublic('js'); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function css() |
|
61 | - { |
|
60 | + public function css() |
|
61 | + { |
|
62 | 62 | return $this->toPublic('css'); |
63 | - } |
|
63 | + } |
|
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -6,44 +6,44 @@ |
||
6 | 6 | |
7 | 7 | class Response |
8 | 8 | { |
9 | - private $app; |
|
9 | + private $app; |
|
10 | 10 | |
11 | - private $headers = []; |
|
11 | + private $headers = []; |
|
12 | 12 | |
13 | - private $content = ''; |
|
13 | + private $content = ''; |
|
14 | 14 | |
15 | - public function __construct(Application $app) |
|
16 | - { |
|
15 | + public function __construct(Application $app) |
|
16 | + { |
|
17 | 17 | $this->app = $app; |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - public function setOutput($content) |
|
21 | - { |
|
20 | + public function setOutput($content) |
|
21 | + { |
|
22 | 22 | $this->content = $content; |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function setHeaders($header, $value) |
|
26 | - { |
|
25 | + public function setHeaders($header, $value) |
|
26 | + { |
|
27 | 27 | $this->headers[$header] = $value; |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function sendOutput() |
|
31 | - { |
|
30 | + public function sendOutput() |
|
31 | + { |
|
32 | 32 | echo $this->content; |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - public function sendHeaders() |
|
36 | - { |
|
35 | + public function sendHeaders() |
|
36 | + { |
|
37 | 37 | foreach($this->headers as $header => $value) |
38 | 38 | { |
39 | - header($header . ':' . $value); |
|
39 | + header($header . ':' . $value); |
|
40 | + } |
|
40 | 41 | } |
41 | - } |
|
42 | 42 | |
43 | - public function send() |
|
44 | - { |
|
43 | + public function send() |
|
44 | + { |
|
45 | 45 | $this->sendHeaders(); |
46 | 46 | |
47 | 47 | $this->sendOutput(); |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -34,7 +34,7 @@ |
||
34 | 34 | |
35 | 35 | public function sendHeaders() |
36 | 36 | { |
37 | - foreach($this->headers as $header => $value) |
|
37 | + foreach ($this->headers as $header => $value) |
|
38 | 38 | { |
39 | 39 | header($header . ':' . $value); |
40 | 40 | } |
@@ -4,87 +4,87 @@ |
||
4 | 4 | |
5 | 5 | class Pagination |
6 | 6 | { |
7 | - private $app; |
|
7 | + private $app; |
|
8 | 8 | |
9 | - private $totalItems; |
|
9 | + private $totalItems; |
|
10 | 10 | |
11 | - private $itemsPerPage = 10; |
|
11 | + private $itemsPerPage = 10; |
|
12 | 12 | |
13 | - private $lastPage; |
|
13 | + private $lastPage; |
|
14 | 14 | |
15 | - private $page = 1; |
|
15 | + private $page = 1; |
|
16 | 16 | |
17 | - public function __construct(Application $app) |
|
18 | - { |
|
17 | + public function __construct(Application $app) |
|
18 | + { |
|
19 | 19 | $this->app = $app; |
20 | 20 | |
21 | 21 | $this->setCurrentPage(); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - private function setCurrentPage() |
|
25 | - { |
|
24 | + private function setCurrentPage() |
|
25 | + { |
|
26 | 26 | $page = $this->app->request->get('page'); |
27 | 27 | |
28 | 28 | if (! is_numeric($page) || $page < 1) { |
29 | - $page = 1; |
|
29 | + $page = 1; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $this->page = $page; |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - public function page() |
|
36 | - { |
|
35 | + public function page() |
|
36 | + { |
|
37 | 37 | return $this->page; |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function itemsPerPage() |
|
41 | - { |
|
40 | + public function itemsPerPage() |
|
41 | + { |
|
42 | 42 | return $this->itemsPerPage; |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - public function totalItems() |
|
46 | - { |
|
45 | + public function totalItems() |
|
46 | + { |
|
47 | 47 | return $this->totalItems; |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - public function last() |
|
51 | - { |
|
50 | + public function last() |
|
51 | + { |
|
52 | 52 | return $this->lastPage; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function next() |
|
56 | - { |
|
55 | + public function next() |
|
56 | + { |
|
57 | 57 | return $this->page + 1; |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function prev() |
|
61 | - { |
|
60 | + public function prev() |
|
61 | + { |
|
62 | 62 | return $this->page - 1; |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - public function setTotalItems($totalItems) |
|
66 | - { |
|
65 | + public function setTotalItems($totalItems) |
|
66 | + { |
|
67 | 67 | $this->totalItems = $totalItems; |
68 | 68 | |
69 | 69 | return $this; |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - public function setItemsPerPage($itemsPerPage) |
|
73 | - { |
|
72 | + public function setItemsPerPage($itemsPerPage) |
|
73 | + { |
|
74 | 74 | $this->itemsPerPage = $itemsPerPage; |
75 | 75 | |
76 | 76 | return $this; |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - public function paginate() |
|
80 | - { |
|
79 | + public function paginate() |
|
80 | + { |
|
81 | 81 | $this->setLastPage(); |
82 | 82 | |
83 | 83 | return $this; |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | - private function setLastPage() |
|
87 | - { |
|
86 | + private function setLastPage() |
|
87 | + { |
|
88 | 88 | $this->lastPage = ceil($this->totalItems / $this->itemsPerPage); |
89 | - } |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -25,7 +25,7 @@ |
||
25 | 25 | { |
26 | 26 | $page = $this->app->request->get('page'); |
27 | 27 | |
28 | - if (! is_numeric($page) || $page < 1) { |
|
28 | + if (!is_numeric($page) || $page < 1) { |
|
29 | 29 | $page = 1; |
30 | 30 | } |
31 | 31 |
@@ -7,16 +7,16 @@ |
||
7 | 7 | |
8 | 8 | class RedirectMiddleware implements Middleware |
9 | 9 | { |
10 | - public function handle(Application $app, $next) |
|
11 | - { |
|
10 | + public function handle(Application $app, $next) |
|
11 | + { |
|
12 | 12 | |
13 | 13 | if (! $this->session->has('error') || $this->session->get('error') != true) { |
14 | 14 | |
15 | - $this->url->redirectTo('/'); |
|
15 | + $this->url->redirectTo('/'); |
|
16 | 16 | |
17 | 17 | } else { |
18 | 18 | |
19 | - $this->session->remove('error'); |
|
19 | + $this->session->remove('error'); |
|
20 | + } |
|
20 | 21 | } |
21 | - } |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -10,7 +10,7 @@ |
||
10 | 10 | public function handle(Application $app, $next) |
11 | 11 | { |
12 | 12 | |
13 | - if (! $this->session->has('error') || $this->session->get('error') != true) { |
|
13 | + if (!$this->session->has('error') || $this->session->get('error') != true) { |
|
14 | 14 | |
15 | 15 | $this->url->redirectTo('/'); |
16 | 16 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'db' => [ |
|
4 | + 'db' => [ |
|
5 | 5 | 'server' => 'localhost', |
6 | 6 | 'dbname' => 'blog', |
7 | 7 | 'dbuser' => 'root', |
8 | 8 | 'dbpass' => '' |
9 | - ], |
|
10 | - 'website' => [ |
|
9 | + ], |
|
10 | + 'website' => [ |
|
11 | 11 | 'websiteLang' => 'de', |
12 | 12 | 'websiteCharset' => 'UTF-8', |
13 | 13 | 'websiteDecsription' => 'Nice Framework', |
14 | 14 | 'websiteKeywords' => 'framework', |
15 | 15 | 'websiteAuth' => 'Refat Alsakka', |
16 | 16 | 'websiteName' => 'framework', |
17 | - ], |
|
17 | + ], |
|
18 | 18 | ]; |
19 | 19 | \ No newline at end of file |
@@ -6,71 +6,71 @@ discard block |
||
6 | 6 | |
7 | 7 | class Route |
8 | 8 | { |
9 | - const NEXT = '_NEXT_'; |
|
9 | + const NEXT = '_NEXT_'; |
|
10 | 10 | |
11 | - private $app; |
|
11 | + private $app; |
|
12 | 12 | |
13 | - private $routes = []; |
|
13 | + private $routes = []; |
|
14 | 14 | |
15 | - public $current = []; |
|
15 | + public $current = []; |
|
16 | 16 | |
17 | - private $prefix; |
|
17 | + private $prefix; |
|
18 | 18 | |
19 | - private $basController; |
|
19 | + private $basController; |
|
20 | 20 | |
21 | - private $middlewareFrom; |
|
21 | + private $middlewareFrom; |
|
22 | 22 | |
23 | - private $groupMiddleware = []; |
|
23 | + private $groupMiddleware = []; |
|
24 | 24 | |
25 | - public function __construct(Application $app) |
|
26 | - { |
|
25 | + public function __construct(Application $app) |
|
26 | + { |
|
27 | 27 | $this->app = $app; |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function add($url, $action, $requestMethos = 'GET', $middleware = []) |
|
31 | - { |
|
30 | + public function add($url, $action, $requestMethos = 'GET', $middleware = []) |
|
31 | + { |
|
32 | 32 | |
33 | 33 | if ($this->prefix) { |
34 | 34 | |
35 | - if ($this->prefix !== '/') { |
|
35 | + if ($this->prefix !== '/') { |
|
36 | 36 | |
37 | 37 | $url = $this->prefix . $url; |
38 | 38 | |
39 | 39 | $url = rtrim($url, '/'); |
40 | - } |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | if ($this->basController) $action = $this->basController . '/' . $action; |
44 | 44 | |
45 | 45 | if ($this->groupMiddleware) { |
46 | 46 | |
47 | - if (is_array($middleware)) { |
|
47 | + if (is_array($middleware)) { |
|
48 | 48 | |
49 | 49 | $middleware = array_merge($this->groupMiddleware[0], $middleware); |
50 | 50 | |
51 | - } else { |
|
51 | + } else { |
|
52 | 52 | |
53 | 53 | array_push($this->groupMiddleware[0], $middleware); |
54 | 54 | |
55 | 55 | $middleware = $this->groupMiddleware[0]; |
56 | - } |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $routes = [ |
60 | - 'url' => $url, |
|
61 | - 'pattern' => $this->generatePattern($url), |
|
62 | - 'action' => $this->getAction($action), |
|
63 | - 'method' => $requestMethos, |
|
64 | - 'middleware' => $middleware |
|
60 | + 'url' => $url, |
|
61 | + 'pattern' => $this->generatePattern($url), |
|
62 | + 'action' => $this->getAction($action), |
|
63 | + 'method' => $requestMethos, |
|
64 | + 'middleware' => $middleware |
|
65 | 65 | ]; |
66 | 66 | |
67 | 67 | $this->routes[] = $routes; |
68 | 68 | |
69 | 69 | return $this; |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - public function group($groupOptions, callable $callback) |
|
73 | - { |
|
72 | + public function group($groupOptions, callable $callback) |
|
73 | + { |
|
74 | 74 | $prefix = $groupOptions['prefix']; |
75 | 75 | $controller = $groupOptions['controller']; |
76 | 76 | $middlewareFrom = array_shift($groupOptions['middleware']); |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $callback($this); |
90 | 90 | |
91 | 91 | return $this; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - public function package($url, $controller) |
|
95 | - { |
|
94 | + public function package($url, $controller) |
|
95 | + { |
|
96 | 96 | $this->add("$url", "$controller"); |
97 | 97 | $this->add("$url/add", "$controller@add", "POST"); |
98 | 98 | $this->add("$url/submit", "$controller@submit", "POST"); |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | $this->add("$url/delete/:id", "$controller@delete", "POST"); |
102 | 102 | |
103 | 103 | return $this; |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - public function generatePattern($url) |
|
107 | - { |
|
106 | + public function generatePattern($url) |
|
107 | + { |
|
108 | 108 | $pattern = '#^'; |
109 | 109 | $pattern .= str_replace([':text', ':id'], ['([a-zA-Z0-9-]+)', '(\d+)'], $url); |
110 | 110 | $pattern .= '$#'; |
111 | 111 | |
112 | 112 | return $pattern; |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - public function getAction($action) |
|
116 | - { |
|
115 | + public function getAction($action) |
|
116 | + { |
|
117 | 117 | $action = str_replace('/', '\\', $action); |
118 | 118 | |
119 | 119 | $action = (strpos($action, '@') != 0) ? $action : $action . '@index'; |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | $action = explode('@', $action); |
122 | 122 | |
123 | 123 | return $action; |
124 | - } |
|
124 | + } |
|
125 | 125 | |
126 | - public function getProperRoute() |
|
127 | - { |
|
126 | + public function getProperRoute() |
|
127 | + { |
|
128 | 128 | foreach($this->routes as $route) { |
129 | 129 | |
130 | - if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
|
130 | + if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
|
131 | 131 | |
132 | 132 | $this->current = $route; |
133 | 133 | |
@@ -135,79 +135,79 @@ discard block |
||
135 | 135 | |
136 | 136 | if ($route['middleware']) { |
137 | 137 | |
138 | - if (is_array($route['middleware'])) { |
|
138 | + if (is_array($route['middleware'])) { |
|
139 | 139 | |
140 | 140 | foreach($route['middleware'] as $middleware) { |
141 | 141 | |
142 | - $output = $this->middleware($middleware); |
|
142 | + $output = $this->middleware($middleware); |
|
143 | 143 | |
144 | - if ($output != '') break; |
|
144 | + if ($output != '') break; |
|
145 | 145 | } |
146 | 146 | |
147 | - } else { |
|
147 | + } else { |
|
148 | 148 | |
149 | 149 | $output = $this->middleware($route['middleware']); |
150 | 150 | |
151 | 151 | if ($output != '') break; |
152 | - } |
|
152 | + } |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | if ($output == '') { |
156 | 156 | |
157 | - list($controller, $method) = $route['action']; |
|
157 | + list($controller, $method) = $route['action']; |
|
158 | 158 | |
159 | - $arguments = $this->getArgumentsFor($route['pattern']); |
|
159 | + $arguments = $this->getArgumentsFor($route['pattern']); |
|
160 | 160 | |
161 | - $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
161 | + $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
162 | 162 | |
163 | - return $output; |
|
163 | + return $output; |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | break; |
167 | - } |
|
167 | + } |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | $output = (string) $this->app->load->action('notFound', 'index', []); |
171 | 171 | |
172 | 172 | return $output; |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - public function isMatching($pattern) |
|
176 | - { |
|
175 | + public function isMatching($pattern) |
|
176 | + { |
|
177 | 177 | $url = $this->app->request->url(); |
178 | 178 | |
179 | 179 | $url = strtolower($url); |
180 | 180 | |
181 | 181 | return preg_match($pattern, $url); |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - private function isMatchingRequestMethod($method) |
|
185 | - { |
|
184 | + private function isMatchingRequestMethod($method) |
|
185 | + { |
|
186 | 186 | $methods = ['GET', 'POST']; |
187 | 187 | |
188 | 188 | if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
189 | 189 | |
190 | 190 | if (is_array($method)) { |
191 | 191 | |
192 | - if (count($method) == 1) { |
|
192 | + if (count($method) == 1) { |
|
193 | 193 | |
194 | 194 | $method = $method[0]; |
195 | 195 | |
196 | - } else if (count($method) == 2) { |
|
196 | + } else if (count($method) == 2) { |
|
197 | 197 | |
198 | 198 | if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
199 | 199 | |
200 | - } else { |
|
200 | + } else { |
|
201 | 201 | |
202 | 202 | return false; |
203 | - } |
|
203 | + } |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | return $this->app->request->method() == $method; |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - public function getArgumentsFor($pattern) |
|
210 | - { |
|
209 | + public function getArgumentsFor($pattern) |
|
210 | + { |
|
211 | 211 | $url = $this->app->request->url(); |
212 | 212 | |
213 | 213 | preg_match($pattern, $url, $matches); |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | array_shift($matches); |
216 | 216 | |
217 | 217 | return $matches; |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - public function getCurrent($key) |
|
221 | - { |
|
220 | + public function getCurrent($key) |
|
221 | + { |
|
222 | 222 | return $this->current[$key]; |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - private function middleware($middleware, $from = 'admin') |
|
226 | - { |
|
225 | + private function middleware($middleware, $from = 'admin') |
|
226 | + { |
|
227 | 227 | $middlewareInterface = 'App\\Middleware\\MiddlewaresInterface'; |
228 | 228 | |
229 | 229 | $middlewares = $this->app->alias['middlewares'][$from]; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $middlewareClass = $middlewares[$middleware]; |
232 | 232 | |
233 | 233 | if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
234 | - throw new Exception("$middlewareClass not Implement"); |
|
234 | + throw new Exception("$middlewareClass not Implement"); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $middlewareObject = new $middlewareClass; |
@@ -241,5 +241,5 @@ discard block |
||
241 | 241 | if ($output && $output === static::NEXT) $output = ''; |
242 | 242 | |
243 | 243 | return $output; |
244 | - } |
|
244 | + } |
|
245 | 245 | } |
246 | 246 | \ No newline at end of file |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $middlewareFrom = array_shift($groupOptions['middleware']); |
77 | 77 | $middleware = $groupOptions['middleware']; |
78 | 78 | |
79 | - $url = ltrim($this->app->request->url(), '/'); |
|
79 | + $url = ltrim($this->app->request->url(), '/'); |
|
80 | 80 | $check = '/' . explode('/', $url)[0]; |
81 | 81 | |
82 | 82 | if ($check !== $prefix) return $this; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | public function getProperRoute() |
127 | 127 | { |
128 | - foreach($this->routes as $route) { |
|
128 | + foreach ($this->routes as $route) { |
|
129 | 129 | |
130 | 130 | if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
131 | 131 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | if (is_array($route['middleware'])) { |
139 | 139 | |
140 | - foreach($route['middleware'] as $middleware) { |
|
140 | + foreach ($route['middleware'] as $middleware) { |
|
141 | 141 | |
142 | 142 | $output = $this->middleware($middleware); |
143 | 143 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | $middlewareClass = $middlewares[$middleware]; |
232 | 232 | |
233 | - if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
233 | + if (!in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
234 | 234 | throw new Exception("$middlewareClass not Implement"); |
235 | 235 | } |
236 | 236 |
@@ -40,7 +40,9 @@ discard block |
||
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | - if ($this->basController) $action = $this->basController . '/' . $action; |
|
43 | + if ($this->basController) { |
|
44 | + $action = $this->basController . '/' . $action; |
|
45 | + } |
|
44 | 46 | |
45 | 47 | if ($this->groupMiddleware) { |
46 | 48 | |
@@ -79,7 +81,9 @@ discard block |
||
79 | 81 | $url = ltrim($this->app->request->url(), '/'); |
80 | 82 | $check = '/' . explode('/', $url)[0]; |
81 | 83 | |
82 | - if ($check !== $prefix) return $this; |
|
84 | + if ($check !== $prefix) { |
|
85 | + return $this; |
|
86 | + } |
|
83 | 87 | |
84 | 88 | $this->prefix = $prefix; |
85 | 89 | $this->basController = $controller; |
@@ -141,14 +145,18 @@ discard block |
||
141 | 145 | |
142 | 146 | $output = $this->middleware($middleware); |
143 | 147 | |
144 | - if ($output != '') break; |
|
148 | + if ($output != '') { |
|
149 | + break; |
|
150 | + } |
|
145 | 151 | } |
146 | 152 | |
147 | 153 | } else { |
148 | 154 | |
149 | 155 | $output = $this->middleware($route['middleware']); |
150 | 156 | |
151 | - if ($output != '') break; |
|
157 | + if ($output != '') { |
|
158 | + break; |
|
159 | + } |
|
152 | 160 | } |
153 | 161 | } |
154 | 162 | |
@@ -185,7 +193,9 @@ discard block |
||
185 | 193 | { |
186 | 194 | $methods = ['GET', 'POST']; |
187 | 195 | |
188 | - if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
|
196 | + if (($method == 'both') && in_array($this->app->request->method(), $methods)) { |
|
197 | + return true; |
|
198 | + } |
|
189 | 199 | |
190 | 200 | if (is_array($method)) { |
191 | 201 | |
@@ -195,7 +205,9 @@ discard block |
||
195 | 205 | |
196 | 206 | } else if (count($method) == 2) { |
197 | 207 | |
198 | - if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
|
208 | + if (in_array($method[0], $methods) && in_array($method[1], $methods)) { |
|
209 | + return true; |
|
210 | + } |
|
199 | 211 | |
200 | 212 | } else { |
201 | 213 | |
@@ -238,7 +250,9 @@ discard block |
||
238 | 250 | |
239 | 251 | $output = $middlewareObject->handle($this->app, static::NEXT); |
240 | 252 | |
241 | - if ($output && $output === static::NEXT) $output = ''; |
|
253 | + if ($output && $output === static::NEXT) { |
|
254 | + $output = ''; |
|
255 | + } |
|
242 | 256 | |
243 | 257 | return $output; |
244 | 258 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class DataProtectionController extends Controller |
8 | 8 | { |
9 | - public function index() |
|
10 | - { |
|
9 | + public function index() |
|
10 | + { |
|
11 | 11 | $context = [ |
12 | 12 | |
13 | 13 | ]; |
14 | 14 | return $this->PugView->render('website/pages/dataProtection', $context); |
15 | - } |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |