Example #1
0
 public function getView(RequestIF $request)
 {
     if ($request->issetParameter('view')) {
         $viewVersion = $request->getParameter('version');
         $viewName = $request->getParameter('view');
         $view = $this->loadView($viewVersion, $viewName);
         if ($view instanceof ViewIF) {
             return $view;
         }
     }
     return null;
 }
Example #2
0
 /**
  * @param RequestIF $request The Request Handler
  * @param ResponseIF $response The Response Handler
  * @return null
  */
 public function execute(RequestIF $request, ResponseIF $response)
 {
     $this->request = $request;
     $this->response = $response;
     // Validate required request parameters
     if (!$this->request->issetParameter("api_key") || !$this->request->issetParameter("token")) {
         $this->response->setStatus(400);
         // Bad Request
         return null;
     }
     if (!$this->validateAuthorization()) {
         $this->response->setStatus(401);
         // Unauthorized
         return null;
     }
     if (!in_array($request->getMethod(), $this->allowedRequestMethods)) {
         $this->response->setStatus(405);
         // Method Not Allowed
         return null;
     }
     $this->response->addHeader("Allow", $this->getAllowedRequestMethodsString());
     $this->response->addHeader("Content-Type", "application/json");
     switch ($request->getMethod()) {
         case "GET":
             if ($this->read()) {
                 $this->response->setStatus(200);
             } else {
                 $response->setStatus(500);
             }
             // Internal Server Error
             break;
         case "POST":
             if ($this->create()) {
                 $this->response->setStatus(201);
             } else {
                 $response->setStatus(500);
             }
             // Internal Server Error
             break;
         case "PUT":
             if ($this->update()) {
                 $this->response->setStatus(200);
             } else {
                 $response->setStatus(500);
             }
             // Internal Server Error
             break;
         case "DELETE":
             if ($this->delete()) {
                 $this->response->setStatus(200);
             } else {
                 $response->setStatus(500);
             }
             // Internal Server Error
             break;
         default:
             $this->response->setStatus(501);
             // Not Implemented
             return null;
             break;
     }
 }