private function loadMethod($newController) { $isMethodExists = false; $reflectionController = new ReflectionClass($newController); $reflectionMethods = $reflectionController->getMethods(); $roles = App::getInstance()->getInstance()->getConfig()->roles; $bindingModel = null; foreach ($reflectionMethods as $reflectionMethod) { if ($this->method === $reflectionMethod->getName()) { $doc = $reflectionMethod->getDocComment(); $annotations = array(); preg_match_all('#@(.*?)\\n#s', $doc, $annotations); foreach ($annotations[1] as $annotation) { $annotation = trim($annotation); if ($annotation === "POST" && $this->input->hasGet()) { throw new \Exception("Cannot access Post method with Get request", 406); } if ($annotation === "GET" && $this->input->hasPost()) { throw new \Exception("Cannot access Get method with Post request", 406); } foreach ($roles as $role) { if ($role === $annotation) { // TODO if user in role -> pass him throw new \Exception("You are not " . strtolower($role) . " to do this", 401); } } } if ($this->input->hasPost()) { $bindingModel = $this->BindModel($annotations[1]); } $isMethodExists = true; } } if ($isMethodExists) { if ($bindingModel) { $newController->{$this->method}($bindingModel); } else { $newController->{$this->method}(); } } else { throw new \Exception("This action do not exists", 404); } }