/** * Loads a REST route * * @param $route SimpleXMLElement The route * @return bool */ private function _loadRest($route) { $path = (string) $route->path; $type = (string) $route->type; $module = (string) $route->module; $controller = (string) $route->controller; $action = (string) $route->action; $method = (string) $route->method; $description = (string) $route->description; $serviceName = (string) $route->serviceName; $authenticationRoles = array(); if (isset($route->authentication)) { foreach ($route->authentication->role as $auth) { $authenticationRoles[] = (string) $auth; } } $parameters = array(); if (isset($route->parameters)) { foreach ($route->parameters->parameter as $param) { $name = (string) $param["name"]; $ptype = (string) $param->type; $required = (string) $param->required; $parameters[] = array("name" => $name, "type" => $ptype, "required" => $required); } } // include the controller and check that the action exists includeController($controller); $dcontroller = "{$controller}Controller"; $controllerObj = new $dcontroller(); if (method_exists($controllerObj, $action)) { $this->connect($path, $type, array("module" => $module, "controller" => $controller, "action" => $action, "method" => $method, "description" => $description, "serviceName" => $serviceName, "authentication" => $authenticationRoles), $parameters); return true; } return false; }
/** * Tries to set an object creating an instance of * the object to be set * @access private * @param $object string The name of the object to be set * @return bool */ private function _setObject($object) { try { includeController($object); $controllerName = "{$object}Controller"; $controllerObj = new $controllerName(); $this->_object = $controllerObj; return true; } catch (Exception $ex) { trigger_error("REST | Error while setting the object: {$ex->getMessage()} ", E_USER_ERROR); return false; } }