/**
  * 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);
 }
Exemplo n.º 2
0
 public function getActionUrl(GraphRequest $request)
 {
     return substr($request->getUrl(), strlen((string) $this->domain) + 2);
 }
Exemplo n.º 3
0
 /**
  * Esegue il forwarding della richiesta per ottenere informazioni da altri
  * moduli
  *
  * @param GraphRequest $request
  * @return GraphResponse
  * @throws GraphException
  */
 public function forward(GraphRequest $request)
 {
     if (!str_starts_with($request->getUrl(), "http://")) {
         $this->pushRequest($request);
         $resp = $this->router->dispatch($request);
         $this->popRequest();
         return $resp;
     } else {
         if (!extension_loaded('curl')) {
             throw new GraphException('request forwarding exception: cUrl extension is not installed', 5000, 500);
         }
         $fp = fsockopen($request->getHost(), 80, $errno, $errstr, 30);
         if (!$fp) {
             throw new GraphException('request forwarding exception: ' . $errstr($errno), 5001, 500);
         } else {
             $msg = "GET /" . $request->getPathname() . " HTTP/1.0\r\nHost: " . $request->getHost() . "\r\n\r\n";
             fwrite($fp, $msg);
             $resString = '';
             while (!feof($fp)) {
                 $resString .= fgets($fp, 128);
             }
             fclose($fp);
             return $this->parseResponse($resString);
         }
     }
 }