Total Complexity | 3 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | abstract class Action extends \yii\base\Action |
||
12 | { |
||
13 | /** |
||
14 | * The access control list for this endpoint |
||
15 | * @var array |
||
16 | */ |
||
17 | public $acl; |
||
18 | |||
19 | /** |
||
20 | * Action runner |
||
21 | * |
||
22 | * @param mixed $id |
||
23 | * @param array $args |
||
24 | * @return mixed |
||
25 | * @throws HttpException |
||
26 | */ |
||
27 | public function run($id = null, array $args = []) |
||
28 | { |
||
29 | $method = strtolower(Yii::$app->request->method); |
||
30 | |||
31 | // Make sure the method exists before trying to call it |
||
32 | if (method_exists(get_called_class(), $method)) { |
||
33 | return $this->$method(\array_merge(['id' => $id], $args)); |
||
34 | } |
||
35 | |||
36 | // Return a 405 if the method isn't implemented |
||
37 | // When coupled with RestController, this should _never_ get called |
||
38 | // But this is the correct response if for some reason it isn't |
||
39 | throw new HttpException(405); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * HTTP Options defaults |
||
44 | * @param array $params |
||
45 | * @return void |
||
46 | */ |
||
47 | public function options(array $params = []) |
||
51 | } |
||
52 | } |
||
53 |