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; }
/** * 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); }