1 | <?php |
||
18 | class SampleController implements ContainerInjectableInterface |
||
19 | { |
||
20 | use ContainerInjectableTrait; |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * @var string $db a sample member variable that gets initialised |
||
26 | */ |
||
27 | private $db = "not active"; |
||
28 | |||
29 | |||
30 | |||
31 | /** |
||
32 | * The initialize method is optional and will always be called before the |
||
33 | * target method/action. This is a convienient method where you could |
||
34 | * setup internal properties that are commonly used by several methods. |
||
35 | * |
||
36 | * @return void |
||
37 | */ |
||
38 | public function initialize() : void |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * This is the index method action, it handles: |
||
48 | * ANY METHOD mountpoint |
||
49 | * ANY METHOD mountpoint/ |
||
50 | * ANY METHOD mountpoint/index |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function indexAction() : string |
||
59 | |||
60 | |||
61 | |||
62 | /** |
||
63 | * Add the request method to the method name to limit what request methods |
||
64 | * the handler supports. |
||
65 | * GET mountpoint/info |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | public function infoActionGet() : string |
||
74 | |||
75 | |||
76 | |||
77 | /** |
||
78 | * This sample method action it the handler for route: |
||
79 | * GET mountpoint/create |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function createActionGet() : string |
||
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * This sample method action it the handler for route: |
||
93 | * POST mountpoint/create |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function createActionPost() : string |
||
102 | |||
103 | |||
104 | |||
105 | /** |
||
106 | * This sample method action takes one argument: |
||
107 | * GET mountpoint/argument/<value> |
||
108 | * |
||
109 | * @param mixed $value |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function argumentActionGet($value) : string |
||
118 | |||
119 | |||
120 | |||
121 | /** |
||
122 | * This sample method action takes zero or one argument and you can use - as a separator which will then be removed: |
||
123 | * GET mountpoint/defaultargument/ |
||
124 | * GET mountpoint/defaultargument/<value> |
||
125 | * GET mountpoint/default-argument/ |
||
126 | * GET mountpoint/default-argument/<value> |
||
127 | * |
||
128 | * @param mixed $value with a default string. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function defaultArgumentActionGet($value = "default") : string |
||
137 | |||
138 | |||
139 | |||
140 | /** |
||
141 | * This sample method action takes two typed arguments: |
||
142 | * GET mountpoint/typed-argument/<string>/<int> |
||
143 | * |
||
144 | * NOTE. Its recommended to not use int as type since it will still |
||
145 | * accept numbers such as 2hundred givving a PHP NOTICE. So, its better to |
||
146 | * deal with type check within the action method and throuw exceptions |
||
147 | * when the expected type is not met. |
||
148 | * |
||
149 | * @param mixed $value with a default string. |
||
|
|||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function typedArgumentActionGet(string $str, int $int) : string |
||
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * This sample method action takes a variadic list of arguments: |
||
163 | * GET mountpoint/variadic/ |
||
164 | * GET mountpoint/variadic/<value> |
||
165 | * GET mountpoint/variadic/<value>/<value> |
||
166 | * GET mountpoint/variadic/<value>/<value>/<value> |
||
167 | * etc. |
||
168 | * |
||
169 | * @param array $value as a variadic parameter. |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function variadicActionGet(...$value) : string |
||
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * Adding an optional catchAll() method will catch all actions sent to the |
||
183 | * router. YOu can then reply with an actual response or return void to |
||
184 | * allow for the router to move on to next handler. |
||
185 | * A catchAll() handles the following, if a specific action method is not |
||
186 | * created: |
||
187 | * ANY METHOD mountpoint/** |
||
188 | * |
||
189 | * @param array $args as a variadic parameter. |
||
190 | * |
||
191 | * @return mixed |
||
192 | */ |
||
193 | public function catchAll(...$args) |
||
199 | } |
||
200 |
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.