| Conditions | 7 |
| Paths | 10 |
| Total Lines | 45 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 30.0568 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 2 | public function call(Micro $api) |
|
| 27 | {
|
||
| 28 | 2 | $auth = $api->getService('auth');
|
|
| 29 | 2 | $router = $api->getService('router');
|
|
| 30 | 2 | $request = $api->getService('request');
|
|
| 31 | |||
| 32 | 2 | 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 = 'read'; |
||
| 47 | break; |
||
| 48 | case 'post': |
||
| 49 | $action = 'create'; |
||
| 50 | break; |
||
| 51 | case 'delete': |
||
| 52 | $action = 'delete'; |
||
| 53 | break; |
||
| 54 | case 'pute': |
||
| 55 | $action = 'update'; |
||
| 56 | break; |
||
| 57 | default: |
||
| 58 | throw new ServerErrorHttpException('No Permission define for this action');
|
||
| 59 | break; |
||
| 60 | } |
||
| 61 | |||
| 62 | //do you have permision |
||
| 63 | if (!$userData->can($resource . '.' . $action)) {
|
||
| 64 | throw new PermissionException('You dont have permission to run this action ' . $action . ' at ' . $resource);
|
||
| 65 | $api->stop(); |
||
| 66 | return false; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | 2 | return true; |
|
| 71 | } |
||
| 73 |