コード例 #1
0
 public function execFilters(GraphRequest $req, Module $module, Action $action)
 {
     if ($req->getHeader('system-token') !== null && $req->getHeader('system-token') === Graphene::getInstance()->getSystemToken()) {
         return true;
     }
     $executed = array();
     self::$ids++;
     $errs = array();
     do {
         $execs = 0;
         foreach ($this->filters as $filter) {
             if (array_search($filter->getName(), $executed) === false && $this->checkAfter($executed, $filter)) {
                 $execs++;
                 $executed[] = $filter->getName();
                 Log::debug('executing filter: ' . $filter->getName());
                 if (!$filter->exec($req, $module, $action)) {
                     $errs[] = array('ignored' => $filter->errorIgnored(), 'name' => $filter->getName(), 'status' => $filter->getStatus(), 'message' => $filter->getMessage());
                 }
             }
         }
     } while ($execs > 0);
     if (count($executed) !== count($this->filters)) {
         Log::err('Some filter was not executed');
         //TODO elenco filtri non eseguiti e dipendenze richieste
     }
     $this->filterErrors[self::$ids] = $errs;
     return !$this->haveErrors();
 }
コード例 #2
0
 public static function createByRequest(GraphRequest $request, Module $mod = null, $lazyChecks = false)
 {
     if ($mod == null) {
         $mod = Graphene::getInstance()->getCurrentModule();
     }
     if (($decoded = json_decode($request->getBody(), true)) === null) {
         throw new GraphException('Malformed request, check jsons structs on body', ExceptionsCodes::REQUEST_MALFORMED, 400);
     }
     $return = array();
     foreach ($decoded as $ModelName => $modelContent) {
         $domain = Graphene::getInstance()->getApplicationName() . '.' . $mod->getNamespace() . '.' . $ModelName;
         if (($return[$ModelName] = self::createModel($modelContent, $domain, $lazyChecks)) === false) {
             self::$BEAN_PARSING_ERRS[] = self::$LAST_BEAN->getLastTestErrors();
             throw new GraphException(self::$LAST_BEAN->getLastTestErrors(), ExceptionsCodes::REQUEST_MALFORMED, 400);
         }
     }
     return $return;
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 protected function forward($url, $data = null, $method = null, $checkErrors = true)
 {
     //Statistics
     $statId = uniqid();
     Graphene::getInstance()->startStat('RequestForwarding', $url . ' : ' . $statId);
     $req = new GraphRequest(true);
     $req->setUrl($url);
     //setting http method
     if ($data === null && $method === null) {
         $req->setMethod('GET');
     } else {
         if ($data !== null && $method === null) {
             $req->setMethod('POST');
         } else {
             if ($method !== null) {
                 $req->setMethod($method);
             }
         }
     }
     //setting request data
     if ($data === null) {
         $req->setData([]);
     } else {
         if (is_array($data)) {
             $req->setData($data);
         } else {
             if (is_string($data)) {
                 $req->setData(json_decode($data, true));
             } else {
                 if ($data instanceof Model) {
                     $req->setData($data->getData());
                 } else {
                     if ($data instanceof ModelCollection) {
                         $req->setData($data->getData());
                     }
                 }
             }
         }
     }
     //setting headers
     $headers = $this->request->getHeaders();
     foreach ($headers as $hk => $hv) {
         $req->setHeader($hk, $hv);
     }
     $req->setHeader('forwarded-by', $this->getUniqueActionName());
     $req->appendForward($this);
     $res = Graphene::getInstance()->forward($req);
     Graphene::getInstance()->stopStat('RequestForwarding', $url . ' : ' . $statId);
     if ($checkErrors && $res->getStatusCode() >= 400) {
         $data = $res->getData();
         throw new GraphException($res->getHeader('graphene-action') . ': ' . $data['error']['message'], $data['error']['code'], 400);
     }
     return $res;
 }
コード例 #5
0
 public function getActionUrl(GraphRequest $request)
 {
     return substr($request->getUrl(), strlen((string) $this->domain) + 2);
 }
コード例 #6
0
 /**
  * Crea un istanza di GraphRequest basandosi sulla richiesta ricevuta
  *
  * @return GraphRequest request
  */
 private function createRequest()
 {
     $req = new GraphRequest();
     $req->setUrl(G_requestUrl());
     $req->setIp($_SERVER['REMOTE_ADDR']);
     $req->setMethod($_SERVER['REQUEST_METHOD']);
     if (count($_POST) || count($_FILES) > 0) {
         $tree = $this->treeFromFlat(array_merge($_FILES, $_POST, $_GET));
         $req->setData($tree);
     } else {
         $jsonData = json_decode(file_get_contents("php://input"), true);
         if ($jsonData === null) {
             $jsonData = [];
         }
         $req->setData(array_merge($this->treeFromFlat($_GET), $jsonData));
     }
     $headers = apache_request_headers();
     foreach ($headers as $header => $value) {
         $req->setHeader($header, $value);
     }
     $this->pushRequest($req);
 }
コード例 #7
0
 /**
  * @param $url
  * @param null $body
  * @param null $method
  * @return GraphResponse
  */
 protected function forward($url, $body = null, $method = null)
 {
     $req = new GraphRequest(true);
     $req->setUrl($url);
     /* Creazione metodo */
     if ($body == null && $method == null) {
         $req->setMethod('GET');
     } else {
         if ($body != null && $method == null) {
             $req->setMethod('POST');
         } else {
             if ($method != null) {
                 $req->setMethod($method);
             }
         }
     }
     /* Creazione body */
     if ($body != null) {
         $req->setBody($body);
     } else {
         $req->setBody('');
     }
     $headers = $this->request->getHeaders();
     foreach ($headers as $hk => $hv) {
         $req->setHeader($hk, $hv);
     }
     $req->setUserAgent($this->request->getUserAgent());
     $req->setHeader('forwarded-by', $this->getName());
     //$req->appendForward($this);
     /* Forwarding */
     $fw = Graphene::getInstance();
     $req->setHeader('system-token', Graphene::getInstance()->getSystemToken());
     return $fw->forward($req);
 }