| Conditions | 9 |
| Paths | 14 |
| Total Lines | 47 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 50.472 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 69 | public function call(Micro $api) |
|
| 27 | { |
||
| 28 | 69 | $auth = $api->getService('auth'); |
|
| 29 | 69 | $router = $api->getService('router'); |
|
| 30 | 69 | $request = $api->getService('request'); |
|
| 31 | |||
| 32 | 69 | if (!$auth->isIgnoreUri()) { |
|
| 33 | // explode() by / , postiion #1 is always the controller , so its the resource ^.^ |
||
| 34 | $matchRouter = explode('/', $router->getMatchedRoute()->getCompiledPattern()); |
||
| 35 | $resource = ucfirst($matchRouter[2]); //2 is alwasy the controller of the router |
||
| 36 | $userData = $api->getService('userData'); |
||
| 37 | |||
| 38 | $action = null; |
||
| 39 | // GET -> read |
||
| 40 | // PUT -> update |
||
| 41 | // DELETE -> delete |
||
| 42 | // POST -> create |
||
| 43 | |||
| 44 | switch (strtolower($request->getMethod())) { |
||
| 45 | case 'get': |
||
| 46 | $action = 'list'; |
||
| 47 | if (preg_match("/\/([0-9]+)(?=[^\/]*$)/", $request->getURI())) { |
||
| 48 | $action = 'read'; |
||
| 49 | } |
||
| 50 | break; |
||
| 51 | case 'post': |
||
| 52 | $action = 'create'; |
||
| 53 | break; |
||
| 54 | case 'delete': |
||
| 55 | $action = 'delete'; |
||
| 56 | break; |
||
| 57 | case 'put': |
||
| 58 | case 'patch': |
||
| 59 | $action = 'update'; |
||
| 60 | break; |
||
| 61 | default: |
||
| 62 | throw new ServerErrorHttpException('No Permission define for this action'); |
||
| 63 | break; |
||
| 64 | } |
||
| 65 | |||
| 66 | //do you have permision |
||
| 67 | if (!$userData->can($resource . '.' . $action)) { |
||
| 68 | throw new PermissionException('You dont have permission to run this action ' . $action . ' at ' . $resource); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | 69 | return true; |
|
| 73 | } |
||
| 75 |