Ejemplo n.º 1
0
 /**
  * GET /link action
  *
  * @route {method: get, name: "home/link", path: "/link"}
  *
  * @return void
  */
 public function getLink()
 {
     echo Router::path("home/user", ["id" => "eser"]);
 }
Ejemplo n.º 2
0
 /**
  * Generates request
  *
  * @param string $uMethod          method
  * @param string $uPathInfo        pathinfo
  * @param array  $uQueryParameters query parameters
  *
  * @throws UnexpectedValueException if routing fails
  * @return RequestInterface request object
  */
 public function generateRequest($uMethod, $uPathInfo, array $uQueryParameters)
 {
     $tRoute = Router::dispatch($uMethod, $uPathInfo);
     $tModule = "front";
     foreach ($this->config["modules"] as $tModuleKey => $tModuleDefinition) {
         if (strncmp($uPathInfo, "/{$tModuleKey}/", strlen($tModuleKey) + 2) === 0) {
             $tModule = $tModuleKey;
             break;
         }
     }
     $tRoute += ["method" => $uMethod, "module" => $tModule, "pathinfo" => $uPathInfo, "queryParameters" => $uQueryParameters];
     $this->events->invoke("requestBegin", $tRoute);
     if ($tRoute["status"] === Router::FOUND) {
         // push some variables like named parameters
         $tInstance = new $tRoute["callback"][0]();
         $tInstance->routeInfo = $tRoute;
         $tInstance->application = $this;
         if (isset($this->config["modules"][$tModule]["config"])) {
             $tInstance->moduleConfig = $this->config["modules"][$tModule]["config"];
         } else {
             $tInstance->moduleConfig = null;
         }
         $tInstance->prerender->invoke();
         call_user_func([&$tInstance, $tRoute["callback"][1]], ...$tRoute["parameters"]);
         $tInstance->postrender->invoke();
         // pop previously pushed variables
     } elseif ($tRoute["status"] === Router::METHOD_NOT_ALLOWED) {
         // TODO exception
         throw new UnexpectedValueException("");
     } elseif ($tRoute["status"] === Router::NOT_FOUND) {
         // TODO exception
         throw new UnexpectedValueException("");
     }
     $this->events->invoke("requestEnd", $tRoute);
 }