Пример #1
0
 /**
  * @param WikiaApp $app
  * @param WikiaResponse $response
  * @param string $className Full class name (with Controller/Service suffix)
  * @param string $methodName Base method name from requeset
  * @return mixed $callStack if post-controller routing is involved, otherwise false
  */
 protected function applyRouting(WikiaApp $app, WikiaResponse $response, $className, $methodName)
 {
     // Starting with requested or default method name which is passed in by dispatch
     $response->setControllerName($className);
     $response->setMethodName($methodName);
     $callNext = array();
     // Check to see if we have a defined route for this controller to another controller
     if (isset($this->routes[$className]["*"])) {
         $route = $this->routes[$className]["*"];
     } else {
         if (isset($this->routes[$className][$methodName])) {
             $route = $this->routes[$className][$methodName];
         } else {
             return false;
         }
     }
     // skin routing, also allows possibility to override template
     if (isset($route['notSkin']) && !$app->checkSkin($route['notSkin']) || isset($route['skin']) && $app->checkSkin($route['skin'])) {
         if (isset($route['controller'])) {
             $response->setControllerName($route['controller']);
         }
         if (isset($route['method'])) {
             $response->setMethodName($route['method']);
         }
         if (isset($route['template'])) {
             $response->getView()->setTemplate($className, $route['template']);
         }
         if (isset($route['after'])) {
             $callNext = $route['after'];
         }
     }
     // global var routing should probably only be for controllers and methods
     if (isset($route['global']) && isset($app->wg->{$route}['global'])) {
         if (isset($route['controller'])) {
             $response->setControllerName($route['controller']);
         }
         if (isset($route['method'])) {
             $response->setMethodName($route['method']);
         }
         if (isset($route['after'])) {
             $callNext = $route['after'];
         }
     }
     return $callNext;
 }
Пример #2
0
 /**
  * factory method - create view object for given controller and method name
  *
  * @param string $controllerName
  * @param string $methodName
  * @param array $data
  * @param string $format
  *
  * @return WikiaView
  */
 public static function newFromControllerAndMethodName($controllerName, $methodName, array $data = [], $format = WikiaResponse::FORMAT_HTML)
 {
     // Service classes must be dispatched by full name otherwise we default to a controller.
     $controllerClassName = self::normalizeControllerClass($controllerName);
     $response = new WikiaResponse($format);
     $response->setControllerName($controllerName);
     $response->setMethodName($methodName);
     $response->setData($data);
     /* @var $controllerClassName WikiaController */
     $response->setTemplateEngine($controllerClassName::DEFAULT_TEMPLATE_ENGINE);
     return $response->getView();
 }