Example #1
0
 /**
  * Executes a request.
  *
  * @param request Request to execute.
  *
  * @return Response Response to send.
  */
 public function execute(Request $request)
 {
     try {
         $segments = $request->getPathSegments();
         if (count($segments) > 0) {
             $firstSegment = $segments[0];
             if (array_key_exists($firstSegment, $this->controllers)) {
                 $controller = $this->controllers[$firstSegment];
                 $controllerRequest = $request->consume();
                 $resource = $controller->getResource($controllerRequest);
                 if (isset($resource)) {
                     $verb = $request->getVerb();
                     if (method_exists($resource, $verb)) {
                         return $resource->{$verb}($controllerRequest);
                     } else {
                         return Response::notSupported();
                     }
                 }
             }
         }
         return Response::notFound();
     } catch (\Exception $e) {
         return Response::error($e->getMessage());
     }
 }
Example #2
0
 protected function unmatched(Request $req)
 {
     if (null !== ($path = $req->consume())) {
         /* Look for a child page */
         $postId = null;
         if (isset($req->data['ID'])) {
             $postId = $req->data['ID'];
         }
         if ($page = $this->model->postWithNameAndParent($path, $postId, 'page')) {
             return $this->routePost($req, $page, 'WordpressPage', 'page');
         }
         $postsPage = $this->model->optionWithName('page_for_posts');
         if (!empty($postsPage) && $postsPage == $postId || !empty($req->data['homepage']) && empty($postsPage)) {
             $params = $req->params;
             array_unshift($params, $path);
             /* XXX: We need to intelligently match the entire array */
             if ($page = $this->model->postWithNameAndParent($path, null, 'post')) {
                 return $this->routePost($req, $page, 'WordpressPost', null);
             }
         }
         $this->request = $req;
         return $this->error(Error::OBJECT_NOT_FOUND);
     }
     return parent::unmatched($req);
 }