1 | <?php |
||
7 | class Order { |
||
8 | |||
9 | /** |
||
10 | * @var string The path pattern. |
||
11 | */ |
||
12 | private $uri; |
||
13 | |||
14 | /** |
||
15 | * @var callable The callback response. |
||
16 | */ |
||
17 | private $response; |
||
18 | |||
19 | /** |
||
20 | * @var string The request method for the path pattern. |
||
21 | */ |
||
22 | private $method; |
||
23 | |||
24 | /** |
||
25 | * @var array Contains all middlewares associate to the action. |
||
26 | */ |
||
27 | private $middlewares = []; |
||
28 | |||
29 | /** |
||
30 | * @var array The types that are supported(for middlewares). |
||
31 | */ |
||
32 | private $middlewareTypes = ['before', 'after']; |
||
33 | |||
34 | public function __construct($uri, $method, $response, array $middlewares = []) { |
||
35 | $this->uri = $uri; |
||
36 | $this->method = $method; |
||
37 | $this->response = $response; |
||
38 | if($this->isValidMiddleware($middlewares)) { |
||
39 | $this->middlewares = $middlewares; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Returns the uri(the pattern path). |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | |||
49 | public function getUri() { |
||
52 | |||
53 | /** |
||
54 | * Returns the request method registered. |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | |||
59 | public function getMethod() { |
||
62 | |||
63 | /** |
||
64 | * Returns the callback associated to the pattern. |
||
65 | * |
||
66 | * @return mixed |
||
67 | */ |
||
68 | |||
69 | public function getResponse() { |
||
72 | |||
73 | /** |
||
74 | * Returns a list of middlewares registered. |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | |||
79 | public function getMiddlewares() { |
||
82 | |||
83 | /** |
||
84 | * Checks if the middleware contains before callback. |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | |||
89 | public function hasBefore() { |
||
92 | |||
93 | /** |
||
94 | * Checks if the middleware contains after callback. |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | |||
99 | public function hasAfter() { |
||
102 | |||
103 | /** |
||
104 | * Checks if middlewares passed as an associative array |
||
105 | * don't contain keys different to "before" and "after". |
||
106 | * |
||
107 | * @param array $middleware The associative array containing |
||
108 | * middleware callbacks. |
||
109 | * @return bool |
||
110 | * @throws InvalidMiddlewareException |
||
111 | */ |
||
112 | |||
113 | private function isValidMiddleware($middleware) { |
||
130 | } |