1 | <?php |
||
21 | class SampleAppController implements AppInjectableInterface |
||
22 | { |
||
23 | use AppInjectableTrait; |
||
24 | |||
25 | |||
26 | |||
27 | /** |
||
28 | * @var string $db a sample member variable that gets initialised |
||
29 | */ |
||
30 | private $db = "not active"; |
||
31 | |||
32 | |||
33 | |||
34 | /** |
||
35 | * The initialize method is optional and will always be called before the |
||
36 | * target method/action. This is a convienient method where you could |
||
37 | * setup internal properties that are commonly used by several methods. |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | 10 | public function initialize() : void |
|
48 | |||
49 | |||
50 | |||
51 | /** |
||
52 | * This is the index method action, it handles: |
||
53 | * ANY METHOD mountpoint |
||
54 | * ANY METHOD mountpoint/ |
||
55 | * ANY METHOD mountpoint/index |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | 1 | public function indexAction() : string |
|
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * This sample method dumps the content of $app. |
||
69 | * GET mountpoint/dump-app |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function dumpAppActionGet() : string |
|
79 | |||
80 | |||
81 | |||
82 | /** |
||
83 | * Add the request method to the method name to limit what request methods |
||
84 | * the handler supports. |
||
85 | * GET mountpoint/info |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 1 | public function infoActionGet() : string |
|
94 | |||
95 | |||
96 | |||
97 | /** |
||
98 | * This sample method action it the handler for route: |
||
99 | * GET mountpoint/create |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 1 | public function createActionGet() : string |
|
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * This sample method action it the handler for route: |
||
113 | * POST mountpoint/create |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 1 | public function createActionPost() : string |
|
122 | |||
123 | |||
124 | |||
125 | /** |
||
126 | * This sample method action takes one argument: |
||
127 | * GET mountpoint/argument/<value> |
||
128 | * |
||
129 | * @param mixed $value |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 1 | public function argumentActionGet($value) : string |
|
138 | |||
139 | |||
140 | |||
141 | /** |
||
142 | * This sample method action takes zero or one argument and you can use - as a separator which will then be removed: |
||
143 | * GET mountpoint/defaultargument/ |
||
144 | * GET mountpoint/defaultargument/<value> |
||
145 | * GET mountpoint/default-argument/ |
||
146 | * GET mountpoint/default-argument/<value> |
||
147 | * |
||
148 | * @param mixed $value with a default string. |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 1 | public function defaultArgumentActionGet($value = "default") : string |
|
157 | |||
158 | |||
159 | |||
160 | /** |
||
161 | * This sample method action takes two typed arguments: |
||
162 | * GET mountpoint/typed-argument/<string>/<int> |
||
163 | * |
||
164 | * NOTE. Its recommended to not use int as type since it will still |
||
165 | * accept numbers such as 2hundred givving a PHP NOTICE. So, its better to |
||
166 | * deal with type check within the action method and throuw exceptions |
||
167 | * when the expected type is not met. |
||
168 | * |
||
169 | * @param mixed $value with a default string. |
||
|
|||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public function typedArgumentActionGet(string $str, int $int) : string |
|
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * This sample method action takes a variadic list of arguments: |
||
183 | * GET mountpoint/variadic/ |
||
184 | * GET mountpoint/variadic/<value> |
||
185 | * GET mountpoint/variadic/<value>/<value> |
||
186 | * GET mountpoint/variadic/<value>/<value>/<value> |
||
187 | * etc. |
||
188 | * |
||
189 | * @param array $value as a variadic parameter. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 1 | public function variadicActionGet(...$value) : string |
|
198 | |||
199 | |||
200 | |||
201 | /** |
||
202 | * Adding an optional catchAll() method will catch all actions sent to the |
||
203 | * router. You can then reply with an actual response or return void to |
||
204 | * allow for the router to move on to next handler. |
||
205 | * A catchAll() handles the following, if a specific action method is not |
||
206 | * created: |
||
207 | * ANY METHOD mountpoint/** |
||
208 | * |
||
209 | * @param array $args as a variadic parameter. |
||
210 | * |
||
211 | * @return mixed |
||
212 | * |
||
213 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
214 | */ |
||
215 | 1 | public function catchAll(...$args) |
|
221 | } |
||
222 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.