push( Middleware::history($this->requestHistory) ); $guzzleOptions['handler'] = $handler; } $this->setClient( $guzzleOptions, $config ); } /** * @param array $guzzleOptions * @param array $config * * @return mixed */ abstract public function setClient(array $guzzleOptions, array $config = []); /** * Return the endpoint being used. * * @return Management|Authentication|JWKFetcher */ public function call() { $this->historyIndex ++; return $this->client; } /** * Get the URL from a mocked request. * * @param integer $parse_component Component for parse_url, null to return complete URL. * * @return string */ public function getHistoryUrl($parse_component = null) { $request = $this->getHistory(); $request_url = $request->getUri()->__toString(); return is_null( $parse_component ) ? $request_url : parse_url( $request_url, $parse_component ); } /** * Get the URL query from a mocked request. * * @return string */ public function getHistoryQuery() { return $this->getHistoryUrl( PHP_URL_QUERY ); } /** * Get the HTTP method from a mocked request. * * @return string */ public function getHistoryMethod() { return $this->getHistory()->getMethod(); } /** * Get the body from a mocked request. * * @return \stdClass|array */ public function getHistoryBody() { $body = $this->getHistory()->getBody(); return json_decode( $body, true ); } /** * Get the form body from a mocked request. * * @return string */ public function getHistoryBodyAsString() { return $this->getHistory()->getBody()->getContents(); } /** * Get the headers from a mocked request. * * @return array */ public function getHistoryHeaders() { return $this->getHistory()->getHeaders(); } /** * Get a Guzzle history record from an array populated by Middleware::history(). * * @return Request */ protected function getHistory() { $requestHistoryIndex = $this->historyIndex - 1; return $this->requestHistory[$requestHistoryIndex]['request']; } }