requestPrototype === null) { $this->requestPrototype = new Request($this); } return $this->requestPrototype; } /** * @param RequestInterface $prototype */ public function setRequestPrototype(RequestInterface $prototype) { $this->requestPrototype = $prototype; } /** * @return RequestInterface */ public function createRequest() { return $this->getRequestPrototype()->createClone(); } /** * @return ResponseInterface */ public function getResponsePrototype() { if ($this->responsePrototype === null) { $this->responsePrototype = new Response(); } return $this->responsePrototype; } /** * @param ResponseInterface $prototype */ public function setResponsePrototype(ResponseInterface $prototype) { $this->responsePrototype = $prototype; } /** * @return ResponseInterface */ public function createResponse() { return clone $this->getResponsePrototype(); } /** * @return Headers */ public function getDefaultRequestHeaders() { if ($this->defaultRequestHeaders === null) { $this->defaultRequestHeaders = new Headers(array( 'User-Agent' => 'fbbizsdk-php-v'.ApiConfig::SDKVersion, 'Accept-Encoding' => '*', )); } return $this->defaultRequestHeaders; } /** * @deprecated use getDefaultRequestHeaders() instead * * @return Headers */ public function getDefaultRequestHeaderds() { @trigger_error(sprintf('%s deprecated, use getDefaultRequestHeaders() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->getDefaultRequestHeaders(); } /** * @param Headers $headers */ public function setDefaultRequestHeaders(Headers $headers) { $this->defaultRequestHeaders = $headers; } /** * @return string */ public function getDefaultGraphBaseDomain() { return $this->defaultGraphBaseDomain; } /** * @param string $domain */ public function setDefaultGraphBaseDomain($domain) { $this->defaultGraphBaseDomain = $domain; } /** * @return AdapterInterface */ public function getAdapter() { if ($this->adapter === null) { $this->adapter = new CurlAdapter($this); } return $this->adapter; } /** * @param AdapterInterface $adapter */ public function setAdapter(AdapterInterface $adapter) { $this->adapter = $adapter; } /** * @return string */ public function getCaBundlePath() { if ($this->caBundlePath === null) { $this->caBundlePath = __DIR__.DIRECTORY_SEPARATOR .str_repeat('..'.DIRECTORY_SEPARATOR, 3) .'fb_ca_chain_bundle.crt'; } return $this->caBundlePath; } /** * @param string $path */ public function setCaBundlePath($path) { $this->caBundlePath = $path; } /** * @param RequestInterface $request * @return ResponseInterface * @throws RequestException */ public function sendRequest(RequestInterface $request) { $response = $this->getAdapter()->sendRequest($request); $response->setRequest($request); $response_content = $response->getContent(); if ($response_content === null) { throw new EmptyResponseException($response); } if (is_array($response_content) && array_key_exists('error', $response_content)) { throw RequestException::create($response); } return $response; } }