@@ -50,7 +50,7 @@ |
||
50 | 50 | 'middleware_pipeline' => [ |
51 | 51 | // execute this middlweare on every /admin[*] path |
52 | 52 | 'permission' => [ |
53 | - 'middleware' => [Middleware\AdminAuth::class], |
|
53 | + 'middleware' => [ Middleware\AdminAuth::class ], |
|
54 | 54 | 'priority' => 100, |
55 | 55 | 'path' => '/admin' |
56 | 56 | ], |
@@ -39,6 +39,6 @@ |
||
39 | 39 | */ |
40 | 40 | public function __invoke(Request $request, Response $response, callable $next = null) |
41 | 41 | { |
42 | - return new HtmlResponse($this->template->render('admin::index', ['layout' => 'layout/admin'])); |
|
42 | + return new HtmlResponse($this->template->render('admin::index', [ 'layout' => 'layout/admin' ])); |
|
43 | 43 | } |
44 | 44 | } |
@@ -98,7 +98,7 @@ |
||
98 | 98 | /** |
99 | 99 | * Clears user session. |
100 | 100 | * |
101 | - * @return static |
|
101 | + * @return \Psr\Http\Message\ResponseInterface |
|
102 | 102 | */ |
103 | 103 | public function logout(): \Psr\Http\Message\ResponseInterface |
104 | 104 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types=1); |
|
2 | +declare(strict_types = 1); |
|
3 | 3 | |
4 | 4 | namespace Admin\Controller; |
5 | 5 | |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function login($error = false): \Psr\Http\Message\ResponseInterface |
62 | 62 | { |
63 | - if($this->session->getStorage()->user) { |
|
63 | + if ($this->session->getStorage()->user) { |
|
64 | 64 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin')); |
65 | 65 | } |
66 | 66 | |
67 | - return new HtmlResponse($this->template->render('admin::login', ['layout' => false, 'error' => $error])); |
|
67 | + return new HtmlResponse($this->template->render('admin::login', [ 'layout' => false, 'error' => $error ])); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function loginHandle(): \Psr\Http\Message\ResponseInterface |
76 | 76 | { |
77 | - if($this->session->getStorage()->user) { |
|
77 | + if ($this->session->getStorage()->user) { |
|
78 | 78 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin')); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $data = $this->request->getParsedBody(); |
82 | - $email = isset($data['email']) ? $data['email'] : null; |
|
83 | - $password = isset($data['password']) ? $data['password'] : null; |
|
82 | + $email = isset($data[ 'email' ]) ? $data[ 'email' ] : null; |
|
83 | + $password = isset($data[ 'password' ]) ? $data[ 'password' ] : null; |
|
84 | 84 | |
85 | 85 | try { |
86 | 86 | $this->session->getStorage()->user = $this->adminUserService->loginUser($email, $password); |
87 | 87 | |
88 | 88 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin')); |
89 | 89 | } |
90 | - catch(\Exception $e) { |
|
90 | + catch (\Exception $e) { |
|
91 | 91 | return $this->login($e->getMessage()); |
92 | 92 | |
93 | 93 | //@todo set $e->getMessage() to flash messanger and print messages in next page |
@@ -86,8 +86,7 @@ |
||
86 | 86 | $this->session->getStorage()->user = $this->adminUserService->loginUser($email, $password); |
87 | 87 | |
88 | 88 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin')); |
89 | - } |
|
90 | - catch(\Exception $e) { |
|
89 | + } catch(\Exception $e) { |
|
91 | 90 | return $this->login($e->getMessage()); |
92 | 91 | |
93 | 92 | //@todo set $e->getMessage() to flash messanger and print messages in next page |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | 'partial/menu-level' => __DIR__ . '/../templates/partial/menu-level.phtml', |
13 | 13 | ], |
14 | 14 | 'paths' => [ |
15 | - 'menu' => [__DIR__ . '/../templates/menu'], |
|
15 | + 'menu' => [ __DIR__ . '/../templates/menu' ], |
|
16 | 16 | ], |
17 | 17 | ], |
18 | 18 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | 'name' => 'admin.menu', |
34 | 34 | 'path' => '/admin/menu', |
35 | 35 | 'middleware' => Controller\IndexController::class, |
36 | - 'allowed_methods' => ['GET'], |
|
36 | + 'allowed_methods' => [ 'GET' ], |
|
37 | 37 | ], |
38 | 38 | [ |
39 | 39 | 'name' => 'admin.menu.action', |
40 | 40 | 'path' => '/admin/menu/:action/:id', |
41 | 41 | 'middleware' => Controller\IndexController::class, |
42 | - 'allowed_methods' => ['GET', 'POST'], |
|
42 | + 'allowed_methods' => [ 'GET', 'POST' ], |
|
43 | 43 | ], |
44 | 44 | ], |
45 | 45 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | public function getMessages(array $msgs) |
20 | 20 | { |
21 | 21 | $allMsgs = ''; |
22 | - array_walk_recursive($msgs, function ($value) use (&$allMsgs){ |
|
22 | + array_walk_recursive($msgs, function($value) use (&$allMsgs){ |
|
23 | 23 | $allMsgs .= "- " . $value . "<br/>"; |
24 | 24 | }); |
25 | 25 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | return [ |
10 | 10 | 'templates' => [ |
11 | 11 | 'paths' => [ |
12 | - 'category' => [__DIR__ . '/../templates/category'], |
|
12 | + 'category' => [ __DIR__ . '/../templates/category' ], |
|
13 | 13 | ], |
14 | 14 | ], |
15 | 15 | |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | 'name' => 'admin.categories', |
31 | 31 | 'path' => '/admin/categories', |
32 | 32 | 'middleware' => Controller\IndexController::class, |
33 | - 'allowed_methods' => ['GET'], |
|
33 | + 'allowed_methods' => [ 'GET' ], |
|
34 | 34 | ], |
35 | 35 | [ |
36 | 36 | 'name' => 'admin.categories.action', |
37 | 37 | 'path' => '/admin/categories/:action/:id', |
38 | 38 | 'middleware' => Controller\IndexController::class, |
39 | - 'allowed_methods' => ['GET', 'POST'] |
|
39 | + 'allowed_methods' => [ 'GET', 'POST' ] |
|
40 | 40 | ], |
41 | 41 | ], |
42 | 42 |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | public function index() : \Psr\Http\Message\ResponseInterface |
48 | 48 | { |
49 | 49 | $params = $this->request->getQueryParams(); |
50 | - $page = isset($params['page']) ? $params['page'] : 1; |
|
51 | - $limit = isset($params['limit']) ? $params['limit'] : 15; |
|
50 | + $page = isset($params[ 'page' ]) ? $params[ 'page' ] : 1; |
|
51 | + $limit = isset($params[ 'limit' ]) ? $params[ 'limit' ] : 15; |
|
52 | 52 | |
53 | 53 | $categories = $this->categoryService->getPagination($page, $limit); |
54 | 54 | |
55 | - return new HtmlResponse($this->template->render('category::index/index', ['list' => $categories, 'layout' => 'layout/admin'])); |
|
55 | + return new HtmlResponse($this->template->render('category::index/index', [ 'list' => $categories, 'layout' => 'layout/admin' ])); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return \Psr\Http\Message\ResponseInterface |
62 | 62 | */ |
63 | - public function edit($errors = []): \Psr\Http\Message\ResponseInterface |
|
63 | + public function edit($errors = [ ]): \Psr\Http\Message\ResponseInterface |
|
64 | 64 | { |
65 | 65 | $id = $this->request->getAttribute('id'); |
66 | 66 | $category = $this->categoryService->getCategory($id); |
67 | 67 | |
68 | - if($this->request->getParsedBody()){ |
|
69 | - $category = (object)($this->request->getParsedBody() + (array)$category); |
|
68 | + if ($this->request->getParsedBody()) { |
|
69 | + $category = (object) ($this->request->getParsedBody() + (array) $category); |
|
70 | 70 | $category->category_id = $id; |
71 | 71 | } |
72 | 72 | |
@@ -79,36 +79,36 @@ discard block |
||
79 | 79 | |
80 | 80 | public function save() |
81 | 81 | { |
82 | - try{ |
|
82 | + try { |
|
83 | 83 | $id = $this->request->getAttribute('id'); |
84 | 84 | $data = $this->request->getParsedBody(); |
85 | 85 | |
86 | - if($id){ |
|
86 | + if ($id) { |
|
87 | 87 | $this->categoryService->updateCategory($data, $id); |
88 | 88 | } |
89 | - else{ |
|
89 | + else { |
|
90 | 90 | $this->categoryService->createCategory($data); |
91 | 91 | } |
92 | 92 | |
93 | 93 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
94 | 94 | } |
95 | - catch(FilterException $fe){ |
|
95 | + catch (FilterException $fe) { |
|
96 | 96 | return $this->edit($fe->getArrayMessages()); |
97 | 97 | } |
98 | - catch(\Exception $e){ |
|
98 | + catch (\Exception $e) { |
|
99 | 99 | throw $e; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | public function delete() |
104 | 104 | { |
105 | - try{ |
|
105 | + try { |
|
106 | 106 | $id = $this->request->getAttribute('id'); |
107 | 107 | $this->categoryService->delete($id); |
108 | 108 | |
109 | 109 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
110 | 110 | } |
111 | - catch(\Exception $e){ |
|
111 | + catch (\Exception $e) { |
|
112 | 112 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
113 | 113 | } |
114 | 114 | } |
@@ -85,17 +85,14 @@ discard block |
||
85 | 85 | |
86 | 86 | if($id){ |
87 | 87 | $this->categoryService->updateCategory($data, $id); |
88 | - } |
|
89 | - else{ |
|
88 | + } else{ |
|
90 | 89 | $this->categoryService->createCategory($data); |
91 | 90 | } |
92 | 91 | |
93 | 92 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
94 | - } |
|
95 | - catch(FilterException $fe){ |
|
93 | + } catch(FilterException $fe){ |
|
96 | 94 | return $this->edit($fe->getArrayMessages()); |
97 | - } |
|
98 | - catch(\Exception $e){ |
|
95 | + } catch(\Exception $e){ |
|
99 | 96 | throw $e; |
100 | 97 | } |
101 | 98 | } |
@@ -107,8 +104,7 @@ discard block |
||
107 | 104 | $this->categoryService->delete($id); |
108 | 105 | |
109 | 106 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
110 | - } |
|
111 | - catch(\Exception $e){ |
|
107 | + } catch(\Exception $e){ |
|
112 | 108 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
113 | 109 | } |
114 | 110 | } |
@@ -12,11 +12,11 @@ |
||
12 | 12 | { |
13 | 13 | public function up() |
14 | 14 | { |
15 | - $this->table('article_categories', ['id' => true, 'primary_key' => 'id']) |
|
16 | - ->addColumn('category_uuid', 'binary', ['limit' => 16]) |
|
17 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
18 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
19 | - ->addForeignKey('category_uuid', 'category', 'category_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
15 | + $this->table('article_categories', [ 'id' => true, 'primary_key' => 'id' ]) |
|
16 | + ->addColumn('category_uuid', 'binary', [ 'limit' => 16 ]) |
|
17 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
18 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
19 | + ->addForeignKey('category_uuid', 'category', 'category_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
20 | 20 | ->create(); |
21 | 21 | |
22 | 22 | //$this->insertDummyData(); |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | public function up() |
9 | 9 | { |
10 | - $this->table('menu', ['id' => false, 'primary_key' => 'menu_uuid']) |
|
11 | - ->addColumn('menu_uuid', 'binary', ['limit' => 16]) |
|
10 | + $this->table('menu', [ 'id' => false, 'primary_key' => 'menu_uuid' ]) |
|
11 | + ->addColumn('menu_uuid', 'binary', [ 'limit' => 16 ]) |
|
12 | 12 | ->addColumn('menu_id', 'text') |
13 | - ->addColumn('parent_id', 'text', ['null' => true]) |
|
13 | + ->addColumn('parent_id', 'text', [ 'null' => true ]) |
|
14 | 14 | ->addColumn('title', 'text') |
15 | - ->addColumn('href', 'text', ['null' => true]) |
|
16 | - ->addColumn('is_active', 'boolean', ['default' => false]) |
|
17 | - ->addColumn('is_in_header', 'boolean', ['default' => true]) |
|
18 | - ->addColumn('is_in_footer', 'boolean', ['default' => true]) |
|
19 | - ->addColumn('is_in_side', 'boolean', ['default' => true]) |
|
20 | - ->addColumn('order_no', 'integer', ['default' => 0]) |
|
21 | - ->addColumn('created_at', 'datetime', ['null' => true]) |
|
15 | + ->addColumn('href', 'text', [ 'null' => true ]) |
|
16 | + ->addColumn('is_active', 'boolean', [ 'default' => false ]) |
|
17 | + ->addColumn('is_in_header', 'boolean', [ 'default' => true ]) |
|
18 | + ->addColumn('is_in_footer', 'boolean', [ 'default' => true ]) |
|
19 | + ->addColumn('is_in_side', 'boolean', [ 'default' => true ]) |
|
20 | + ->addColumn('order_no', 'integer', [ 'default' => 0 ]) |
|
21 | + ->addColumn('created_at', 'datetime', [ 'null' => true ]) |
|
22 | 22 | //->addForeignKey('parent_id', 'menu', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) # we can not add constraints |
23 | - ->addColumn('article_uuid', 'binary', ['limit' => 16, 'null' => true]) |
|
24 | - ->addColumn('category_uuid', 'binary', ['limit' => 16, 'null' => true]) |
|
25 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
26 | - ->addForeignKey('category_uuid', 'category', 'category_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
23 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16, 'null' => true ]) |
|
24 | + ->addColumn('category_uuid', 'binary', [ 'limit' => 16, 'null' => true ]) |
|
25 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
26 | + ->addForeignKey('category_uuid', 'category', 'category_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
27 | 27 | ->create(); |
28 | 28 | } |
29 | 29 |