/** * @param $url * @param array $options * @param array $headers * @param bool $array * @param bool $permanent * @param bool $force * * @return mixed */ protected function getFromProxy($url, array $options = [], array $headers = [], $array = false, $permanent = false, $force = false) { $requestUrl = ConnectorTrait::bindUrlOptions($url, $options); $key = ['url' => $requestUrl]; $requestHeaders = $this->buildHeaders($requestUrl, $headers); $now = new \DateTime(); $storedCall = $this->proxy->find($key); if (null === $storedCall || $force) { $response = $this->getAbsolute($url, $options, $headers, false, false); if ($response) { $data = ['data' => $response, 'url' => $url, 'headers' => $this->getLastHeaders(), 'timestamp' => $now->getTimestamp(), 'ttl' => $permanent ? null : 86400, 'permanent' => $permanent, 'request_headers' => $requestHeaders]; $this->proxy->save($key, $data); } return json_decode(json_encode($response), $array); } if ($this->recordHasExpired($storedCall)) { $this->proxy->delete($key); return $this->getFromProxy($url, $options, $requestHeaders, $array, $permanent, $force); } $this->lastHeaders = json_decode(json_encode($storedCall->headers), true); return json_decode(json_encode($storedCall->data), $array); }