@@ -73,6 +73,9 @@ |
||
73 | 73 | return [$controller, $action]; |
74 | 74 | } |
75 | 75 | |
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
76 | 79 | abstract protected function getControllerClass(ServerRequestInterface $request); |
77 | 80 | |
78 | 81 | /** |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | |
11 | 11 | abstract class EndPoint implements RequestHandlerInterface |
12 | 12 | { |
13 | - /** @var string|null */ |
|
14 | - protected $controller; |
|
15 | - /** @var string|null */ |
|
16 | - protected $action; |
|
17 | - /** @var string */ |
|
13 | + /** @var string|null */ |
|
14 | + protected $controller; |
|
15 | + /** @var string|null */ |
|
16 | + protected $action; |
|
17 | + /** @var string */ |
|
18 | 18 | protected $prefix = ''; |
19 | 19 | |
20 | 20 | public function __construct(array $params = []) |
@@ -33,26 +33,26 @@ discard block |
||
33 | 33 | * @throws \BadMethodCallException |
34 | 34 | */ |
35 | 35 | public function handle(ServerRequestInterface $request): ResponseInterface |
36 | - { |
|
37 | - $route = $this->getRoute($request); |
|
36 | + { |
|
37 | + $route = $this->getRoute($request); |
|
38 | 38 | $endPoint = $this->getPoint($request); |
39 | 39 | |
40 | 40 | $params = $this->getParams($route); |
41 | 41 | return $endPoint(...$params); |
42 | 42 | } |
43 | 43 | |
44 | - /** |
|
45 | - * Get params from router and remove all protected params (_controller/_action/_other) |
|
46 | - * |
|
47 | - * @param Route $route |
|
48 | - * @return array |
|
49 | - */ |
|
44 | + /** |
|
45 | + * Get params from router and remove all protected params (_controller/_action/_other) |
|
46 | + * |
|
47 | + * @param Route $route |
|
48 | + * @return array |
|
49 | + */ |
|
50 | 50 | protected function getParams(Route $route): array |
51 | - { |
|
51 | + { |
|
52 | 52 | return array_filter($route->getMatchesParams(), function ($name) { |
53 | 53 | return $name[0] !== '_'; |
54 | 54 | }, ARRAY_FILTER_USE_KEY); |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @param ServerRequestInterface $request |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return callable |
61 | 61 | * @throws \BadMethodCallException |
62 | 62 | */ |
63 | - protected function getPoint(ServerRequestInterface $request) : callable |
|
63 | + protected function getPoint(ServerRequestInterface $request) : callable |
|
64 | 64 | { |
65 | 65 | $controller = $this->getControllerClass($request); |
66 | 66 | $this->checkController($controller); |
@@ -75,37 +75,37 @@ discard block |
||
75 | 75 | |
76 | 76 | abstract protected function getControllerClass(ServerRequestInterface $request); |
77 | 77 | |
78 | - /** |
|
79 | - * @param string $controller |
|
80 | - * @throws \BadMethodCallException |
|
81 | - */ |
|
82 | - protected function checkController(string $controller) : void |
|
78 | + /** |
|
79 | + * @param string $controller |
|
80 | + * @throws \BadMethodCallException |
|
81 | + */ |
|
82 | + protected function checkController(string $controller) : void |
|
83 | 83 | { |
84 | 84 | if (!class_exists($controller)) { |
85 | 85 | throw new \BadMethodCallException('Controller not found'); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * @param \object $controller |
|
91 | - * @param string $action |
|
92 | - * @throws \BadMethodCallException |
|
93 | - */ |
|
94 | - protected function checkAction(object $controller, string $action) : void |
|
89 | + /** |
|
90 | + * @param \object $controller |
|
91 | + * @param string $action |
|
92 | + * @throws \BadMethodCallException |
|
93 | + */ |
|
94 | + protected function checkAction(object $controller, string $action) : void |
|
95 | 95 | { |
96 | 96 | if (!method_exists($controller, $action)) { |
97 | 97 | throw new \BadMethodCallException('Action not found'); |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - protected function getAction(ServerRequestInterface $request): ?string |
|
102 | - { |
|
101 | + protected function getAction(ServerRequestInterface $request): ?string |
|
102 | + { |
|
103 | 103 | $route = $this->getRoute($request); |
104 | 104 | $matches = $route->getMatchesParams(); |
105 | - return $matches['_action'] ?? $this->action ?? null; |
|
106 | - } |
|
105 | + return $matches['_action'] ?? $this->action ?? null; |
|
106 | + } |
|
107 | 107 | |
108 | - protected function getRoute(ServerRequestInterface $request): Route |
|
108 | + protected function getRoute(ServerRequestInterface $request): Route |
|
109 | 109 | { |
110 | 110 | return $request->getAttribute('route'); |
111 | 111 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | protected function getParams(Route $route): array |
51 | 51 | { |
52 | - return array_filter($route->getMatchesParams(), function ($name) { |
|
52 | + return array_filter($route->getMatchesParams(), function($name) { |
|
53 | 53 | return $name[0] !== '_'; |
54 | 54 | }, ARRAY_FILTER_USE_KEY); |
55 | 55 | } |
@@ -18,13 +18,13 @@ |
||
18 | 18 | throw new \BadMethodCallException('Not found controller name for dynamic controller point'); |
19 | 19 | } |
20 | 20 | |
21 | - return $this->prefix . $this->normalizeClassFromUrl($matches['_controller']); |
|
21 | + return $this->prefix.$this->normalizeClassFromUrl($matches['_controller']); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | protected function normalizeClassFromUrl(string $class) : string |
25 | 25 | { |
26 | - return array_reduce(explode('-', $class), function ($prev, $item) { |
|
27 | - return $prev . ucfirst($item); |
|
26 | + return array_reduce(explode('-', $class), function($prev, $item) { |
|
27 | + return $prev.ucfirst($item); |
|
28 | 28 | }); |
29 | 29 | } |
30 | 30 |