Пример #1
0
 public function service(WebAppRequest $req, WebAppResponse $res)
 {
     switch ($req->getMethod()) {
         case 'GET':
             $this->doGet($req, $res);
             break;
         case 'POST':
             $this->doPost($req, $res);
             break;
         default:
             $res->sendError(WebAppResponse::SC_NOT_IMPLEMENTED);
             break;
     }
 }
 /**
  * Prefix the context path, our webapp emulator and append the request
  * parameters to the redirection string before calling sendRedirect.
  *
  * @param $request WebAppRequest
  * @param $redirectPath string
  * @return string
  * @access protected
  */
 protected function getURL(WebAppRequest $request, $redirectPath)
 {
     $result = '';
     $webAppPath = $request->getUrlPath();
     if (!is_null($webAppPath) && $webAppPath != '/') {
         $result = $request->generateControllerPath($webAppPath, true);
     }
     $result .= $redirectPath;
     $query = $request->getQueryString();
     if (!is_null($query)) {
         $result .= '?' . $query;
     }
     return $result;
 }
 /**
  * Prefix the context path, our webapp emulator and append the request
  * parameters to the redirection string before calling sendRedirect.
  *
  * @param $request WebAppRequest
  * @param $redirectPath string
  * @return string
  */
 protected function getURL(WebAppRequest $request, $redirectPath)
 {
     $result = '';
     $container = \Innomatic\Webapp\WebAppContainer::instance('\\Innomatic\\Webapp\\WebAppContainer');
     $processor = $container->getProcessor();
     $webAppPath = $request->getUrlPath();
     if (!is_null($webAppPath) && $webAppPath != '/') {
         $result = $request->generateControllerPath($webAppPath, true);
     }
     $result .= $redirectPath;
     $query = $request->getQueryString();
     if (!is_null($query)) {
         $result .= '?' . $query;
     }
     return $result;
 }
 /**
  * Maps the request to the right webapp handler
  */
 public function mapHandler(WebAppRequest $request)
 {
     $url_path = $request->getUrlPath();
     // NOTE: the requestURI comes from the pathInfo that follows our fusebox file (index.php)
     // initially the pathInfo is null since we don't know what constitutes the extra information
     // until we section off the webapp mapping, and then we can say that the rest is pathInfo
     $requestURI = $request->getRequestURI();
     $relativeURI = substr($requestURI, strlen($url_path));
     if ($relativeURI == '/' . WebAppRequest::RECEIVER) {
         $relativeURI = '/';
     }
     $fqclassname = null;
     $webAppPath = $relativeURI;
     $pathInfo = null;
     $handlerName = null;
     $match = 'none';
     // Rule 1: Exact Match
     if (is_null($fqclassname)) {
         if ($relativeURI != '/') {
             $handlerName = $this->webapp->getHandlerMapping($relativeURI);
         }
         if (!is_null($handlerName)) {
             $fqclassname = $this->webapp->getHandler($handlerName);
         }
         if (!is_null($fqclassname)) {
             $webAppPath = $relativeURI;
             $pathInfo = null;
             $match = 'exact';
         }
     }
     // Rule 2: Prefix Match
     if (is_null($fqclassname)) {
         $tmpPath = $relativeURI;
         while (true) {
             $handlerName = $this->webapp->getHandlerMapping($tmpPath . "/*");
             if (!is_null($handlerName)) {
                 $fqclassname = $this->webapp->getHandler($handlerName);
             }
             if (!is_null($fqclassname)) {
                 $pathInfo = substr($relativeURI, strlen($tmpPath));
                 if (strlen($pathInfo) == 0) {
                     $pathInfo = null;
                 }
                 $match = 'prefix';
                 break;
             }
             $slash = strrpos($tmpPath, '/');
             if ($slash === false) {
                 break;
             }
             $tmpPath = substr($tmpPath, 0, $slash);
         }
     }
     // Rule 3: Extension Match
     if (is_null($fqclassname)) {
         $slash = strrpos($relativeURI, '/');
         if ($slash !== false) {
             $last = substr($relativeURI, $slash);
             $period = strrpos($last, '.');
             if ($period !== false) {
                 $pattern = '*' . substr($last, $period);
                 $handlerName = $this->webapp->getHandlerMapping($pattern);
                 if (!is_null($handlerName)) {
                     $fqclassname = $this->webapp->getHandler($handlerName);
                 }
                 if (!is_null($fqclassname)) {
                     $webAppPath = $relativeURI;
                     $pathInfo = null;
                     $match = 'extension';
                 }
             }
         }
     }
     // Rule 4: Default Match
     if (is_null($fqclassname)) {
         $handlerName = $this->webapp->getHandlerMapping('/');
         if (!is_null($handlerName)) {
             $fqclassname = $this->webapp->getHandler($handlerName);
         }
         if (!is_null($fqclassname)) {
             $webAppPath = $relativeURI;
             //$pathInfo = $relativeURI;
             $pathInfo = null;
             $match = 'default';
         }
     }
     //echo 'Match: '.$match.' - Name: '.$handlerName.' - Web app path: '.$webAppPath.' - Path info: '.$pathInfo."<br>\n";
     $request->setWebAppPath($webAppPath);
     $request->setPathInfo($pathInfo);
     if ($fqclassname == null) {
         $this->response->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'No matching handler found for current request');
         return;
     }
     if (!@(include_once $fqclassname)) {
         $this->response->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'No handler found');
         return;
     }
     // Loads Webapp Handler class
     $classname = str_replace('/', '\\', substr($fqclassname, 0, -4));
     if (!class_exists($classname, true)) {
         $this->response->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'Malformed handler found');
         return;
     }
     // Instantiate Webapp Handler
     $handler = new $classname();
     $handler->setInitParameters($this->webapp->getHandlerParameters($handlerName));
     $handler->init();
     return $handler;
 }
 protected function getRelativePath(WebAppRequest $request)
 {
     $result = $request->getPathInfo();
     return \Innomatic\Io\Filesystem\DirectoryUtils::normalize(strlen($result) ? $result : '/');
 }