Exemplo n.º 1
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);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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);
 }