Exemplo n.º 1
0
 /**
  * If a @template annotation has been defined, this function will return the output
  * of Slim's parsing of a template, if the correct @render annotation has been specified
  *
  * @param Route        $autoroute
  * @param \Spore\Spore $app
  * @param              $data
  *
  * @return string
  */
 private function getTemplateOutput(Route $autoroute, Spore $app, $data)
 {
     $template = $autoroute->getTemplate();
     $renderMode = $autoroute->getRender();
     $output = "";
     switch ($renderMode) {
         case "always":
             $app->render($template, $data);
             $output = ob_get_clean();
             break;
         case "never":
             return Serializer::getSerializedData($app, $data);
             break;
         default:
             if (!$app->request()->isAjax()) {
                 $app->render($template, $data);
                 $output = ob_get_clean();
             } else {
                 return Serializer::getSerializedData($app, $data);
             }
             break;
     }
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Create the auto-route
  *
  * @param MethodElement   $method
  * @param string|object   $class
  * @param RouteDescriptor $descriptor
  *
  * @return Route
  */
 private function createRoute(MethodElement $method, $class, RouteDescriptor $descriptor)
 {
     $uri = $this->getRouteAnnotation($method);
     if (!$uri) {
         return null;
     }
     $name = $this->getNameAnnotation($method);
     $httpMethods = $this->getRouteMethods($method);
     $authorizedUsers = $this->getAuthorizedUsers($method);
     $template = $this->getTemplateAnnotation($method);
     $render = $this->getRenderAnnotation($method);
     $conditions = $this->getConditionAnnotations($method);
     // set the auto-route properties based on the provided annotations
     $route = new Route($descriptor);
     $route->setName($name);
     $route->setUri($uri);
     $route->setMethods($httpMethods);
     $route->setAuthorizedUsers($authorizedUsers);
     $route->setTemplate($template);
     $route->setRender($render);
     $route->setCallback(array($class, $method->name));
     $route->setConditions($conditions);
     return $route;
 }