Example #1
0
function G_requestUrl()
{
    $reqUri = $_SERVER["REQUEST_URI"];
    $base = Settings::getInstance()->getPar('baseUrl');
    if (str_starts_with($reqUri, $base)) {
        $reqUri = substr($reqUri, strlen($base));
    }
    $reqUri = '/' . url_trimAndClean($reqUri);
    return $reqUri;
}
 private function checkUrl($url)
 {
     $url = url_trimAndClean($url);
     preg_match_all('/:(\\w+)/', $this->pattern, $matches);
     $regex = str_replace('/', '\\/', $this->pattern);
     $regex = '/^' . preg_replace('/:(\\w+)/', '(\\w+)', $regex) . '(\\/|)$/';
     $parLabels = $matches[1];
     $parsKV = [];
     if (preg_match($regex, $url, $matches)) {
         for ($i = 0; $i < count($parLabels); $i++) {
             $parsKV[$parLabels[$i]] = $matches[$i + 1];
         }
         $this->matchedPars = $parsKV;
         return true;
     } else {
         return false;
     }
 }
 /**
  * Dirotta la richiesta al servizio che corrisponde al matching, ritornando
  * una risposta
  *
  * @param GraphRequest $request
  * @return GraphResponse
  */
 public function dispatch(GraphRequest $request)
 {
     $request->setContextPar('dispatchingId', uniqid());
     Graphene::getInstance()->startStat('DispatchingTime', $request->getMethod() . ' ' . $request->getUrl() . ' ' . $request->getContextPar('dispatchingId'));
     $response = null;
     $url = url_trimAndClean($request->getUrl());
     foreach ($this->modules as $dir => $module) {
         $domain = (string) $module->getDomain();
         if (str_starts_with($url, strtolower($domain))) {
             $this->pushModule($module);
             $response = $module->exec($request);
             $this->popModule();
             if ($response != null) {
                 break;
             }
         }
     }
     if ($response === null) {
     }
     return $this->getSafeResponse($response);
 }