repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
egeloen/ivory-http-adapter | src/SocketHttpAdapter.php | SocketHttpAdapter.prepareRequest | private function prepareRequest(InternalRequestInterface $internalRequest)
{
$uri = $internalRequest->getUri();
$path = $uri->getPath().($uri->getQuery() ? '?'.$uri->getQuery() : '');
$request = $internalRequest->getMethod().' '.$path.' HTTP/'.$internalRequest->getProtocolVersion()."\r\n";
$request .= 'Host: '.$uri->getHost().($uri->getPort() !== null ? ':'.$uri->getPort() : '')."\r\n";
$request .= implode("\r\n", $this->prepareHeaders($internalRequest, false, true, true))."\r\n\r\n";
$request .= $this->prepareBody($internalRequest)."\r\n";
return $request;
} | php | private function prepareRequest(InternalRequestInterface $internalRequest)
{
$uri = $internalRequest->getUri();
$path = $uri->getPath().($uri->getQuery() ? '?'.$uri->getQuery() : '');
$request = $internalRequest->getMethod().' '.$path.' HTTP/'.$internalRequest->getProtocolVersion()."\r\n";
$request .= 'Host: '.$uri->getHost().($uri->getPort() !== null ? ':'.$uri->getPort() : '')."\r\n";
$request .= implode("\r\n", $this->prepareHeaders($internalRequest, false, true, true))."\r\n\r\n";
$request .= $this->prepareBody($internalRequest)."\r\n";
return $request;
} | [
"private",
"function",
"prepareRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"uri",
"=",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
";",
"$",
"path",
"=",
"$",
"uri",
"->",
"getPath",
"(",
")",
".",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
"?",
"'?'",
".",
"$",
"uri",
"->",
"getQuery",
"(",
")",
":",
"''",
")",
";",
"$",
"request",
"=",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
".",
"' '",
".",
"$",
"path",
".",
"' HTTP/'",
".",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
".",
"\"\\r\\n\"",
";",
"$",
"request",
".=",
"'Host: '",
".",
"$",
"uri",
"->",
"getHost",
"(",
")",
".",
"(",
"$",
"uri",
"->",
"getPort",
"(",
")",
"!==",
"null",
"?",
"':'",
".",
"$",
"uri",
"->",
"getPort",
"(",
")",
":",
"''",
")",
".",
"\"\\r\\n\"",
";",
"$",
"request",
".=",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
",",
"false",
",",
"true",
",",
"true",
")",
")",
".",
"\"\\r\\n\\r\\n\"",
";",
"$",
"request",
".=",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
".",
"\"\\r\\n\"",
";",
"return",
"$",
"request",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@return string | [
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/SocketHttpAdapter.php#L79-L90 |
egeloen/ivory-http-adapter | src/SocketHttpAdapter.php | SocketHttpAdapter.parseResponse | private function parseResponse($socket)
{
$headers = '';
$body = '';
$processHeaders = true;
while (!feof($socket) && !$this->detectTimeout($socket)) {
$line = fgets($socket);
if ($line === "\r\n") {
$processHeaders = false;
} elseif ($processHeaders) {
$headers .= $line;
} else {
$body .= $line;
}
}
return [$headers, $body];
} | php | private function parseResponse($socket)
{
$headers = '';
$body = '';
$processHeaders = true;
while (!feof($socket) && !$this->detectTimeout($socket)) {
$line = fgets($socket);
if ($line === "\r\n") {
$processHeaders = false;
} elseif ($processHeaders) {
$headers .= $line;
} else {
$body .= $line;
}
}
return [$headers, $body];
} | [
"private",
"function",
"parseResponse",
"(",
"$",
"socket",
")",
"{",
"$",
"headers",
"=",
"''",
";",
"$",
"body",
"=",
"''",
";",
"$",
"processHeaders",
"=",
"true",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"socket",
")",
"&&",
"!",
"$",
"this",
"->",
"detectTimeout",
"(",
"$",
"socket",
")",
")",
"{",
"$",
"line",
"=",
"fgets",
"(",
"$",
"socket",
")",
";",
"if",
"(",
"$",
"line",
"===",
"\"\\r\\n\"",
")",
"{",
"$",
"processHeaders",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"processHeaders",
")",
"{",
"$",
"headers",
".=",
"$",
"line",
";",
"}",
"else",
"{",
"$",
"body",
".=",
"$",
"line",
";",
"}",
"}",
"return",
"[",
"$",
"headers",
",",
"$",
"body",
"]",
";",
"}"
] | @param resource $socket
@return array | [
"@param",
"resource",
"$socket"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/SocketHttpAdapter.php#L97-L116 |
egeloen/ivory-http-adapter | src/SocketHttpAdapter.php | SocketHttpAdapter.decodeBody | private function decodeBody(array $headers, $body)
{
$headers = array_change_key_case($headers);
if (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') {
for ($decodedBody = ''; !empty($body); $body = trim($body)) {
$pos = strpos($body, "\r\n");
$length = hexdec(substr($body, 0, $pos));
$decodedBody .= substr($body, $pos + 2, $length);
$body = substr($body, $pos + $length + 2);
}
return $decodedBody;
}
return $body;
} | php | private function decodeBody(array $headers, $body)
{
$headers = array_change_key_case($headers);
if (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') {
for ($decodedBody = ''; !empty($body); $body = trim($body)) {
$pos = strpos($body, "\r\n");
$length = hexdec(substr($body, 0, $pos));
$decodedBody .= substr($body, $pos + 2, $length);
$body = substr($body, $pos + $length + 2);
}
return $decodedBody;
}
return $body;
} | [
"private",
"function",
"decodeBody",
"(",
"array",
"$",
"headers",
",",
"$",
"body",
")",
"{",
"$",
"headers",
"=",
"array_change_key_case",
"(",
"$",
"headers",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'transfer-encoding'",
"]",
")",
"&&",
"$",
"headers",
"[",
"'transfer-encoding'",
"]",
"===",
"'chunked'",
")",
"{",
"for",
"(",
"$",
"decodedBody",
"=",
"''",
";",
"!",
"empty",
"(",
"$",
"body",
")",
";",
"$",
"body",
"=",
"trim",
"(",
"$",
"body",
")",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"body",
",",
"\"\\r\\n\"",
")",
";",
"$",
"length",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"body",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"$",
"decodedBody",
".=",
"substr",
"(",
"$",
"body",
",",
"$",
"pos",
"+",
"2",
",",
"$",
"length",
")",
";",
"$",
"body",
"=",
"substr",
"(",
"$",
"body",
",",
"$",
"pos",
"+",
"$",
"length",
"+",
"2",
")",
";",
"}",
"return",
"$",
"decodedBody",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | @param array $headers
@param string $body
@return string | [
"@param",
"array",
"$headers",
"@param",
"string",
"$body"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/SocketHttpAdapter.php#L124-L140 |
egeloen/ivory-http-adapter | src/Guzzle3HttpAdapter.php | Guzzle3HttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$response = $this->createRequest($internalRequest)->send();
} catch (RequestException $e) {
throw HttpAdapterException::cannotFetchUri(
$e->getRequest()->getUrl(),
$this->getName(),
$e->getMessage()
);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($response) {
$resource = $response->getBody()->getStream();
$response->getBody()->detachStream();
return $resource;
},
$internalRequest->getMethod()
)
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$response = $this->createRequest($internalRequest)->send();
} catch (RequestException $e) {
throw HttpAdapterException::cannotFetchUri(
$e->getRequest()->getUrl(),
$this->getName(),
$e->getMessage()
);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($response) {
$resource = $response->getBody()->getStream();
$response->getBody()->detachStream();
return $resource;
},
$internalRequest->getMethod()
)
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"internalRequest",
")",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"e",
"->",
"getRequest",
"(",
")",
"->",
"getUrl",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"$",
"resource",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getStream",
"(",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"detachStream",
"(",
")",
";",
"return",
"$",
"resource",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle3HttpAdapter.php#L53-L79 |
egeloen/ivory-http-adapter | src/Guzzle3HttpAdapter.php | Guzzle3HttpAdapter.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $internalRequest) {
$requests[] = $this->createRequest($internalRequest, $success, $error);
}
try {
$this->client->send($requests);
} catch (\Exception $e) {
}
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $internalRequest) {
$requests[] = $this->createRequest($internalRequest, $success, $error);
}
try {
$this->client->send($requests);
} catch (\Exception $e) {
}
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"$",
"requests",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"internalRequests",
"as",
"$",
"internalRequest",
")",
"{",
"$",
"requests",
"[",
"]",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"internalRequest",
",",
"$",
"success",
",",
"$",
"error",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"requests",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle3HttpAdapter.php#L84-L95 |
egeloen/ivory-http-adapter | src/Guzzle3HttpAdapter.php | Guzzle3HttpAdapter.createRequest | private function createRequest(InternalRequestInterface $internalRequest, $success = null, $error = null)
{
$request = $this->client->createRequest(
$internalRequest->getMethod(),
(string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareContent($internalRequest),
[
'exceptions' => false,
'allow_redirects' => false,
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
]
);
$request->setProtocolVersion($internalRequest->getProtocolVersion());
if (is_callable($success)) {
$messageFactory = $this->getConfiguration()->getMessageFactory();
$request->getEventDispatcher()->addListener(
'request.success',
function (Event $event) use ($messageFactory, $success, $internalRequest) {
$response = $messageFactory->createResponse(
$event['response']->getStatusCode(),
$event['response']->getProtocolVersion(),
$event['response']->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($event) {
$resource = $event['response']->getBody()->getStream();
$event['response']->getBody()->detachStream();
return $resource;
},
$internalRequest->getMethod()
)
);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
}
);
}
if (is_callable($error)) {
$httpAdapterName = $this->getName();
$request->getEventDispatcher()->addListener(
'request.exception',
function (Event $event) use ($error, $internalRequest, $httpAdapterName) {
$exception = HttpAdapterException::cannotFetchUri(
$event['exception']->getRequest()->getUrl(),
$httpAdapterName,
$event['exception']->getMessage()
);
$exception->setRequest($internalRequest);
call_user_func($error, $exception);
}
);
}
return $request;
} | php | private function createRequest(InternalRequestInterface $internalRequest, $success = null, $error = null)
{
$request = $this->client->createRequest(
$internalRequest->getMethod(),
(string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareContent($internalRequest),
[
'exceptions' => false,
'allow_redirects' => false,
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
]
);
$request->setProtocolVersion($internalRequest->getProtocolVersion());
if (is_callable($success)) {
$messageFactory = $this->getConfiguration()->getMessageFactory();
$request->getEventDispatcher()->addListener(
'request.success',
function (Event $event) use ($messageFactory, $success, $internalRequest) {
$response = $messageFactory->createResponse(
$event['response']->getStatusCode(),
$event['response']->getProtocolVersion(),
$event['response']->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($event) {
$resource = $event['response']->getBody()->getStream();
$event['response']->getBody()->detachStream();
return $resource;
},
$internalRequest->getMethod()
)
);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
}
);
}
if (is_callable($error)) {
$httpAdapterName = $this->getName();
$request->getEventDispatcher()->addListener(
'request.exception',
function (Event $event) use ($error, $internalRequest, $httpAdapterName) {
$exception = HttpAdapterException::cannotFetchUri(
$event['exception']->getRequest()->getUrl(),
$httpAdapterName,
$event['exception']->getMessage()
);
$exception->setRequest($internalRequest);
call_user_func($error, $exception);
}
);
}
return $request;
} | [
"private",
"function",
"createRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
",",
"$",
"success",
"=",
"null",
",",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
",",
"$",
"this",
"->",
"prepareContent",
"(",
"$",
"internalRequest",
")",
",",
"[",
"'exceptions'",
"=>",
"false",
",",
"'allow_redirects'",
"=>",
"false",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'connect_timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"]",
")",
";",
"$",
"request",
"->",
"setProtocolVersion",
"(",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"success",
")",
")",
"{",
"$",
"messageFactory",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
";",
"$",
"request",
"->",
"getEventDispatcher",
"(",
")",
"->",
"addListener",
"(",
"'request.success'",
",",
"function",
"(",
"Event",
"$",
"event",
")",
"use",
"(",
"$",
"messageFactory",
",",
"$",
"success",
",",
"$",
"internalRequest",
")",
"{",
"$",
"response",
"=",
"$",
"messageFactory",
"->",
"createResponse",
"(",
"$",
"event",
"[",
"'response'",
"]",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"event",
"[",
"'response'",
"]",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"event",
"[",
"'response'",
"]",
"->",
"getHeaders",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"event",
")",
"{",
"$",
"resource",
"=",
"$",
"event",
"[",
"'response'",
"]",
"->",
"getBody",
"(",
")",
"->",
"getStream",
"(",
")",
";",
"$",
"event",
"[",
"'response'",
"]",
"->",
"getBody",
"(",
")",
"->",
"detachStream",
"(",
")",
";",
"return",
"$",
"resource",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withParameter",
"(",
"'request'",
",",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"error",
")",
")",
"{",
"$",
"httpAdapterName",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"request",
"->",
"getEventDispatcher",
"(",
")",
"->",
"addListener",
"(",
"'request.exception'",
",",
"function",
"(",
"Event",
"$",
"event",
")",
"use",
"(",
"$",
"error",
",",
"$",
"internalRequest",
",",
"$",
"httpAdapterName",
")",
"{",
"$",
"exception",
"=",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"event",
"[",
"'exception'",
"]",
"->",
"getRequest",
"(",
")",
"->",
"getUrl",
"(",
")",
",",
"$",
"httpAdapterName",
",",
"$",
"event",
"[",
"'exception'",
"]",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"exception",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"exception",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"request",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@param callable|null $success
@param callable|null $error
@return RequestInterface | [
"@param",
"InternalRequestInterface",
"$internalRequest",
"@param",
"callable|null",
"$success",
"@param",
"callable|null",
"$error"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle3HttpAdapter.php#L112-L175 |
egeloen/ivory-http-adapter | src/PeclHttpAdapter.php | PeclHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$body = new Body();
$body->append($this->prepareBody($internalRequest));
$request = new Request(
$internalRequest->getMethod(),
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$body
);
$httpVersion = $internalRequest->getProtocolVersion() === InternalRequestInterface::PROTOCOL_VERSION_1_0
? \http\Client\Curl\HTTP_VERSION_1_0
: \http\Client\Curl\HTTP_VERSION_1_1;
$request->setOptions([
'protocol' => $httpVersion,
'timeout' => $this->getConfiguration()->getTimeout(),
]);
try {
$this->client->reset()->enqueue($request)->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
$response = $this->client->getResponse();
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getResponseCode(),
$response->getHttpVersion(),
$response->getHeaders(),
$response->getBody()->getResource()
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$body = new Body();
$body->append($this->prepareBody($internalRequest));
$request = new Request(
$internalRequest->getMethod(),
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$body
);
$httpVersion = $internalRequest->getProtocolVersion() === InternalRequestInterface::PROTOCOL_VERSION_1_0
? \http\Client\Curl\HTTP_VERSION_1_0
: \http\Client\Curl\HTTP_VERSION_1_1;
$request->setOptions([
'protocol' => $httpVersion,
'timeout' => $this->getConfiguration()->getTimeout(),
]);
try {
$this->client->reset()->enqueue($request)->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
$response = $this->client->getResponse();
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getResponseCode(),
$response->getHttpVersion(),
$response->getHeaders(),
$response->getBody()->getResource()
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"body",
"=",
"new",
"Body",
"(",
")",
";",
"$",
"body",
"->",
"append",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
",",
"$",
"body",
")",
";",
"$",
"httpVersion",
"=",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
"===",
"InternalRequestInterface",
"::",
"PROTOCOL_VERSION_1_0",
"?",
"\\",
"http",
"\\",
"Client",
"\\",
"Curl",
"\\",
"HTTP_VERSION_1_0",
":",
"\\",
"http",
"\\",
"Client",
"\\",
"Curl",
"\\",
"HTTP_VERSION_1_1",
";",
"$",
"request",
"->",
"setOptions",
"(",
"[",
"'protocol'",
"=>",
"$",
"httpVersion",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"]",
")",
";",
"try",
"{",
"$",
"this",
"->",
"client",
"->",
"reset",
"(",
")",
"->",
"enqueue",
"(",
"$",
"request",
")",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"getResponse",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"getResponseCode",
"(",
")",
",",
"$",
"response",
"->",
"getHttpVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getResource",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/PeclHttpAdapter.php#L43-L78 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/SessionCookieJar.php | SessionCookieJar.load | public function load()
{
$this->unserialize(isset($_SESSION[$this->key]) ? $_SESSION[$this->key] : null);
} | php | public function load()
{
$this->unserialize(isset($_SESSION[$this->key]) ? $_SESSION[$this->key] : null);
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"this",
"->",
"unserialize",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"key",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"key",
"]",
":",
"null",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/SessionCookieJar.php#L56-L59 |
egeloen/ivory-http-adapter | src/CakeHttpAdapter.php | CakeHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$request = new Request();
foreach ($this->prepareHeaders($internalRequest) as $name => $value) {
$request->header($name, $value);
}
$request->method($internalRequest->getMethod());
$request->body($this->prepareBody($internalRequest));
$request->url($uri = (string) $internalRequest->getUri());
$request->version($this->getConfiguration()->getProtocolVersion());
try {
$response = $this->client->send($request, [
'timeout' => $this->getConfiguration()->getTimeout(),
'redirect' => false,
]);
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->statusCode(),
$response->version(),
$response->headers(),
$response->body()
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$request = new Request();
foreach ($this->prepareHeaders($internalRequest) as $name => $value) {
$request->header($name, $value);
}
$request->method($internalRequest->getMethod());
$request->body($this->prepareBody($internalRequest));
$request->url($uri = (string) $internalRequest->getUri());
$request->version($this->getConfiguration()->getProtocolVersion());
try {
$response = $this->client->send($request, [
'timeout' => $this->getConfiguration()->getTimeout(),
'redirect' => false,
]);
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->statusCode(),
$response->version(),
$response->headers(),
$response->body()
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"request",
"=",
"new",
"Request",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"request",
"->",
"header",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"$",
"request",
"->",
"method",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
";",
"$",
"request",
"->",
"body",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
";",
"$",
"request",
"->",
"url",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
";",
"$",
"request",
"->",
"version",
"(",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getProtocolVersion",
"(",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
",",
"[",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'redirect'",
"=>",
"false",
",",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"(",
"int",
")",
"$",
"response",
"->",
"statusCode",
"(",
")",
",",
"$",
"response",
"->",
"version",
"(",
")",
",",
"$",
"response",
"->",
"headers",
"(",
")",
",",
"$",
"response",
"->",
"body",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/CakeHttpAdapter.php#L50-L78 |
egeloen/ivory-http-adapter | src/Normalizer/BodyNormalizer.php | BodyNormalizer.normalize | public static function normalize($body, $method)
{
if ($method === RequestInterface::METHOD_HEAD || empty($body)) {
return;
}
if (is_callable($body)) {
return call_user_func($body);
}
return $body;
} | php | public static function normalize($body, $method)
{
if ($method === RequestInterface::METHOD_HEAD || empty($body)) {
return;
}
if (is_callable($body)) {
return call_user_func($body);
}
return $body;
} | [
"public",
"static",
"function",
"normalize",
"(",
"$",
"body",
",",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"method",
"===",
"RequestInterface",
"::",
"METHOD_HEAD",
"||",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"body",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"body",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | @param mixed $body
@param string $method
@return mixed | [
"@param",
"mixed",
"$body",
"@param",
"string",
"$method"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Normalizer/BodyNormalizer.php#L28-L39 |
egeloen/ivory-http-adapter | src/Event/Retry/Retry.php | Retry.retry | public function retry(InternalRequestInterface $internalRequest, $wait = true)
{
if (!$this->strategy->verify($internalRequest)) {
return false;
}
if ($wait && ($delay = $this->strategy->delay($internalRequest)) > 0) {
usleep($delay * 1000000);
}
return $internalRequest->withParameter(
self::RETRY_COUNT,
$internalRequest->getParameter(self::RETRY_COUNT) + 1
);
} | php | public function retry(InternalRequestInterface $internalRequest, $wait = true)
{
if (!$this->strategy->verify($internalRequest)) {
return false;
}
if ($wait && ($delay = $this->strategy->delay($internalRequest)) > 0) {
usleep($delay * 1000000);
}
return $internalRequest->withParameter(
self::RETRY_COUNT,
$internalRequest->getParameter(self::RETRY_COUNT) + 1
);
} | [
"public",
"function",
"retry",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
",",
"$",
"wait",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"strategy",
"->",
"verify",
"(",
"$",
"internalRequest",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"wait",
"&&",
"(",
"$",
"delay",
"=",
"$",
"this",
"->",
"strategy",
"->",
"delay",
"(",
"$",
"internalRequest",
")",
")",
">",
"0",
")",
"{",
"usleep",
"(",
"$",
"delay",
"*",
"1000000",
")",
";",
"}",
"return",
"$",
"internalRequest",
"->",
"withParameter",
"(",
"self",
"::",
"RETRY_COUNT",
",",
"$",
"internalRequest",
"->",
"getParameter",
"(",
"self",
"::",
"RETRY_COUNT",
")",
"+",
"1",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Retry/Retry.php#L56-L70 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/FileCookieJar.php | FileCookieJar.load | public function load()
{
if (($data = @file_get_contents($this->file)) === false) {
$error = error_get_last();
throw HttpAdapterException::cannotLoadCookieJar($error['message']);
}
$this->unserialize($data);
} | php | public function load()
{
if (($data = @file_get_contents($this->file)) === false) {
$error = error_get_last();
throw HttpAdapterException::cannotLoadCookieJar($error['message']);
}
$this->unserialize($data);
} | [
"public",
"function",
"load",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"data",
"=",
"@",
"file_get_contents",
"(",
"$",
"this",
"->",
"file",
")",
")",
"===",
"false",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"throw",
"HttpAdapterException",
"::",
"cannotLoadCookieJar",
"(",
"$",
"error",
"[",
"'message'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"unserialize",
"(",
"$",
"data",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/FileCookieJar.php#L57-L65 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/FileCookieJar.php | FileCookieJar.save | public function save()
{
if (@file_put_contents($this->file, $this->serialize()) === false) {
$error = error_get_last();
throw HttpAdapterException::cannotSaveCookieJar($error['message']);
}
} | php | public function save()
{
if (@file_put_contents($this->file, $this->serialize()) === false) {
$error = error_get_last();
throw HttpAdapterException::cannotSaveCookieJar($error['message']);
}
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"@",
"file_put_contents",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"serialize",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"throw",
"HttpAdapterException",
"::",
"cannotSaveCookieJar",
"(",
"$",
"error",
"[",
"'message'",
"]",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/FileCookieJar.php#L70-L76 |
egeloen/ivory-http-adapter | src/CurlHttpAdapter.php | CurlHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$curl = $this->createCurl($internalRequest);
try {
$response = $this->createResponse($curl, curl_exec($curl), $internalRequest);
} catch (HttpAdapterException $e) {
curl_close($curl);
throw $e;
}
curl_close($curl);
return $response;
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$curl = $this->createCurl($internalRequest);
try {
$response = $this->createResponse($curl, curl_exec($curl), $internalRequest);
} catch (HttpAdapterException $e) {
curl_close($curl);
throw $e;
}
curl_close($curl);
return $response;
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"curl",
"=",
"$",
"this",
"->",
"createCurl",
"(",
"$",
"internalRequest",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponse",
"(",
"$",
"curl",
",",
"curl_exec",
"(",
"$",
"curl",
")",
",",
"$",
"internalRequest",
")",
";",
"}",
"catch",
"(",
"HttpAdapterException",
"$",
"e",
")",
"{",
"curl_close",
"(",
"$",
"curl",
")",
";",
"throw",
"$",
"e",
";",
"}",
"curl_close",
"(",
"$",
"curl",
")",
";",
"return",
"$",
"response",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/CurlHttpAdapter.php#L46-L61 |
egeloen/ivory-http-adapter | src/CurlHttpAdapter.php | CurlHttpAdapter.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$curlMulti = curl_multi_init();
$contexts = [];
foreach ($internalRequests as $internalRequest) {
$contexts[] = [
'curl' => $curl = $this->createCurl($internalRequest),
'request' => $internalRequest,
];
curl_multi_add_handle($curlMulti, $curl);
}
do {
do {
$exec = curl_multi_exec($curlMulti, $running);
} while ($exec === CURLM_CALL_MULTI_PERFORM);
while ($done = curl_multi_info_read($curlMulti)) {
$curl = $done['handle'];
$internalRequest = $this->resolveInternalRequest($curl, $contexts);
try {
$response = $this->createResponse($curl, curl_multi_getcontent($curl), $internalRequest);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
call_user_func($error, $e);
}
curl_multi_remove_handle($curlMulti, $curl);
curl_close($curl);
}
} while ($running);
curl_multi_close($curlMulti);
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$curlMulti = curl_multi_init();
$contexts = [];
foreach ($internalRequests as $internalRequest) {
$contexts[] = [
'curl' => $curl = $this->createCurl($internalRequest),
'request' => $internalRequest,
];
curl_multi_add_handle($curlMulti, $curl);
}
do {
do {
$exec = curl_multi_exec($curlMulti, $running);
} while ($exec === CURLM_CALL_MULTI_PERFORM);
while ($done = curl_multi_info_read($curlMulti)) {
$curl = $done['handle'];
$internalRequest = $this->resolveInternalRequest($curl, $contexts);
try {
$response = $this->createResponse($curl, curl_multi_getcontent($curl), $internalRequest);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
call_user_func($error, $e);
}
curl_multi_remove_handle($curlMulti, $curl);
curl_close($curl);
}
} while ($running);
curl_multi_close($curlMulti);
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"$",
"curlMulti",
"=",
"curl_multi_init",
"(",
")",
";",
"$",
"contexts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"internalRequests",
"as",
"$",
"internalRequest",
")",
"{",
"$",
"contexts",
"[",
"]",
"=",
"[",
"'curl'",
"=>",
"$",
"curl",
"=",
"$",
"this",
"->",
"createCurl",
"(",
"$",
"internalRequest",
")",
",",
"'request'",
"=>",
"$",
"internalRequest",
",",
"]",
";",
"curl_multi_add_handle",
"(",
"$",
"curlMulti",
",",
"$",
"curl",
")",
";",
"}",
"do",
"{",
"do",
"{",
"$",
"exec",
"=",
"curl_multi_exec",
"(",
"$",
"curlMulti",
",",
"$",
"running",
")",
";",
"}",
"while",
"(",
"$",
"exec",
"===",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"while",
"(",
"$",
"done",
"=",
"curl_multi_info_read",
"(",
"$",
"curlMulti",
")",
")",
"{",
"$",
"curl",
"=",
"$",
"done",
"[",
"'handle'",
"]",
";",
"$",
"internalRequest",
"=",
"$",
"this",
"->",
"resolveInternalRequest",
"(",
"$",
"curl",
",",
"$",
"contexts",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponse",
"(",
"$",
"curl",
",",
"curl_multi_getcontent",
"(",
"$",
"curl",
")",
",",
"$",
"internalRequest",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withParameter",
"(",
"'request'",
",",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"HttpAdapterException",
"$",
"e",
")",
"{",
"$",
"e",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"e",
")",
";",
"}",
"curl_multi_remove_handle",
"(",
"$",
"curlMulti",
",",
"$",
"curl",
")",
";",
"curl_close",
"(",
"$",
"curl",
")",
";",
"}",
"}",
"while",
"(",
"$",
"running",
")",
";",
"curl_multi_close",
"(",
"$",
"curlMulti",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/CurlHttpAdapter.php#L66-L104 |
egeloen/ivory-http-adapter | src/CurlHttpAdapter.php | CurlHttpAdapter.createCurl | private function createCurl(InternalRequestInterface $internalRequest)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, (string) $internalRequest->getUri());
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HTTP_VERSION, $this->prepareProtocolVersion($internalRequest));
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->prepareHeaders($internalRequest, false, false));
$this->configureTimeout($curl, 'CURLOPT_TIMEOUT');
$this->configureTimeout($curl, 'CURLOPT_CONNECTTIMEOUT');
$files = $internalRequest->getFiles();
if (!empty($files) && $this->isSafeUpload()) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
}
switch ($internalRequest->getMethod()) {
case RequestInterface::METHOD_HEAD:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
curl_setopt($curl, CURLOPT_NOBODY, true);
break;
case RequestInterface::METHOD_TRACE:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
break;
case RequestInterface::METHOD_POST:
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->prepareContent($internalRequest));
break;
case RequestInterface::METHOD_PUT:
case RequestInterface::METHOD_PATCH:
case RequestInterface::METHOD_DELETE:
case RequestInterface::METHOD_OPTIONS:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->prepareContent($internalRequest));
break;
}
return $curl;
} | php | private function createCurl(InternalRequestInterface $internalRequest)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, (string) $internalRequest->getUri());
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HTTP_VERSION, $this->prepareProtocolVersion($internalRequest));
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->prepareHeaders($internalRequest, false, false));
$this->configureTimeout($curl, 'CURLOPT_TIMEOUT');
$this->configureTimeout($curl, 'CURLOPT_CONNECTTIMEOUT');
$files = $internalRequest->getFiles();
if (!empty($files) && $this->isSafeUpload()) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
}
switch ($internalRequest->getMethod()) {
case RequestInterface::METHOD_HEAD:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
curl_setopt($curl, CURLOPT_NOBODY, true);
break;
case RequestInterface::METHOD_TRACE:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
break;
case RequestInterface::METHOD_POST:
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->prepareContent($internalRequest));
break;
case RequestInterface::METHOD_PUT:
case RequestInterface::METHOD_PATCH:
case RequestInterface::METHOD_DELETE:
case RequestInterface::METHOD_OPTIONS:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $internalRequest->getMethod());
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->prepareContent($internalRequest));
break;
}
return $curl;
} | [
"private",
"function",
"createCurl",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_URL",
",",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_HTTP_VERSION",
",",
"$",
"this",
"->",
"prepareProtocolVersion",
"(",
"$",
"internalRequest",
")",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
",",
"false",
",",
"false",
")",
")",
";",
"$",
"this",
"->",
"configureTimeout",
"(",
"$",
"curl",
",",
"'CURLOPT_TIMEOUT'",
")",
";",
"$",
"this",
"->",
"configureTimeout",
"(",
"$",
"curl",
",",
"'CURLOPT_CONNECTTIMEOUT'",
")",
";",
"$",
"files",
"=",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"files",
")",
"&&",
"$",
"this",
"->",
"isSafeUpload",
"(",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_SAFE_UPLOAD",
",",
"true",
")",
";",
"}",
"switch",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"RequestInterface",
"::",
"METHOD_HEAD",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_NOBODY",
",",
"true",
")",
";",
"break",
";",
"case",
"RequestInterface",
"::",
"METHOD_TRACE",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
";",
"break",
";",
"case",
"RequestInterface",
"::",
"METHOD_POST",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"prepareContent",
"(",
"$",
"internalRequest",
")",
")",
";",
"break",
";",
"case",
"RequestInterface",
"::",
"METHOD_PUT",
":",
"case",
"RequestInterface",
"::",
"METHOD_PATCH",
":",
"case",
"RequestInterface",
"::",
"METHOD_DELETE",
":",
"case",
"RequestInterface",
"::",
"METHOD_OPTIONS",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"prepareContent",
"(",
"$",
"internalRequest",
")",
")",
";",
"break",
";",
"}",
"return",
"$",
"curl",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@return resource | [
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/CurlHttpAdapter.php#L111-L156 |
egeloen/ivory-http-adapter | src/CurlHttpAdapter.php | CurlHttpAdapter.createResponse | private function createResponse($curl, $data, InternalRequestInterface $internalRequest)
{
if (empty($data)) {
throw HttpAdapterException::cannotFetchUri(
(string) $internalRequest->getUri(),
$this->getName(),
curl_error($curl)
);
}
$headers = substr($data, 0, $headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE));
return $this->getConfiguration()->getMessageFactory()->createResponse(
StatusCodeExtractor::extract($headers),
ProtocolVersionExtractor::extract($headers),
HeadersNormalizer::normalize($headers),
BodyNormalizer::normalize(substr($data, $headersSize), $internalRequest->getMethod())
);
} | php | private function createResponse($curl, $data, InternalRequestInterface $internalRequest)
{
if (empty($data)) {
throw HttpAdapterException::cannotFetchUri(
(string) $internalRequest->getUri(),
$this->getName(),
curl_error($curl)
);
}
$headers = substr($data, 0, $headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE));
return $this->getConfiguration()->getMessageFactory()->createResponse(
StatusCodeExtractor::extract($headers),
ProtocolVersionExtractor::extract($headers),
HeadersNormalizer::normalize($headers),
BodyNormalizer::normalize(substr($data, $headersSize), $internalRequest->getMethod())
);
} | [
"private",
"function",
"createResponse",
"(",
"$",
"curl",
",",
"$",
"data",
",",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"curl_error",
"(",
"$",
"curl",
")",
")",
";",
"}",
"$",
"headers",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"headersSize",
"=",
"curl_getinfo",
"(",
"$",
"curl",
",",
"CURLINFO_HEADER_SIZE",
")",
")",
";",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"StatusCodeExtractor",
"::",
"extract",
"(",
"$",
"headers",
")",
",",
"ProtocolVersionExtractor",
"::",
"extract",
"(",
"$",
"headers",
")",
",",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"headers",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"headersSize",
")",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | @param resource $curl
@param string|bool|null $data
@param InternalRequestInterface $internalRequest
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"resource",
"$curl",
"@param",
"string|bool|null",
"$data",
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/CurlHttpAdapter.php#L180-L198 |
egeloen/ivory-http-adapter | src/Event/Cookie/CookieFactory.php | CookieFactory.create | public function create($name, $value, array $attributes, $createdAt)
{
return new Cookie($name, $value, $attributes, $createdAt);
} | php | public function create($name, $value, array $attributes, $createdAt)
{
return new Cookie($name, $value, $attributes, $createdAt);
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"array",
"$",
"attributes",
",",
"$",
"createdAt",
")",
"{",
"return",
"new",
"Cookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"$",
"createdAt",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/CookieFactory.php#L24-L27 |
egeloen/ivory-http-adapter | src/Event/Cookie/CookieFactory.php | CookieFactory.parse | public function parse($header)
{
list($name, $value, $attributes) = CookieParser::parse($header);
return $this->create($name, $value, $attributes, time());
} | php | public function parse($header)
{
list($name, $value, $attributes) = CookieParser::parse($header);
return $this->create($name, $value, $attributes, time());
} | [
"public",
"function",
"parse",
"(",
"$",
"header",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"attributes",
")",
"=",
"CookieParser",
"::",
"parse",
"(",
"$",
"header",
")",
";",
"return",
"$",
"this",
"->",
"create",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"time",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/CookieFactory.php#L32-L37 |
egeloen/ivory-http-adapter | src/Normalizer/HeadersNormalizer.php | HeadersNormalizer.normalize | public static function normalize($headers, $associative = true)
{
$normalizedHeaders = [];
if (!$associative) {
$headers = self::normalize($headers);
}
foreach (HeadersParser::parse($headers) as $name => $value) {
if (strpos($value, 'HTTP/') === 0) {
continue;
}
list($name, $value) = explode(':', $value, 2);
$name = self::normalizeHeaderName($name);
$value = self::normalizeHeaderValue($value);
if (!$associative) {
$normalizedHeaders[] = $name.': '.$value;
} else {
$normalizedHeaders[$name] = isset($normalizedHeaders[$name])
? $normalizedHeaders[$name].', '.$value
: $value;
}
}
return $normalizedHeaders;
} | php | public static function normalize($headers, $associative = true)
{
$normalizedHeaders = [];
if (!$associative) {
$headers = self::normalize($headers);
}
foreach (HeadersParser::parse($headers) as $name => $value) {
if (strpos($value, 'HTTP/') === 0) {
continue;
}
list($name, $value) = explode(':', $value, 2);
$name = self::normalizeHeaderName($name);
$value = self::normalizeHeaderValue($value);
if (!$associative) {
$normalizedHeaders[] = $name.': '.$value;
} else {
$normalizedHeaders[$name] = isset($normalizedHeaders[$name])
? $normalizedHeaders[$name].', '.$value
: $value;
}
}
return $normalizedHeaders;
} | [
"public",
"static",
"function",
"normalize",
"(",
"$",
"headers",
",",
"$",
"associative",
"=",
"true",
")",
"{",
"$",
"normalizedHeaders",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"associative",
")",
"{",
"$",
"headers",
"=",
"self",
"::",
"normalize",
"(",
"$",
"headers",
")",
";",
"}",
"foreach",
"(",
"HeadersParser",
"::",
"parse",
"(",
"$",
"headers",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'HTTP/'",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"value",
",",
"2",
")",
";",
"$",
"name",
"=",
"self",
"::",
"normalizeHeaderName",
"(",
"$",
"name",
")",
";",
"$",
"value",
"=",
"self",
"::",
"normalizeHeaderValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"associative",
")",
"{",
"$",
"normalizedHeaders",
"[",
"]",
"=",
"$",
"name",
".",
"': '",
".",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"normalizedHeaders",
"[",
"$",
"name",
"]",
"=",
"isset",
"(",
"$",
"normalizedHeaders",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"normalizedHeaders",
"[",
"$",
"name",
"]",
".",
"', '",
".",
"$",
"value",
":",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"normalizedHeaders",
";",
"}"
] | @param string|array $headers
@param bool $associative
@return array | [
"@param",
"string|array",
"$headers",
"@param",
"bool",
"$associative"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Normalizer/HeadersNormalizer.php#L28-L56 |
egeloen/ivory-http-adapter | src/Event/Subscriber/StopwatchSubscriber.php | StopwatchSubscriber.getStopwatchName | private function getStopwatchName(HttpAdapterInterface $httpAdapter, InternalRequestInterface $internalRequest)
{
return sprintf('ivory.http_adapter.%s (%s)', $httpAdapter->getName(), (string) $internalRequest->getUri());
} | php | private function getStopwatchName(HttpAdapterInterface $httpAdapter, InternalRequestInterface $internalRequest)
{
return sprintf('ivory.http_adapter.%s (%s)', $httpAdapter->getName(), (string) $internalRequest->getUri());
} | [
"private",
"function",
"getStopwatchName",
"(",
"HttpAdapterInterface",
"$",
"httpAdapter",
",",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"return",
"sprintf",
"(",
"'ivory.http_adapter.%s (%s)'",
",",
"$",
"httpAdapter",
"->",
"getName",
"(",
")",
",",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
";",
"}"
] | @param HttpAdapterInterface $httpAdapter
@param InternalRequestInterface $internalRequest
@return string | [
"@param",
"HttpAdapterInterface",
"$httpAdapter",
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Subscriber/StopwatchSubscriber.php#L139-L142 |
egeloen/ivory-http-adapter | src/FopenHttpAdapter.php | FopenHttpAdapter.process | protected function process($uri, $context)
{
$http_response_header = [];
$resource = @fopen($uri, 'rb', false, $context);
if (is_resource($resource)) {
$copy = @fopen('php://memory', 'rb+');
stream_copy_to_stream($resource, $copy);
fclose($resource);
} else {
$copy = $resource;
}
return [$copy, $http_response_header];
} | php | protected function process($uri, $context)
{
$http_response_header = [];
$resource = @fopen($uri, 'rb', false, $context);
if (is_resource($resource)) {
$copy = @fopen('php://memory', 'rb+');
stream_copy_to_stream($resource, $copy);
fclose($resource);
} else {
$copy = $resource;
}
return [$copy, $http_response_header];
} | [
"protected",
"function",
"process",
"(",
"$",
"uri",
",",
"$",
"context",
")",
"{",
"$",
"http_response_header",
"=",
"[",
"]",
";",
"$",
"resource",
"=",
"@",
"fopen",
"(",
"$",
"uri",
",",
"'rb'",
",",
"false",
",",
"$",
"context",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"copy",
"=",
"@",
"fopen",
"(",
"'php://memory'",
",",
"'rb+'",
")",
";",
"stream_copy_to_stream",
"(",
"$",
"resource",
",",
"$",
"copy",
")",
";",
"fclose",
"(",
"$",
"resource",
")",
";",
"}",
"else",
"{",
"$",
"copy",
"=",
"$",
"resource",
";",
"}",
"return",
"[",
"$",
"copy",
",",
"$",
"http_response_header",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/FopenHttpAdapter.php#L30-L44 |
egeloen/ivory-http-adapter | src/Guzzle6HttpAdapter.php | Guzzle6HttpAdapter.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $key => $internalRequest) {
$requests[$key] = $this->createRequest($internalRequest);
}
$httpAdapter = $this;
$pool = new Pool($this->client, $requests, array_merge($this->createOptions(), [
'fulfilled' => function ($response, $index) use ($success, $internalRequests, $httpAdapter) {
$response = $httpAdapter->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response->getBody()->detach();
},
$internalRequests[$index]->getMethod()
)
);
$response = $response->withParameter('request', $internalRequests[$index]);
call_user_func($success, $response);
},
'rejected' => function ($exception, $index) use ($error, $internalRequests, $httpAdapter) {
$exception = HttpAdapterException::cannotFetchUri(
$exception->getRequest()->getUri(),
$httpAdapter->getName(),
$exception->getMessage()
);
$exception->setRequest($internalRequests[$index]);
call_user_func($error, $exception);
},
]));
$pool->promise()->wait();
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $key => $internalRequest) {
$requests[$key] = $this->createRequest($internalRequest);
}
$httpAdapter = $this;
$pool = new Pool($this->client, $requests, array_merge($this->createOptions(), [
'fulfilled' => function ($response, $index) use ($success, $internalRequests, $httpAdapter) {
$response = $httpAdapter->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response->getBody()->detach();
},
$internalRequests[$index]->getMethod()
)
);
$response = $response->withParameter('request', $internalRequests[$index]);
call_user_func($success, $response);
},
'rejected' => function ($exception, $index) use ($error, $internalRequests, $httpAdapter) {
$exception = HttpAdapterException::cannotFetchUri(
$exception->getRequest()->getUri(),
$httpAdapter->getName(),
$exception->getMessage()
);
$exception->setRequest($internalRequests[$index]);
call_user_func($error, $exception);
},
]));
$pool->promise()->wait();
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"$",
"requests",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"internalRequests",
"as",
"$",
"key",
"=>",
"$",
"internalRequest",
")",
"{",
"$",
"requests",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"internalRequest",
")",
";",
"}",
"$",
"httpAdapter",
"=",
"$",
"this",
";",
"$",
"pool",
"=",
"new",
"Pool",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"requests",
",",
"array_merge",
"(",
"$",
"this",
"->",
"createOptions",
"(",
")",
",",
"[",
"'fulfilled'",
"=>",
"function",
"(",
"$",
"response",
",",
"$",
"index",
")",
"use",
"(",
"$",
"success",
",",
"$",
"internalRequests",
",",
"$",
"httpAdapter",
")",
"{",
"$",
"response",
"=",
"$",
"httpAdapter",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"(",
"int",
")",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"detach",
"(",
")",
";",
"}",
",",
"$",
"internalRequests",
"[",
"$",
"index",
"]",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withParameter",
"(",
"'request'",
",",
"$",
"internalRequests",
"[",
"$",
"index",
"]",
")",
";",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
",",
"'rejected'",
"=>",
"function",
"(",
"$",
"exception",
",",
"$",
"index",
")",
"use",
"(",
"$",
"error",
",",
"$",
"internalRequests",
",",
"$",
"httpAdapter",
")",
"{",
"$",
"exception",
"=",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"exception",
"->",
"getRequest",
"(",
")",
"->",
"getUri",
"(",
")",
",",
"$",
"httpAdapter",
"->",
"getName",
"(",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"exception",
"->",
"setRequest",
"(",
"$",
"internalRequests",
"[",
"$",
"index",
"]",
")",
";",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"exception",
")",
";",
"}",
",",
"]",
")",
")",
";",
"$",
"pool",
"->",
"promise",
"(",
")",
"->",
"wait",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle6HttpAdapter.php#L85-L124 |
egeloen/ivory-http-adapter | src/Guzzle6HttpAdapter.php | Guzzle6HttpAdapter.createRequest | private function createRequest(InternalRequestInterface $internalRequest)
{
return new Request(
$internalRequest->getMethod(),
$internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareBody($internalRequest),
$internalRequest->getProtocolVersion()
);
} | php | private function createRequest(InternalRequestInterface $internalRequest)
{
return new Request(
$internalRequest->getMethod(),
$internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareBody($internalRequest),
$internalRequest->getProtocolVersion()
);
} | [
"private",
"function",
"createRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"return",
"new",
"Request",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
",",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
",",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
")",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@return Request | [
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle6HttpAdapter.php#L131-L140 |
egeloen/ivory-http-adapter | src/Zend1HttpAdapter.php | Zend1HttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client
->resetParameters(true)
->setConfig([
'httpversion' => $internalRequest->getProtocolVersion(),
'timeout' => $this->getConfiguration()->getTimeout(),
'request_timeout' => $this->getConfiguration()->getTimeout(),
'maxredirects' => 0,
])
->setUri($uri = (string) $internalRequest->getUri())
->setMethod($internalRequest->getMethod())
->setHeaders($this->prepareHeaders($internalRequest))
->setRawData($this->prepareBody($internalRequest));
try {
$response = $this->client->request();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatus(),
$response->getVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response instanceof \Zend_Http_Response_Stream
? $response->getStream()
: $response->getBody();
},
$internalRequest->getMethod()
)
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client
->resetParameters(true)
->setConfig([
'httpversion' => $internalRequest->getProtocolVersion(),
'timeout' => $this->getConfiguration()->getTimeout(),
'request_timeout' => $this->getConfiguration()->getTimeout(),
'maxredirects' => 0,
])
->setUri($uri = (string) $internalRequest->getUri())
->setMethod($internalRequest->getMethod())
->setHeaders($this->prepareHeaders($internalRequest))
->setRawData($this->prepareBody($internalRequest));
try {
$response = $this->client->request();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatus(),
$response->getVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response instanceof \Zend_Http_Response_Stream
? $response->getStream()
: $response->getBody();
},
$internalRequest->getMethod()
)
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"resetParameters",
"(",
"true",
")",
"->",
"setConfig",
"(",
"[",
"'httpversion'",
"=>",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'request_timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'maxredirects'",
"=>",
"0",
",",
"]",
")",
"->",
"setUri",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
"->",
"setMethod",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
")",
"->",
"setRawData",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"getStatus",
"(",
")",
",",
"$",
"response",
"->",
"getVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"instanceof",
"\\",
"Zend_Http_Response_Stream",
"?",
"$",
"response",
"->",
"getStream",
"(",
")",
":",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Zend1HttpAdapter.php#L47-L81 |
egeloen/ivory-http-adapter | src/Event/Subscriber/CookieSubscriber.php | CookieSubscriber.getSubscribedEvents | public static function getSubscribedEvents()
{
return [
Events::REQUEST_CREATED => ['onRequestCreated', 300],
Events::REQUEST_SENT => ['onRequestSent', 300],
Events::REQUEST_ERRORED => ['onRequestErrored', 300],
Events::MULTI_REQUEST_CREATED => ['onMultiRequestCreated', 300],
Events::MULTI_REQUEST_SENT => ['onMultiRequestSent', 300],
Events::MULTI_REQUEST_ERRORED => ['onMultiResponseErrored', 300],
];
} | php | public static function getSubscribedEvents()
{
return [
Events::REQUEST_CREATED => ['onRequestCreated', 300],
Events::REQUEST_SENT => ['onRequestSent', 300],
Events::REQUEST_ERRORED => ['onRequestErrored', 300],
Events::MULTI_REQUEST_CREATED => ['onMultiRequestCreated', 300],
Events::MULTI_REQUEST_SENT => ['onMultiRequestSent', 300],
Events::MULTI_REQUEST_ERRORED => ['onMultiResponseErrored', 300],
];
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"return",
"[",
"Events",
"::",
"REQUEST_CREATED",
"=>",
"[",
"'onRequestCreated'",
",",
"300",
"]",
",",
"Events",
"::",
"REQUEST_SENT",
"=>",
"[",
"'onRequestSent'",
",",
"300",
"]",
",",
"Events",
"::",
"REQUEST_ERRORED",
"=>",
"[",
"'onRequestErrored'",
",",
"300",
"]",
",",
"Events",
"::",
"MULTI_REQUEST_CREATED",
"=>",
"[",
"'onMultiRequestCreated'",
",",
"300",
"]",
",",
"Events",
"::",
"MULTI_REQUEST_SENT",
"=>",
"[",
"'onMultiRequestSent'",
",",
"300",
"]",
",",
"Events",
"::",
"MULTI_REQUEST_ERRORED",
"=>",
"[",
"'onMultiResponseErrored'",
",",
"300",
"]",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Subscriber/CookieSubscriber.php#L113-L123 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/AbstractPersistentCookieJar.php | AbstractPersistentCookieJar.unserialize | public function unserialize($serialized)
{
$data = json_decode($serialized, true);
if (empty($data)) {
$this->clear();
} else {
$cookieFactory = $this->getCookieFactory();
$this->setCookies(array_map(function (array $cookie) use ($cookieFactory) {
return $cookieFactory->create(
$cookie['name'],
$cookie['value'],
$cookie['attributes'],
$cookie['created_at']
);
}, $data));
}
} | php | public function unserialize($serialized)
{
$data = json_decode($serialized, true);
if (empty($data)) {
$this->clear();
} else {
$cookieFactory = $this->getCookieFactory();
$this->setCookies(array_map(function (array $cookie) use ($cookieFactory) {
return $cookieFactory->create(
$cookie['name'],
$cookie['value'],
$cookie['attributes'],
$cookie['created_at']
);
}, $data));
}
} | [
"public",
"function",
"unserialize",
"(",
"$",
"serialized",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"serialized",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"$",
"cookieFactory",
"=",
"$",
"this",
"->",
"getCookieFactory",
"(",
")",
";",
"$",
"this",
"->",
"setCookies",
"(",
"array_map",
"(",
"function",
"(",
"array",
"$",
"cookie",
")",
"use",
"(",
"$",
"cookieFactory",
")",
"{",
"return",
"$",
"cookieFactory",
"->",
"create",
"(",
"$",
"cookie",
"[",
"'name'",
"]",
",",
"$",
"cookie",
"[",
"'value'",
"]",
",",
"$",
"cookie",
"[",
"'attributes'",
"]",
",",
"$",
"cookie",
"[",
"'created_at'",
"]",
")",
";",
"}",
",",
"$",
"data",
")",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/AbstractPersistentCookieJar.php#L56-L74 |
egeloen/ivory-http-adapter | src/StopwatchHttpAdapter.php | StopwatchHttpAdapter.doSendInternalRequest | protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->stopwatch->start($name = 'ivory.http_adapter');
try {
$result = parent::doSendInternalRequest($internalRequest);
} catch (\Exception $e) {
$this->stopwatch->stop($name);
throw $e;
}
$this->stopwatch->stop($name);
return $result;
} | php | protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->stopwatch->start($name = 'ivory.http_adapter');
try {
$result = parent::doSendInternalRequest($internalRequest);
} catch (\Exception $e) {
$this->stopwatch->stop($name);
throw $e;
}
$this->stopwatch->stop($name);
return $result;
} | [
"protected",
"function",
"doSendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"$",
"name",
"=",
"'ivory.http_adapter'",
")",
";",
"try",
"{",
"$",
"result",
"=",
"parent",
"::",
"doSendInternalRequest",
"(",
"$",
"internalRequest",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"name",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"name",
")",
";",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/StopwatchHttpAdapter.php#L41-L56 |
egeloen/ivory-http-adapter | src/StopwatchHttpAdapter.php | StopwatchHttpAdapter.doSendInternalRequests | protected function doSendInternalRequests(array $internalRequests)
{
$this->stopwatch->start($name = 'ivory.http_adapter');
try {
$result = parent::doSendInternalRequests($internalRequests);
} catch (\Exception $e) {
$this->stopwatch->stop($name);
throw $e;
}
$this->stopwatch->stop($name);
return $result;
} | php | protected function doSendInternalRequests(array $internalRequests)
{
$this->stopwatch->start($name = 'ivory.http_adapter');
try {
$result = parent::doSendInternalRequests($internalRequests);
} catch (\Exception $e) {
$this->stopwatch->stop($name);
throw $e;
}
$this->stopwatch->stop($name);
return $result;
} | [
"protected",
"function",
"doSendInternalRequests",
"(",
"array",
"$",
"internalRequests",
")",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"$",
"name",
"=",
"'ivory.http_adapter'",
")",
";",
"try",
"{",
"$",
"result",
"=",
"parent",
"::",
"doSendInternalRequests",
"(",
"$",
"internalRequests",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"name",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"name",
")",
";",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/StopwatchHttpAdapter.php#L61-L76 |
egeloen/ivory-http-adapter | src/ReactHttpAdapter.php | ReactHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$loop = EventLoopFactory::create();
$dnsResolverFactory = new DnsResolverFactory();
$httpClientFactory = new HttpClientFactory();
$error = null;
$response = null;
$body = null;
$request = $httpClientFactory->create($loop, $dnsResolverFactory->createCached('8.8.8.8', $loop))->request(
$internalRequest->getMethod(),
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest, true, true, true)
);
$request->on('error', function (\Exception $onError) use (&$error) {
$error = $onError;
});
$request->on('response', function (Response $onResponse) use (&$response, &$body) {
$onResponse->on('data', function ($data) use (&$body) {
$body .= $data;
});
$response = $onResponse;
});
$request->end($this->prepareBody($internalRequest));
$loop->run();
if ($error !== null) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $error->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getCode(),
$response->getVersion(),
$response->getHeaders(),
BodyNormalizer::normalize($body, $internalRequest->getMethod())
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$loop = EventLoopFactory::create();
$dnsResolverFactory = new DnsResolverFactory();
$httpClientFactory = new HttpClientFactory();
$error = null;
$response = null;
$body = null;
$request = $httpClientFactory->create($loop, $dnsResolverFactory->createCached('8.8.8.8', $loop))->request(
$internalRequest->getMethod(),
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest, true, true, true)
);
$request->on('error', function (\Exception $onError) use (&$error) {
$error = $onError;
});
$request->on('response', function (Response $onResponse) use (&$response, &$body) {
$onResponse->on('data', function ($data) use (&$body) {
$body .= $data;
});
$response = $onResponse;
});
$request->end($this->prepareBody($internalRequest));
$loop->run();
if ($error !== null) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $error->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getCode(),
$response->getVersion(),
$response->getHeaders(),
BodyNormalizer::normalize($body, $internalRequest->getMethod())
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"loop",
"=",
"EventLoopFactory",
"::",
"create",
"(",
")",
";",
"$",
"dnsResolverFactory",
"=",
"new",
"DnsResolverFactory",
"(",
")",
";",
"$",
"httpClientFactory",
"=",
"new",
"HttpClientFactory",
"(",
")",
";",
"$",
"error",
"=",
"null",
";",
"$",
"response",
"=",
"null",
";",
"$",
"body",
"=",
"null",
";",
"$",
"request",
"=",
"$",
"httpClientFactory",
"->",
"create",
"(",
"$",
"loop",
",",
"$",
"dnsResolverFactory",
"->",
"createCached",
"(",
"'8.8.8.8'",
",",
"$",
"loop",
")",
")",
"->",
"request",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
",",
"true",
",",
"true",
",",
"true",
")",
")",
";",
"$",
"request",
"->",
"on",
"(",
"'error'",
",",
"function",
"(",
"\\",
"Exception",
"$",
"onError",
")",
"use",
"(",
"&",
"$",
"error",
")",
"{",
"$",
"error",
"=",
"$",
"onError",
";",
"}",
")",
";",
"$",
"request",
"->",
"on",
"(",
"'response'",
",",
"function",
"(",
"Response",
"$",
"onResponse",
")",
"use",
"(",
"&",
"$",
"response",
",",
"&",
"$",
"body",
")",
"{",
"$",
"onResponse",
"->",
"on",
"(",
"'data'",
",",
"function",
"(",
"$",
"data",
")",
"use",
"(",
"&",
"$",
"body",
")",
"{",
"$",
"body",
".=",
"$",
"data",
";",
"}",
")",
";",
"$",
"response",
"=",
"$",
"onResponse",
";",
"}",
")",
";",
"$",
"request",
"->",
"end",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
";",
"$",
"loop",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"error",
"!==",
"null",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"error",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"(",
"int",
")",
"$",
"response",
"->",
"getCode",
"(",
")",
",",
"$",
"response",
"->",
"getVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"$",
"body",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/ReactHttpAdapter.php#L37-L78 |
egeloen/ivory-http-adapter | src/Message/MessageFactory.php | MessageFactory.createRequest | public function createRequest(
$uri,
$method = RequestInterface::METHOD_GET,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$body = null,
array $parameters = []
) {
return (new Request(
$this->createUri($uri),
$method,
$this->createStream($body),
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | php | public function createRequest(
$uri,
$method = RequestInterface::METHOD_GET,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$body = null,
array $parameters = []
) {
return (new Request(
$this->createUri($uri),
$method,
$this->createStream($body),
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | [
"public",
"function",
"createRequest",
"(",
"$",
"uri",
",",
"$",
"method",
"=",
"RequestInterface",
"::",
"METHOD_GET",
",",
"$",
"protocolVersion",
"=",
"RequestInterface",
"::",
"PROTOCOL_VERSION_1_1",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"(",
"new",
"Request",
"(",
"$",
"this",
"->",
"createUri",
"(",
"$",
"uri",
")",
",",
"$",
"method",
",",
"$",
"this",
"->",
"createStream",
"(",
"$",
"body",
")",
",",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"headers",
")",
",",
"$",
"parameters",
")",
")",
"->",
"withProtocolVersion",
"(",
"$",
"protocolVersion",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/MessageFactory.php#L68-L83 |
egeloen/ivory-http-adapter | src/Message/MessageFactory.php | MessageFactory.createInternalRequest | public function createInternalRequest(
$uri,
$method = RequestInterface::METHOD_GET,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$datas = [],
array $files = [],
array $parameters = []
) {
$body = null;
if (!is_array($datas)) {
$body = $this->createStream($datas);
$datas = $files = [];
}
return (new InternalRequest(
$this->createUri($uri),
$method,
$body !== null ? $body : 'php://memory',
$datas,
$files,
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | php | public function createInternalRequest(
$uri,
$method = RequestInterface::METHOD_GET,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$datas = [],
array $files = [],
array $parameters = []
) {
$body = null;
if (!is_array($datas)) {
$body = $this->createStream($datas);
$datas = $files = [];
}
return (new InternalRequest(
$this->createUri($uri),
$method,
$body !== null ? $body : 'php://memory',
$datas,
$files,
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | [
"public",
"function",
"createInternalRequest",
"(",
"$",
"uri",
",",
"$",
"method",
"=",
"RequestInterface",
"::",
"METHOD_GET",
",",
"$",
"protocolVersion",
"=",
"RequestInterface",
"::",
"PROTOCOL_VERSION_1_1",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"datas",
")",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"createStream",
"(",
"$",
"datas",
")",
";",
"$",
"datas",
"=",
"$",
"files",
"=",
"[",
"]",
";",
"}",
"return",
"(",
"new",
"InternalRequest",
"(",
"$",
"this",
"->",
"createUri",
"(",
"$",
"uri",
")",
",",
"$",
"method",
",",
"$",
"body",
"!==",
"null",
"?",
"$",
"body",
":",
"'php://memory'",
",",
"$",
"datas",
",",
"$",
"files",
",",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"headers",
")",
",",
"$",
"parameters",
")",
")",
"->",
"withProtocolVersion",
"(",
"$",
"protocolVersion",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/MessageFactory.php#L88-L113 |
egeloen/ivory-http-adapter | src/Message/MessageFactory.php | MessageFactory.createResponse | public function createResponse(
$statusCode = 200,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$body = null,
array $parameters = []
) {
return (new Response(
$this->createStream($body),
$statusCode,
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | php | public function createResponse(
$statusCode = 200,
$protocolVersion = RequestInterface::PROTOCOL_VERSION_1_1,
array $headers = [],
$body = null,
array $parameters = []
) {
return (new Response(
$this->createStream($body),
$statusCode,
HeadersNormalizer::normalize($headers),
$parameters
))->withProtocolVersion($protocolVersion);
} | [
"public",
"function",
"createResponse",
"(",
"$",
"statusCode",
"=",
"200",
",",
"$",
"protocolVersion",
"=",
"RequestInterface",
"::",
"PROTOCOL_VERSION_1_1",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"(",
"new",
"Response",
"(",
"$",
"this",
"->",
"createStream",
"(",
"$",
"body",
")",
",",
"$",
"statusCode",
",",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"headers",
")",
",",
"$",
"parameters",
")",
")",
"->",
"withProtocolVersion",
"(",
"$",
"protocolVersion",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/MessageFactory.php#L118-L131 |
egeloen/ivory-http-adapter | src/Message/MessageFactory.php | MessageFactory.createUri | private function createUri($uri)
{
if ($this->hasBaseUri() && (stripos($uri, $baseUri = (string) $this->getBaseUri()) === false)) {
return $baseUri.$uri;
}
return $uri;
} | php | private function createUri($uri)
{
if ($this->hasBaseUri() && (stripos($uri, $baseUri = (string) $this->getBaseUri()) === false)) {
return $baseUri.$uri;
}
return $uri;
} | [
"private",
"function",
"createUri",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasBaseUri",
"(",
")",
"&&",
"(",
"stripos",
"(",
"$",
"uri",
",",
"$",
"baseUri",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"getBaseUri",
"(",
")",
")",
"===",
"false",
")",
")",
"{",
"return",
"$",
"baseUri",
".",
"$",
"uri",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] | @param string $uri
@return string | [
"@param",
"string",
"$uri"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/MessageFactory.php#L138-L145 |
egeloen/ivory-http-adapter | src/PsrHttpAdapterDecorator.php | PsrHttpAdapterDecorator.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$exceptions = [];
try {
$responses = $this->doSendInternalRequests($internalRequests);
} catch (MultiHttpAdapterException $e) {
$responses = $e->getResponses();
$exceptions = $e->getExceptions();
}
foreach ($responses as $response) {
call_user_func($success, $response);
}
foreach ($exceptions as $exception) {
call_user_func($error, $exception);
}
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$exceptions = [];
try {
$responses = $this->doSendInternalRequests($internalRequests);
} catch (MultiHttpAdapterException $e) {
$responses = $e->getResponses();
$exceptions = $e->getExceptions();
}
foreach ($responses as $response) {
call_user_func($success, $response);
}
foreach ($exceptions as $exception) {
call_user_func($error, $exception);
}
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"$",
"exceptions",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"responses",
"=",
"$",
"this",
"->",
"doSendInternalRequests",
"(",
"$",
"internalRequests",
")",
";",
"}",
"catch",
"(",
"MultiHttpAdapterException",
"$",
"e",
")",
"{",
"$",
"responses",
"=",
"$",
"e",
"->",
"getResponses",
"(",
")",
";",
"$",
"exceptions",
"=",
"$",
"e",
"->",
"getExceptions",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"responses",
"as",
"$",
"response",
")",
"{",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
"foreach",
"(",
"$",
"exceptions",
"as",
"$",
"exception",
")",
"{",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"exception",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/PsrHttpAdapterDecorator.php#L71-L89 |
egeloen/ivory-http-adapter | src/Parser/HeadersParser.php | HeadersParser.parse | public static function parse($headers)
{
if (is_string($headers)) {
$headers = explode("\r\n\r\n", trim($headers));
return explode("\r\n", end($headers));
}
$parsedHeaders = [];
foreach ($headers as $name => $value) {
$value = HeadersNormalizer::normalizeHeaderValue($value);
if (is_int($name)) {
if (strpos($value, 'HTTP/') === 0) {
$parsedHeaders = [$value];
} else {
$parsedHeaders[] = $value;
}
} else {
$parsedHeaders[] = $name.': '.$value;
}
}
return $parsedHeaders;
} | php | public static function parse($headers)
{
if (is_string($headers)) {
$headers = explode("\r\n\r\n", trim($headers));
return explode("\r\n", end($headers));
}
$parsedHeaders = [];
foreach ($headers as $name => $value) {
$value = HeadersNormalizer::normalizeHeaderValue($value);
if (is_int($name)) {
if (strpos($value, 'HTTP/') === 0) {
$parsedHeaders = [$value];
} else {
$parsedHeaders[] = $value;
}
} else {
$parsedHeaders[] = $name.': '.$value;
}
}
return $parsedHeaders;
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"headers",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"headers",
")",
")",
"{",
"$",
"headers",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"trim",
"(",
"$",
"headers",
")",
")",
";",
"return",
"explode",
"(",
"\"\\r\\n\"",
",",
"end",
"(",
"$",
"headers",
")",
")",
";",
"}",
"$",
"parsedHeaders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"HeadersNormalizer",
"::",
"normalizeHeaderValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'HTTP/'",
")",
"===",
"0",
")",
"{",
"$",
"parsedHeaders",
"=",
"[",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"$",
"parsedHeaders",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"parsedHeaders",
"[",
"]",
"=",
"$",
"name",
".",
"': '",
".",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"parsedHeaders",
";",
"}"
] | @param array|string $headers
@return array | [
"@param",
"array|string",
"$headers"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Parser/HeadersParser.php#L27-L52 |
egeloen/ivory-http-adapter | src/RequestsHttpAdapter.php | RequestsHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$options = [
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
'protocol_version' => (float) $this->getConfiguration()->getProtocolVersion(),
'follow_redirects' => 0,
'data_format' => 'body',
];
if ($this->transport !== null) {
$options['transport'] = $this->transport;
}
try {
$response = \Requests::request(
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareBody($internalRequest),
$internalRequest->getMethod(),
$options
);
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->status_code,
sprintf('%.1f', $response->protocol_version),
$response->headers->getAll(),
$response->body
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$options = [
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
'protocol_version' => (float) $this->getConfiguration()->getProtocolVersion(),
'follow_redirects' => 0,
'data_format' => 'body',
];
if ($this->transport !== null) {
$options['transport'] = $this->transport;
}
try {
$response = \Requests::request(
$uri = (string) $internalRequest->getUri(),
$this->prepareHeaders($internalRequest),
$this->prepareBody($internalRequest),
$internalRequest->getMethod(),
$options
);
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->status_code,
sprintf('%.1f', $response->protocol_version),
$response->headers->getAll(),
$response->body
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"options",
"=",
"[",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'connect_timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'protocol_version'",
"=>",
"(",
"float",
")",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getProtocolVersion",
"(",
")",
",",
"'follow_redirects'",
"=>",
"0",
",",
"'data_format'",
"=>",
"'body'",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"transport",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'transport'",
"]",
"=",
"$",
"this",
"->",
"transport",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"\\",
"Requests",
"::",
"request",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
",",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"status_code",
",",
"sprintf",
"(",
"'%.1f'",
",",
"$",
"response",
"->",
"protocol_version",
")",
",",
"$",
"response",
"->",
"headers",
"->",
"getAll",
"(",
")",
",",
"$",
"response",
"->",
"body",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/RequestsHttpAdapter.php#L48-L80 |
egeloen/ivory-http-adapter | src/Parser/CookieParser.php | CookieParser.parse | public static function parse($header)
{
if (strpos($header, '=') === false) {
$header = '='.$header;
}
list($name, $header) = explode('=', $header, 2);
if (strpos($header, ';') === false) {
$value = $header;
$header = null;
} else {
list($value, $header) = explode(';', $header, 2);
}
$attributes = [];
foreach (array_map('trim', explode(';', $header)) as $pair) {
if (empty($pair)) {
continue;
}
if (strpos($pair, '=') === false) {
$attributeName = $pair;
$attributeValue = null;
} else {
list($attributeName, $attributeValue) = explode('=', $pair);
}
$attributes[trim($attributeName)] = $attributeValue ? trim($attributeValue) : true;
}
$name = trim($name);
$value = trim($value);
return [!empty($name) ? $name : null, !empty($value) ? $value : null, $attributes];
} | php | public static function parse($header)
{
if (strpos($header, '=') === false) {
$header = '='.$header;
}
list($name, $header) = explode('=', $header, 2);
if (strpos($header, ';') === false) {
$value = $header;
$header = null;
} else {
list($value, $header) = explode(';', $header, 2);
}
$attributes = [];
foreach (array_map('trim', explode(';', $header)) as $pair) {
if (empty($pair)) {
continue;
}
if (strpos($pair, '=') === false) {
$attributeName = $pair;
$attributeValue = null;
} else {
list($attributeName, $attributeValue) = explode('=', $pair);
}
$attributes[trim($attributeName)] = $attributeValue ? trim($attributeValue) : true;
}
$name = trim($name);
$value = trim($value);
return [!empty($name) ? $name : null, !empty($value) ? $value : null, $attributes];
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"header",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"header",
",",
"'='",
")",
"===",
"false",
")",
"{",
"$",
"header",
"=",
"'='",
".",
"$",
"header",
";",
"}",
"list",
"(",
"$",
"name",
",",
"$",
"header",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"header",
",",
"2",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"header",
",",
"';'",
")",
"===",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"header",
";",
"$",
"header",
"=",
"null",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"header",
")",
"=",
"explode",
"(",
"';'",
",",
"$",
"header",
",",
"2",
")",
";",
"}",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"';'",
",",
"$",
"header",
")",
")",
"as",
"$",
"pair",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"pair",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"pair",
",",
"'='",
")",
"===",
"false",
")",
"{",
"$",
"attributeName",
"=",
"$",
"pair",
";",
"$",
"attributeValue",
"=",
"null",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"attributeName",
",",
"$",
"attributeValue",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"pair",
")",
";",
"}",
"$",
"attributes",
"[",
"trim",
"(",
"$",
"attributeName",
")",
"]",
"=",
"$",
"attributeValue",
"?",
"trim",
"(",
"$",
"attributeValue",
")",
":",
"true",
";",
"}",
"$",
"name",
"=",
"trim",
"(",
"$",
"name",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"return",
"[",
"!",
"empty",
"(",
"$",
"name",
")",
"?",
"$",
"name",
":",
"null",
",",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"null",
",",
"$",
"attributes",
"]",
";",
"}"
] | @param string $header
@return array | [
"@param",
"string",
"$header"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Parser/CookieParser.php#L26-L61 |
egeloen/ivory-http-adapter | src/Event/History/Journal.php | Journal.record | public function record(InternalRequestInterface $request, ResponseInterface $response)
{
$this->addEntry($this->journalEntryFactory->create($request, $response));
} | php | public function record(InternalRequestInterface $request, ResponseInterface $response)
{
$this->addEntry($this->journalEntryFactory->create($request, $response));
} | [
"public",
"function",
"record",
"(",
"InternalRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"addEntry",
"(",
"$",
"this",
"->",
"journalEntryFactory",
"->",
"create",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/History/Journal.php#L64-L67 |
egeloen/ivory-http-adapter | src/Event/History/Journal.php | Journal.addEntry | public function addEntry(JournalEntryInterface $entry)
{
if (!$this->hasEntry($entry)) {
$this->entries[] = $entry;
$this->entries = array_slice($this->entries, $this->limit * -1);
}
} | php | public function addEntry(JournalEntryInterface $entry)
{
if (!$this->hasEntry($entry)) {
$this->entries[] = $entry;
$this->entries = array_slice($this->entries, $this->limit * -1);
}
} | [
"public",
"function",
"addEntry",
"(",
"JournalEntryInterface",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasEntry",
"(",
"$",
"entry",
")",
")",
"{",
"$",
"this",
"->",
"entries",
"[",
"]",
"=",
"$",
"entry",
";",
"$",
"this",
"->",
"entries",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"entries",
",",
"$",
"this",
"->",
"limit",
"*",
"-",
"1",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/History/Journal.php#L133-L139 |
egeloen/ivory-http-adapter | src/Event/History/Journal.php | Journal.removeEntry | public function removeEntry(JournalEntryInterface $entry)
{
if ($this->hasEntry($entry)) {
unset($this->entries[array_search($entry, $this->entries, true)]);
$this->entries = array_values($this->entries);
}
} | php | public function removeEntry(JournalEntryInterface $entry)
{
if ($this->hasEntry($entry)) {
unset($this->entries[array_search($entry, $this->entries, true)]);
$this->entries = array_values($this->entries);
}
} | [
"public",
"function",
"removeEntry",
"(",
"JournalEntryInterface",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasEntry",
"(",
"$",
"entry",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"entries",
"[",
"array_search",
"(",
"$",
"entry",
",",
"$",
"this",
"->",
"entries",
",",
"true",
")",
"]",
")",
";",
"$",
"this",
"->",
"entries",
"=",
"array_values",
"(",
"$",
"this",
"->",
"entries",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/History/Journal.php#L144-L150 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.clean | public function clean()
{
foreach ($this->cookies as $cookie) {
if ($cookie->isExpired()) {
$this->removeCookie($cookie);
}
}
} | php | public function clean()
{
foreach ($this->cookies as $cookie) {
if ($cookie->isExpired()) {
$this->removeCookie($cookie);
}
}
} | [
"public",
"function",
"clean",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"$",
"cookie",
"->",
"isExpired",
"(",
")",
")",
"{",
"$",
"this",
"->",
"removeCookie",
"(",
"$",
"cookie",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L62-L69 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.clear | public function clear($domain = null, $path = null, $name = null)
{
foreach ($this->cookies as $cookie) {
if ($domain !== null && !$cookie->matchDomain($domain)) {
continue;
}
if ($path !== null && !$cookie->matchPath($path)) {
continue;
}
if ($name !== null && $cookie->getName() !== $name) {
continue;
}
$this->removeCookie($cookie);
}
} | php | public function clear($domain = null, $path = null, $name = null)
{
foreach ($this->cookies as $cookie) {
if ($domain !== null && !$cookie->matchDomain($domain)) {
continue;
}
if ($path !== null && !$cookie->matchPath($path)) {
continue;
}
if ($name !== null && $cookie->getName() !== $name) {
continue;
}
$this->removeCookie($cookie);
}
} | [
"public",
"function",
"clear",
"(",
"$",
"domain",
"=",
"null",
",",
"$",
"path",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"$",
"domain",
"!==",
"null",
"&&",
"!",
"$",
"cookie",
"->",
"matchDomain",
"(",
"$",
"domain",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"path",
"!==",
"null",
"&&",
"!",
"$",
"cookie",
"->",
"matchPath",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"name",
"!==",
"null",
"&&",
"$",
"cookie",
"->",
"getName",
"(",
")",
"!==",
"$",
"name",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"removeCookie",
"(",
"$",
"cookie",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L74-L91 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.addCookie | public function addCookie(CookieInterface $cookie)
{
if (!$cookie->hasName() || $this->hasCookie($cookie)) {
return;
}
if (!$cookie->hasValue()) {
$this->clear(
$cookie->getAttribute(CookieInterface::ATTR_DOMAIN),
$cookie->getAttribute(CookieInterface::ATTR_PATH),
$cookie->getName()
);
return;
}
foreach ($this->cookies as $jarCookie) {
if (!$cookie->compare($jarCookie)) {
continue;
}
if ($cookie->getExpires() > $jarCookie->getExpires()) {
$this->removeCookie($jarCookie);
continue;
}
if ($cookie->getValue() !== $jarCookie->getValue()) {
$this->removeCookie($jarCookie);
continue;
}
return;
}
$this->cookies[] = $cookie;
} | php | public function addCookie(CookieInterface $cookie)
{
if (!$cookie->hasName() || $this->hasCookie($cookie)) {
return;
}
if (!$cookie->hasValue()) {
$this->clear(
$cookie->getAttribute(CookieInterface::ATTR_DOMAIN),
$cookie->getAttribute(CookieInterface::ATTR_PATH),
$cookie->getName()
);
return;
}
foreach ($this->cookies as $jarCookie) {
if (!$cookie->compare($jarCookie)) {
continue;
}
if ($cookie->getExpires() > $jarCookie->getExpires()) {
$this->removeCookie($jarCookie);
continue;
}
if ($cookie->getValue() !== $jarCookie->getValue()) {
$this->removeCookie($jarCookie);
continue;
}
return;
}
$this->cookies[] = $cookie;
} | [
"public",
"function",
"addCookie",
"(",
"CookieInterface",
"$",
"cookie",
")",
"{",
"if",
"(",
"!",
"$",
"cookie",
"->",
"hasName",
"(",
")",
"||",
"$",
"this",
"->",
"hasCookie",
"(",
"$",
"cookie",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"cookie",
"->",
"hasValue",
"(",
")",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
"$",
"cookie",
"->",
"getAttribute",
"(",
"CookieInterface",
"::",
"ATTR_DOMAIN",
")",
",",
"$",
"cookie",
"->",
"getAttribute",
"(",
"CookieInterface",
"::",
"ATTR_PATH",
")",
",",
"$",
"cookie",
"->",
"getName",
"(",
")",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"jarCookie",
")",
"{",
"if",
"(",
"!",
"$",
"cookie",
"->",
"compare",
"(",
"$",
"jarCookie",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"cookie",
"->",
"getExpires",
"(",
")",
">",
"$",
"jarCookie",
"->",
"getExpires",
"(",
")",
")",
"{",
"$",
"this",
"->",
"removeCookie",
"(",
"$",
"jarCookie",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"cookie",
"->",
"getValue",
"(",
")",
"!==",
"$",
"jarCookie",
"->",
"getValue",
"(",
")",
")",
"{",
"$",
"this",
"->",
"removeCookie",
"(",
"$",
"jarCookie",
")",
";",
"continue",
";",
"}",
"return",
";",
"}",
"$",
"this",
"->",
"cookies",
"[",
"]",
"=",
"$",
"cookie",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L149-L184 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.removeCookie | public function removeCookie(CookieInterface $cookie)
{
unset($this->cookies[array_search($cookie, $this->cookies, true)]);
$this->cookies = array_values($this->cookies);
} | php | public function removeCookie(CookieInterface $cookie)
{
unset($this->cookies[array_search($cookie, $this->cookies, true)]);
$this->cookies = array_values($this->cookies);
} | [
"public",
"function",
"removeCookie",
"(",
"CookieInterface",
"$",
"cookie",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"cookies",
"[",
"array_search",
"(",
"$",
"cookie",
",",
"$",
"this",
"->",
"cookies",
",",
"true",
")",
"]",
")",
";",
"$",
"this",
"->",
"cookies",
"=",
"array_values",
"(",
"$",
"this",
"->",
"cookies",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L189-L193 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.populate | public function populate(InternalRequestInterface $request)
{
foreach ($this->cookies as $cookie) {
if (!$cookie->isExpired() && $cookie->match($request)) {
$request = $request->withAddedHeader('Cookie', (string) $cookie);
}
}
return $request;
} | php | public function populate(InternalRequestInterface $request)
{
foreach ($this->cookies as $cookie) {
if (!$cookie->isExpired() && $cookie->match($request)) {
$request = $request->withAddedHeader('Cookie', (string) $cookie);
}
}
return $request;
} | [
"public",
"function",
"populate",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"!",
"$",
"cookie",
"->",
"isExpired",
"(",
")",
"&&",
"$",
"cookie",
"->",
"match",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withAddedHeader",
"(",
"'Cookie'",
",",
"(",
"string",
")",
"$",
"cookie",
")",
";",
"}",
"}",
"return",
"$",
"request",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L198-L207 |
egeloen/ivory-http-adapter | src/Event/Cookie/Jar/CookieJar.php | CookieJar.extract | public function extract(InternalRequestInterface $request, ResponseInterface $response)
{
foreach ($response->getHeader('Set-Cookie') as $header) {
$cookie = $this->cookieFactory->parse($header);
if (!$cookie->hasAttribute(CookieInterface::ATTR_DOMAIN)) {
$cookie->setAttribute(CookieInterface::ATTR_DOMAIN, $request->getUri()->getHost());
}
$this->addCookie($cookie);
}
} | php | public function extract(InternalRequestInterface $request, ResponseInterface $response)
{
foreach ($response->getHeader('Set-Cookie') as $header) {
$cookie = $this->cookieFactory->parse($header);
if (!$cookie->hasAttribute(CookieInterface::ATTR_DOMAIN)) {
$cookie->setAttribute(CookieInterface::ATTR_DOMAIN, $request->getUri()->getHost());
}
$this->addCookie($cookie);
}
} | [
"public",
"function",
"extract",
"(",
"InternalRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"foreach",
"(",
"$",
"response",
"->",
"getHeader",
"(",
"'Set-Cookie'",
")",
"as",
"$",
"header",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"cookieFactory",
"->",
"parse",
"(",
"$",
"header",
")",
";",
"if",
"(",
"!",
"$",
"cookie",
"->",
"hasAttribute",
"(",
"CookieInterface",
"::",
"ATTR_DOMAIN",
")",
")",
"{",
"$",
"cookie",
"->",
"setAttribute",
"(",
"CookieInterface",
"::",
"ATTR_DOMAIN",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getHost",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"addCookie",
"(",
"$",
"cookie",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Jar/CookieJar.php#L212-L223 |
egeloen/ivory-http-adapter | src/AbstractStreamHttpAdapter.php | AbstractStreamHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$context = stream_context_create([
'http' => [
'follow_location' => false,
'max_redirects' => 1,
'ignore_errors' => true,
'timeout' => $this->getConfiguration()->getTimeout(),
'protocol_version' => $internalRequest->getProtocolVersion(),
'method' => $internalRequest->getMethod(),
'header' => $this->prepareHeaders($internalRequest, false),
'content' => $this->prepareBody($internalRequest),
],
]);
list($body, $headers) = $this->process($uri = (string) $internalRequest->getUri(), $context);
if ($body === false) {
$error = error_get_last();
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $error['message']);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
StatusCodeExtractor::extract($headers),
ProtocolVersionExtractor::extract($headers),
HeadersNormalizer::normalize($headers),
BodyNormalizer::normalize($body, $internalRequest->getMethod())
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$context = stream_context_create([
'http' => [
'follow_location' => false,
'max_redirects' => 1,
'ignore_errors' => true,
'timeout' => $this->getConfiguration()->getTimeout(),
'protocol_version' => $internalRequest->getProtocolVersion(),
'method' => $internalRequest->getMethod(),
'header' => $this->prepareHeaders($internalRequest, false),
'content' => $this->prepareBody($internalRequest),
],
]);
list($body, $headers) = $this->process($uri = (string) $internalRequest->getUri(), $context);
if ($body === false) {
$error = error_get_last();
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $error['message']);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
StatusCodeExtractor::extract($headers),
ProtocolVersionExtractor::extract($headers),
HeadersNormalizer::normalize($headers),
BodyNormalizer::normalize($body, $internalRequest->getMethod())
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"context",
"=",
"stream_context_create",
"(",
"[",
"'http'",
"=>",
"[",
"'follow_location'",
"=>",
"false",
",",
"'max_redirects'",
"=>",
"1",
",",
"'ignore_errors'",
"=>",
"true",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'protocol_version'",
"=>",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
",",
"'method'",
"=>",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"'header'",
"=>",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
",",
"false",
")",
",",
"'content'",
"=>",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
",",
"]",
",",
"]",
")",
";",
"list",
"(",
"$",
"body",
",",
"$",
"headers",
")",
"=",
"$",
"this",
"->",
"process",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"body",
"===",
"false",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"error",
"[",
"'message'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"StatusCodeExtractor",
"::",
"extract",
"(",
"$",
"headers",
")",
",",
"ProtocolVersionExtractor",
"::",
"extract",
"(",
"$",
"headers",
")",
",",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"headers",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"$",
"body",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractStreamHttpAdapter.php#L28-L56 |
egeloen/ivory-http-adapter | src/HttpfulHttpAdapter.php | HttpfulHttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$request = Request::init($internalRequest->getMethod())
->whenError(function () {
})
->addOnCurlOption(CURLOPT_HTTP_VERSION, $this->prepareProtocolVersion($internalRequest))
->timeout($this->getConfiguration()->getTimeout())
->uri($uri = (string) $internalRequest->getUri())
->addHeaders($this->prepareHeaders($internalRequest))
->body($this->prepareContent($internalRequest));
if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
$request->addOnCurlOption(CURLOPT_CONNECTTIMEOUT_MS, $this->getConfiguration()->getTimeout() * 1000);
} else { // @codeCoverageIgnoreStart
$request->addOnCurlOption(CURLOPT_CONNECTTIMEOUT, $this->getConfiguration()->getTimeout());
} // @codeCoverageIgnoreEnd
$files = $internalRequest->getFiles();
if (!empty($files)) {
$request->mime(Mime::UPLOAD);
}
try {
$response = $request->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->code,
ProtocolVersionExtractor::extract($response->raw_headers),
$response->headers->toArray(),
BodyNormalizer::normalize($response->body, $internalRequest->getMethod())
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$request = Request::init($internalRequest->getMethod())
->whenError(function () {
})
->addOnCurlOption(CURLOPT_HTTP_VERSION, $this->prepareProtocolVersion($internalRequest))
->timeout($this->getConfiguration()->getTimeout())
->uri($uri = (string) $internalRequest->getUri())
->addHeaders($this->prepareHeaders($internalRequest))
->body($this->prepareContent($internalRequest));
if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
$request->addOnCurlOption(CURLOPT_CONNECTTIMEOUT_MS, $this->getConfiguration()->getTimeout() * 1000);
} else { // @codeCoverageIgnoreStart
$request->addOnCurlOption(CURLOPT_CONNECTTIMEOUT, $this->getConfiguration()->getTimeout());
} // @codeCoverageIgnoreEnd
$files = $internalRequest->getFiles();
if (!empty($files)) {
$request->mime(Mime::UPLOAD);
}
try {
$response = $request->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->code,
ProtocolVersionExtractor::extract($response->raw_headers),
$response->headers->toArray(),
BodyNormalizer::normalize($response->body, $internalRequest->getMethod())
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"init",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
"->",
"whenError",
"(",
"function",
"(",
")",
"{",
"}",
")",
"->",
"addOnCurlOption",
"(",
"CURLOPT_HTTP_VERSION",
",",
"$",
"this",
"->",
"prepareProtocolVersion",
"(",
"$",
"internalRequest",
")",
")",
"->",
"timeout",
"(",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
")",
"->",
"uri",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
"->",
"addHeaders",
"(",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
")",
"->",
"body",
"(",
"$",
"this",
"->",
"prepareContent",
"(",
"$",
"internalRequest",
")",
")",
";",
"if",
"(",
"defined",
"(",
"'CURLOPT_CONNECTTIMEOUT_MS'",
")",
")",
"{",
"$",
"request",
"->",
"addOnCurlOption",
"(",
"CURLOPT_CONNECTTIMEOUT_MS",
",",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
"*",
"1000",
")",
";",
"}",
"else",
"{",
"// @codeCoverageIgnoreStart",
"$",
"request",
"->",
"addOnCurlOption",
"(",
"CURLOPT_CONNECTTIMEOUT",
",",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
")",
";",
"}",
"// @codeCoverageIgnoreEnd",
"$",
"files",
"=",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"$",
"request",
"->",
"mime",
"(",
"Mime",
"::",
"UPLOAD",
")",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"request",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"code",
",",
"ProtocolVersionExtractor",
"::",
"extract",
"(",
"$",
"response",
"->",
"raw_headers",
")",
",",
"$",
"response",
"->",
"headers",
"->",
"toArray",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"$",
"response",
"->",
"body",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpfulHttpAdapter.php#L44-L79 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.addAttributes | public function addAttributes(array $attributes)
{
foreach ($attributes as $name => $value) {
$this->setAttribute($name, $value);
}
} | php | public function addAttributes(array $attributes)
{
foreach ($attributes as $name => $value) {
$this->setAttribute($name, $value);
}
} | [
"public",
"function",
"addAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L139-L144 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.getAttribute | public function getAttribute($name)
{
return $this->hasAttribute($name) ? $this->attributes[$this->fixAttribute($name)] : null;
} | php | public function getAttribute($name)
{
return $this->hasAttribute($name) ? $this->attributes[$this->fixAttribute($name)] : null;
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"hasAttribute",
"(",
"$",
"name",
")",
"?",
"$",
"this",
"->",
"attributes",
"[",
"$",
"this",
"->",
"fixAttribute",
"(",
"$",
"name",
")",
"]",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L167-L170 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.getExpires | public function getExpires()
{
if ($this->hasAttribute(self::ATTR_EXPIRES)) {
return strtotime($this->getAttribute(self::ATTR_EXPIRES));
}
if ($this->hasAttribute(self::ATTR_MAX_AGE)) {
return $this->createdAt + $this->getAttribute(self::ATTR_MAX_AGE);
}
return false;
} | php | public function getExpires()
{
if ($this->hasAttribute(self::ATTR_EXPIRES)) {
return strtotime($this->getAttribute(self::ATTR_EXPIRES));
}
if ($this->hasAttribute(self::ATTR_MAX_AGE)) {
return $this->createdAt + $this->getAttribute(self::ATTR_MAX_AGE);
}
return false;
} | [
"public",
"function",
"getExpires",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasAttribute",
"(",
"self",
"::",
"ATTR_EXPIRES",
")",
")",
"{",
"return",
"strtotime",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_EXPIRES",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasAttribute",
"(",
"self",
"::",
"ATTR_MAX_AGE",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createdAt",
"+",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_MAX_AGE",
")",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L207-L218 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.compare | public function compare(CookieInterface $cookie)
{
return $this->name === $cookie->getName()
&& $this->getAttribute(self::ATTR_DOMAIN) === $cookie->getAttribute(self::ATTR_DOMAIN)
&& $this->getAttribute(self::ATTR_PATH) === $cookie->getAttribute(self::ATTR_PATH);
} | php | public function compare(CookieInterface $cookie)
{
return $this->name === $cookie->getName()
&& $this->getAttribute(self::ATTR_DOMAIN) === $cookie->getAttribute(self::ATTR_DOMAIN)
&& $this->getAttribute(self::ATTR_PATH) === $cookie->getAttribute(self::ATTR_PATH);
} | [
"public",
"function",
"compare",
"(",
"CookieInterface",
"$",
"cookie",
")",
"{",
"return",
"$",
"this",
"->",
"name",
"===",
"$",
"cookie",
"->",
"getName",
"(",
")",
"&&",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_DOMAIN",
")",
"===",
"$",
"cookie",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_DOMAIN",
")",
"&&",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_PATH",
")",
"===",
"$",
"cookie",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_PATH",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L231-L236 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.match | public function match(InternalRequestInterface $request)
{
return $this->matchDomain($request->getUri()->getHost())
&& $this->matchPath($request->getUri()->getPath())
&& $this->matchScheme($request->getUri()->getScheme());
} | php | public function match(InternalRequestInterface $request)
{
return $this->matchDomain($request->getUri()->getHost())
&& $this->matchPath($request->getUri()->getPath())
&& $this->matchScheme($request->getUri()->getScheme());
} | [
"public",
"function",
"match",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"matchDomain",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getHost",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"matchPath",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"matchScheme",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getScheme",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L241-L246 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.matchDomain | public function matchDomain($domain)
{
if (!$this->hasAttribute(self::ATTR_DOMAIN)) {
return true;
}
$cookieDomain = $this->getAttribute(self::ATTR_DOMAIN);
if (strpos($cookieDomain, '.') === 0) {
return (bool) preg_match('/\b'.preg_quote(substr($cookieDomain, 1), '/').'$/i', $domain);
}
return strcasecmp($cookieDomain, $domain) === 0;
} | php | public function matchDomain($domain)
{
if (!$this->hasAttribute(self::ATTR_DOMAIN)) {
return true;
}
$cookieDomain = $this->getAttribute(self::ATTR_DOMAIN);
if (strpos($cookieDomain, '.') === 0) {
return (bool) preg_match('/\b'.preg_quote(substr($cookieDomain, 1), '/').'$/i', $domain);
}
return strcasecmp($cookieDomain, $domain) === 0;
} | [
"public",
"function",
"matchDomain",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAttribute",
"(",
"self",
"::",
"ATTR_DOMAIN",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"cookieDomain",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_DOMAIN",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"cookieDomain",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"'/\\b'",
".",
"preg_quote",
"(",
"substr",
"(",
"$",
"cookieDomain",
",",
"1",
")",
",",
"'/'",
")",
".",
"'$/i'",
",",
"$",
"domain",
")",
";",
"}",
"return",
"strcasecmp",
"(",
"$",
"cookieDomain",
",",
"$",
"domain",
")",
"===",
"0",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L251-L264 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.matchPath | public function matchPath($path)
{
if (!$this->hasAttribute(self::ATTR_PATH)) {
return true;
}
return strpos($path, $this->getAttribute(self::ATTR_PATH)) === 0;
} | php | public function matchPath($path)
{
if (!$this->hasAttribute(self::ATTR_PATH)) {
return true;
}
return strpos($path, $this->getAttribute(self::ATTR_PATH)) === 0;
} | [
"public",
"function",
"matchPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAttribute",
"(",
"self",
"::",
"ATTR_PATH",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"strpos",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_PATH",
")",
")",
"===",
"0",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L269-L276 |
egeloen/ivory-http-adapter | src/Event/Cookie/Cookie.php | Cookie.matchScheme | public function matchScheme($scheme)
{
if (!$this->hasAttribute(self::ATTR_SECURE)) {
return true;
}
$secure = $this->getAttribute(self::ATTR_SECURE);
return ($secure && $scheme === 'https') || (!$secure && ($scheme === 'http' || $scheme === null));
} | php | public function matchScheme($scheme)
{
if (!$this->hasAttribute(self::ATTR_SECURE)) {
return true;
}
$secure = $this->getAttribute(self::ATTR_SECURE);
return ($secure && $scheme === 'https') || (!$secure && ($scheme === 'http' || $scheme === null));
} | [
"public",
"function",
"matchScheme",
"(",
"$",
"scheme",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAttribute",
"(",
"self",
"::",
"ATTR_SECURE",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"secure",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"self",
"::",
"ATTR_SECURE",
")",
";",
"return",
"(",
"$",
"secure",
"&&",
"$",
"scheme",
"===",
"'https'",
")",
"||",
"(",
"!",
"$",
"secure",
"&&",
"(",
"$",
"scheme",
"===",
"'http'",
"||",
"$",
"scheme",
"===",
"null",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cookie/Cookie.php#L281-L290 |
egeloen/ivory-http-adapter | src/Event/Cache/Adapter/DoctrineCacheAdapter.php | DoctrineCacheAdapter.get | public function get($id)
{
return $this->has($id) ? $this->cache->fetch($id) : null;
} | php | public function get($id)
{
return $this->has($id) ? $this->cache->fetch($id) : null;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
"?",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"$",
"id",
")",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Cache/Adapter/DoctrineCacheAdapter.php#L45-L48 |
egeloen/ivory-http-adapter | src/EventDispatcherHttpAdapter.php | EventDispatcherHttpAdapter.doSendInternalRequest | protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$this->eventDispatcher->dispatch(
Events::REQUEST_CREATED,
$requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest)
);
if ($requestCreatedEvent->hasException()) {
throw $requestCreatedEvent->getException();
}
$response = $requestCreatedEvent->hasResponse()
? $requestCreatedEvent->getResponse()
: parent::doSendInternalRequest($requestCreatedEvent->getRequest());
$this->eventDispatcher->dispatch(
Events::REQUEST_SENT,
$requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response)
);
if ($requestSentEvent->hasException()) {
throw $requestSentEvent->getException();
}
$response = $requestSentEvent->getResponse();
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
$e->setResponse(isset($response) ? $response : null);
$this->eventDispatcher->dispatch(
Events::REQUEST_ERRORED,
$exceptionEvent = new RequestErroredEvent($this, $e)
);
if ($exceptionEvent->hasResponse()) {
return $exceptionEvent->getResponse();
}
throw $exceptionEvent->getException();
}
return $response;
} | php | protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$this->eventDispatcher->dispatch(
Events::REQUEST_CREATED,
$requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest)
);
if ($requestCreatedEvent->hasException()) {
throw $requestCreatedEvent->getException();
}
$response = $requestCreatedEvent->hasResponse()
? $requestCreatedEvent->getResponse()
: parent::doSendInternalRequest($requestCreatedEvent->getRequest());
$this->eventDispatcher->dispatch(
Events::REQUEST_SENT,
$requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response)
);
if ($requestSentEvent->hasException()) {
throw $requestSentEvent->getException();
}
$response = $requestSentEvent->getResponse();
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
$e->setResponse(isset($response) ? $response : null);
$this->eventDispatcher->dispatch(
Events::REQUEST_ERRORED,
$exceptionEvent = new RequestErroredEvent($this, $e)
);
if ($exceptionEvent->hasResponse()) {
return $exceptionEvent->getResponse();
}
throw $exceptionEvent->getException();
}
return $response;
} | [
"protected",
"function",
"doSendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"REQUEST_CREATED",
",",
"$",
"requestCreatedEvent",
"=",
"new",
"RequestCreatedEvent",
"(",
"$",
"this",
",",
"$",
"internalRequest",
")",
")",
";",
"if",
"(",
"$",
"requestCreatedEvent",
"->",
"hasException",
"(",
")",
")",
"{",
"throw",
"$",
"requestCreatedEvent",
"->",
"getException",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"requestCreatedEvent",
"->",
"hasResponse",
"(",
")",
"?",
"$",
"requestCreatedEvent",
"->",
"getResponse",
"(",
")",
":",
"parent",
"::",
"doSendInternalRequest",
"(",
"$",
"requestCreatedEvent",
"->",
"getRequest",
"(",
")",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"REQUEST_SENT",
",",
"$",
"requestSentEvent",
"=",
"new",
"RequestSentEvent",
"(",
"$",
"this",
",",
"$",
"requestCreatedEvent",
"->",
"getRequest",
"(",
")",
",",
"$",
"response",
")",
")",
";",
"if",
"(",
"$",
"requestSentEvent",
"->",
"hasException",
"(",
")",
")",
"{",
"throw",
"$",
"requestSentEvent",
"->",
"getException",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"requestSentEvent",
"->",
"getResponse",
"(",
")",
";",
"}",
"catch",
"(",
"HttpAdapterException",
"$",
"e",
")",
"{",
"$",
"e",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"isset",
"(",
"$",
"response",
")",
"?",
"$",
"response",
":",
"null",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"REQUEST_ERRORED",
",",
"$",
"exceptionEvent",
"=",
"new",
"RequestErroredEvent",
"(",
"$",
"this",
",",
"$",
"e",
")",
")",
";",
"if",
"(",
"$",
"exceptionEvent",
"->",
"hasResponse",
"(",
")",
")",
"{",
"return",
"$",
"exceptionEvent",
"->",
"getResponse",
"(",
")",
";",
"}",
"throw",
"$",
"exceptionEvent",
"->",
"getException",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/EventDispatcherHttpAdapter.php#L48-L91 |
egeloen/ivory-http-adapter | src/EventDispatcherHttpAdapter.php | EventDispatcherHttpAdapter.doSendInternalRequests | protected function doSendInternalRequests(array $internalRequests)
{
$responses = [];
$exceptions = [];
if (!empty($internalRequests)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_CREATED,
$multiRequestCreatedEvent = new MultiRequestCreatedEvent($this, $internalRequests)
);
$internalRequests = $multiRequestCreatedEvent->getRequests();
$responses = $multiRequestCreatedEvent->getResponses();
$exceptions = $multiRequestCreatedEvent->getExceptions();
}
try {
$responses = array_merge($responses, parent::doSendInternalRequests($internalRequests));
} catch (MultiHttpAdapterException $e) {
$responses = array_merge($responses, $e->getResponses());
$exceptions = array_merge($exceptions, $e->getExceptions());
}
if (!empty($responses)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_SENT,
$requestSentEvent = new MultiRequestSentEvent($this, $responses)
);
$exceptions = array_merge($exceptions, $requestSentEvent->getExceptions());
$responses = $requestSentEvent->getResponses();
}
if (!empty($exceptions)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_ERRORED,
$exceptionEvent = new MultiRequestErroredEvent($this, $exceptions)
);
$responses = array_merge($responses, $exceptionEvent->getResponses());
$exceptions = $exceptionEvent->getExceptions();
if (!empty($exceptions)) {
throw new MultiHttpAdapterException($exceptions, $responses);
}
}
return $responses;
} | php | protected function doSendInternalRequests(array $internalRequests)
{
$responses = [];
$exceptions = [];
if (!empty($internalRequests)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_CREATED,
$multiRequestCreatedEvent = new MultiRequestCreatedEvent($this, $internalRequests)
);
$internalRequests = $multiRequestCreatedEvent->getRequests();
$responses = $multiRequestCreatedEvent->getResponses();
$exceptions = $multiRequestCreatedEvent->getExceptions();
}
try {
$responses = array_merge($responses, parent::doSendInternalRequests($internalRequests));
} catch (MultiHttpAdapterException $e) {
$responses = array_merge($responses, $e->getResponses());
$exceptions = array_merge($exceptions, $e->getExceptions());
}
if (!empty($responses)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_SENT,
$requestSentEvent = new MultiRequestSentEvent($this, $responses)
);
$exceptions = array_merge($exceptions, $requestSentEvent->getExceptions());
$responses = $requestSentEvent->getResponses();
}
if (!empty($exceptions)) {
$this->eventDispatcher->dispatch(
Events::MULTI_REQUEST_ERRORED,
$exceptionEvent = new MultiRequestErroredEvent($this, $exceptions)
);
$responses = array_merge($responses, $exceptionEvent->getResponses());
$exceptions = $exceptionEvent->getExceptions();
if (!empty($exceptions)) {
throw new MultiHttpAdapterException($exceptions, $responses);
}
}
return $responses;
} | [
"protected",
"function",
"doSendInternalRequests",
"(",
"array",
"$",
"internalRequests",
")",
"{",
"$",
"responses",
"=",
"[",
"]",
";",
"$",
"exceptions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"internalRequests",
")",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"MULTI_REQUEST_CREATED",
",",
"$",
"multiRequestCreatedEvent",
"=",
"new",
"MultiRequestCreatedEvent",
"(",
"$",
"this",
",",
"$",
"internalRequests",
")",
")",
";",
"$",
"internalRequests",
"=",
"$",
"multiRequestCreatedEvent",
"->",
"getRequests",
"(",
")",
";",
"$",
"responses",
"=",
"$",
"multiRequestCreatedEvent",
"->",
"getResponses",
"(",
")",
";",
"$",
"exceptions",
"=",
"$",
"multiRequestCreatedEvent",
"->",
"getExceptions",
"(",
")",
";",
"}",
"try",
"{",
"$",
"responses",
"=",
"array_merge",
"(",
"$",
"responses",
",",
"parent",
"::",
"doSendInternalRequests",
"(",
"$",
"internalRequests",
")",
")",
";",
"}",
"catch",
"(",
"MultiHttpAdapterException",
"$",
"e",
")",
"{",
"$",
"responses",
"=",
"array_merge",
"(",
"$",
"responses",
",",
"$",
"e",
"->",
"getResponses",
"(",
")",
")",
";",
"$",
"exceptions",
"=",
"array_merge",
"(",
"$",
"exceptions",
",",
"$",
"e",
"->",
"getExceptions",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"responses",
")",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"MULTI_REQUEST_SENT",
",",
"$",
"requestSentEvent",
"=",
"new",
"MultiRequestSentEvent",
"(",
"$",
"this",
",",
"$",
"responses",
")",
")",
";",
"$",
"exceptions",
"=",
"array_merge",
"(",
"$",
"exceptions",
",",
"$",
"requestSentEvent",
"->",
"getExceptions",
"(",
")",
")",
";",
"$",
"responses",
"=",
"$",
"requestSentEvent",
"->",
"getResponses",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"exceptions",
")",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Events",
"::",
"MULTI_REQUEST_ERRORED",
",",
"$",
"exceptionEvent",
"=",
"new",
"MultiRequestErroredEvent",
"(",
"$",
"this",
",",
"$",
"exceptions",
")",
")",
";",
"$",
"responses",
"=",
"array_merge",
"(",
"$",
"responses",
",",
"$",
"exceptionEvent",
"->",
"getResponses",
"(",
")",
")",
";",
"$",
"exceptions",
"=",
"$",
"exceptionEvent",
"->",
"getExceptions",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"exceptions",
")",
")",
"{",
"throw",
"new",
"MultiHttpAdapterException",
"(",
"$",
"exceptions",
",",
"$",
"responses",
")",
";",
"}",
"}",
"return",
"$",
"responses",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/EventDispatcherHttpAdapter.php#L96-L144 |
egeloen/ivory-http-adapter | src/Event/Retry/Strategy/AbstractRetryStrategyChain.php | AbstractRetryStrategyChain.verify | public function verify(InternalRequestInterface $request)
{
$verify = $this->doVerify($request);
if ($verify && $this->hasNext()) {
return $this->next->verify($request);
}
return $verify;
} | php | public function verify(InternalRequestInterface $request)
{
$verify = $this->doVerify($request);
if ($verify && $this->hasNext()) {
return $this->next->verify($request);
}
return $verify;
} | [
"public",
"function",
"verify",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"$",
"verify",
"=",
"$",
"this",
"->",
"doVerify",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"verify",
"&&",
"$",
"this",
"->",
"hasNext",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"next",
"->",
"verify",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"verify",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Retry/Strategy/AbstractRetryStrategyChain.php#L61-L70 |
egeloen/ivory-http-adapter | src/Event/Retry/Strategy/AbstractRetryStrategyChain.php | AbstractRetryStrategyChain.delay | public function delay(InternalRequestInterface $request)
{
$delay = $this->doDelay($request);
if ($this->hasNext() && (($nextDelay = $this->next->delay($request)) > $delay)) {
return $nextDelay;
}
return $delay;
} | php | public function delay(InternalRequestInterface $request)
{
$delay = $this->doDelay($request);
if ($this->hasNext() && (($nextDelay = $this->next->delay($request)) > $delay)) {
return $nextDelay;
}
return $delay;
} | [
"public",
"function",
"delay",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"$",
"delay",
"=",
"$",
"this",
"->",
"doDelay",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasNext",
"(",
")",
"&&",
"(",
"(",
"$",
"nextDelay",
"=",
"$",
"this",
"->",
"next",
"->",
"delay",
"(",
"$",
"request",
")",
")",
">",
"$",
"delay",
")",
")",
"{",
"return",
"$",
"nextDelay",
";",
"}",
"return",
"$",
"delay",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Retry/Strategy/AbstractRetryStrategyChain.php#L75-L84 |
egeloen/ivory-http-adapter | src/AbstractCurlHttpAdapter.php | AbstractCurlHttpAdapter.prepareContent | protected function prepareContent(InternalRequestInterface $internalRequest)
{
$files = $internalRequest->getFiles();
if (empty($files)) {
return $this->prepareBody($internalRequest);
}
$content = [];
foreach ($internalRequest->getDatas() as $name => $data) {
$content = array_merge($content, $this->prepareRawContent($name, $data));
}
foreach ($files as $name => $file) {
$content = array_merge($content, $this->prepareRawContent($name, $file, true));
}
return $content;
} | php | protected function prepareContent(InternalRequestInterface $internalRequest)
{
$files = $internalRequest->getFiles();
if (empty($files)) {
return $this->prepareBody($internalRequest);
}
$content = [];
foreach ($internalRequest->getDatas() as $name => $data) {
$content = array_merge($content, $this->prepareRawContent($name, $data));
}
foreach ($files as $name => $file) {
$content = array_merge($content, $this->prepareRawContent($name, $file, true));
}
return $content;
} | [
"protected",
"function",
"prepareContent",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"files",
"=",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"return",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
";",
"}",
"$",
"content",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"internalRequest",
"->",
"getDatas",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"data",
")",
"{",
"$",
"content",
"=",
"array_merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"prepareRawContent",
"(",
"$",
"name",
",",
"$",
"data",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"name",
"=>",
"$",
"file",
")",
"{",
"$",
"content",
"=",
"array_merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"prepareRawContent",
"(",
"$",
"name",
",",
"$",
"file",
",",
"true",
")",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@return array|string | [
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractCurlHttpAdapter.php#L53-L72 |
egeloen/ivory-http-adapter | src/AbstractCurlHttpAdapter.php | AbstractCurlHttpAdapter.prepareRawContent | private function prepareRawContent($name, $data, $isFile = false)
{
if (is_array($data)) {
$preparedData = [];
foreach ($data as $subName => $subData) {
$preparedData = array_merge(
$preparedData,
$this->prepareRawContent($this->prepareName($name, $subName), $subData, $isFile)
);
}
return $preparedData;
}
return [$name => $isFile ? $this->createFile($data) : $data];
} | php | private function prepareRawContent($name, $data, $isFile = false)
{
if (is_array($data)) {
$preparedData = [];
foreach ($data as $subName => $subData) {
$preparedData = array_merge(
$preparedData,
$this->prepareRawContent($this->prepareName($name, $subName), $subData, $isFile)
);
}
return $preparedData;
}
return [$name => $isFile ? $this->createFile($data) : $data];
} | [
"private",
"function",
"prepareRawContent",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"isFile",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"preparedData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"subName",
"=>",
"$",
"subData",
")",
"{",
"$",
"preparedData",
"=",
"array_merge",
"(",
"$",
"preparedData",
",",
"$",
"this",
"->",
"prepareRawContent",
"(",
"$",
"this",
"->",
"prepareName",
"(",
"$",
"name",
",",
"$",
"subName",
")",
",",
"$",
"subData",
",",
"$",
"isFile",
")",
")",
";",
"}",
"return",
"$",
"preparedData",
";",
"}",
"return",
"[",
"$",
"name",
"=>",
"$",
"isFile",
"?",
"$",
"this",
"->",
"createFile",
"(",
"$",
"data",
")",
":",
"$",
"data",
"]",
";",
"}"
] | @param string $name
@param array|string $data
@param bool $isFile
@return array | [
"@param",
"string",
"$name",
"@param",
"array|string",
"$data",
"@param",
"bool",
"$isFile"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractCurlHttpAdapter.php#L99-L115 |
egeloen/ivory-http-adapter | src/Zend2HttpAdapter.php | Zend2HttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client
->resetParameters(true)
->setOptions([
'httpversion' => $internalRequest->getProtocolVersion(),
'timeout' => $this->getConfiguration()->getTimeout(),
'maxredirects' => 0,
])
->setUri($uri = (string) $internalRequest->getUri())
->setMethod($internalRequest->getMethod())
->setHeaders($this->prepareHeaders($internalRequest))
->setRawBody($this->prepareBody($internalRequest));
try {
$response = $this->client->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatusCode(),
$response->getVersion(),
$response->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($response) {
return $response instanceof Stream ? $response->getStream() : $response->getBody();
},
$internalRequest->getMethod()
)
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client
->resetParameters(true)
->setOptions([
'httpversion' => $internalRequest->getProtocolVersion(),
'timeout' => $this->getConfiguration()->getTimeout(),
'maxredirects' => 0,
])
->setUri($uri = (string) $internalRequest->getUri())
->setMethod($internalRequest->getMethod())
->setHeaders($this->prepareHeaders($internalRequest))
->setRawBody($this->prepareBody($internalRequest));
try {
$response = $this->client->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
$response->getStatusCode(),
$response->getVersion(),
$response->getHeaders()->toArray(),
BodyNormalizer::normalize(
function () use ($response) {
return $response instanceof Stream ? $response->getStream() : $response->getBody();
},
$internalRequest->getMethod()
)
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"resetParameters",
"(",
"true",
")",
"->",
"setOptions",
"(",
"[",
"'httpversion'",
"=>",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'maxredirects'",
"=>",
"0",
",",
"]",
")",
"->",
"setUri",
"(",
"$",
"uri",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
")",
"->",
"setMethod",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
")",
"->",
"setRawBody",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"instanceof",
"Stream",
"?",
"$",
"response",
"->",
"getStream",
"(",
")",
":",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Zend2HttpAdapter.php#L51-L82 |
egeloen/ivory-http-adapter | src/Guzzle4HttpAdapter.php | Guzzle4HttpAdapter.sendInternalRequest | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$response = $this->client->send($this->createRequest($internalRequest));
} catch (RequestException $e) {
throw HttpAdapterException::cannotFetchUri(
$e->getRequest()->getUrl(),
$this->getName(),
$e->getMessage()
);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response->getBody()->detach();
},
$internalRequest->getMethod()
)
);
} | php | protected function sendInternalRequest(InternalRequestInterface $internalRequest)
{
try {
$response = $this->client->send($this->createRequest($internalRequest));
} catch (RequestException $e) {
throw HttpAdapterException::cannotFetchUri(
$e->getRequest()->getUrl(),
$this->getName(),
$e->getMessage()
);
}
return $this->getConfiguration()->getMessageFactory()->createResponse(
(int) $response->getStatusCode(),
$response->getProtocolVersion(),
$response->getHeaders(),
BodyNormalizer::normalize(
function () use ($response) {
return $response->getBody()->detach();
},
$internalRequest->getMethod()
)
);
} | [
"protected",
"function",
"sendInternalRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"internalRequest",
")",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"throw",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"e",
"->",
"getRequest",
"(",
")",
"->",
"getUrl",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createResponse",
"(",
"(",
"int",
")",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"response",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"detach",
"(",
")",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle4HttpAdapter.php#L56-L79 |
egeloen/ivory-http-adapter | src/Guzzle4HttpAdapter.php | Guzzle4HttpAdapter.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $internalRequest) {
$requests[] = $this->createRequest($internalRequest, $success, $error);
}
class_exists('GuzzleHttp\Pool')
? Pool::batch($this->client, $requests)
: \GuzzleHttp\batch($this->client, $requests);
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
$requests = [];
foreach ($internalRequests as $internalRequest) {
$requests[] = $this->createRequest($internalRequest, $success, $error);
}
class_exists('GuzzleHttp\Pool')
? Pool::batch($this->client, $requests)
: \GuzzleHttp\batch($this->client, $requests);
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"$",
"requests",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"internalRequests",
"as",
"$",
"internalRequest",
")",
"{",
"$",
"requests",
"[",
"]",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"internalRequest",
",",
"$",
"success",
",",
"$",
"error",
")",
";",
"}",
"class_exists",
"(",
"'GuzzleHttp\\Pool'",
")",
"?",
"Pool",
"::",
"batch",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"requests",
")",
":",
"\\",
"GuzzleHttp",
"\\",
"batch",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"requests",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle4HttpAdapter.php#L84-L94 |
egeloen/ivory-http-adapter | src/Guzzle4HttpAdapter.php | Guzzle4HttpAdapter.createRequest | private function createRequest(InternalRequestInterface $internalRequest, $success = null, $error = null)
{
$request = $this->client->createRequest(
$internalRequest->getMethod(),
(string) $internalRequest->getUri(),
[
'exceptions' => false,
'allow_redirects' => false,
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
'version' => $internalRequest->getProtocolVersion(),
'headers' => $this->prepareHeaders($internalRequest),
'body' => $this->prepareContent($internalRequest),
]
);
if (is_callable($success)) {
$messageFactory = $this->getConfiguration()->getMessageFactory();
$request->getEmitter()->on(
'complete',
function (CompleteEvent $event) use ($success, $internalRequest, $messageFactory) {
$response = $messageFactory->createResponse(
(int) $event->getResponse()->getStatusCode(),
$event->getResponse()->getProtocolVersion(),
$event->getResponse()->getHeaders(),
BodyNormalizer::normalize(
function () use ($event) {
return $event->getResponse()->getBody()->detach();
},
$internalRequest->getMethod()
)
);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
}
);
}
if (is_callable($error)) {
$httpAdapterName = $this->getName();
$request->getEmitter()->on(
'error',
function (ErrorEvent $event) use ($error, $internalRequest, $httpAdapterName) {
$exception = HttpAdapterException::cannotFetchUri(
$event->getException()->getRequest()->getUrl(),
$httpAdapterName,
$event->getException()->getMessage()
);
$exception->setRequest($internalRequest);
call_user_func($error, $exception);
}
);
}
return $request;
} | php | private function createRequest(InternalRequestInterface $internalRequest, $success = null, $error = null)
{
$request = $this->client->createRequest(
$internalRequest->getMethod(),
(string) $internalRequest->getUri(),
[
'exceptions' => false,
'allow_redirects' => false,
'timeout' => $this->getConfiguration()->getTimeout(),
'connect_timeout' => $this->getConfiguration()->getTimeout(),
'version' => $internalRequest->getProtocolVersion(),
'headers' => $this->prepareHeaders($internalRequest),
'body' => $this->prepareContent($internalRequest),
]
);
if (is_callable($success)) {
$messageFactory = $this->getConfiguration()->getMessageFactory();
$request->getEmitter()->on(
'complete',
function (CompleteEvent $event) use ($success, $internalRequest, $messageFactory) {
$response = $messageFactory->createResponse(
(int) $event->getResponse()->getStatusCode(),
$event->getResponse()->getProtocolVersion(),
$event->getResponse()->getHeaders(),
BodyNormalizer::normalize(
function () use ($event) {
return $event->getResponse()->getBody()->detach();
},
$internalRequest->getMethod()
)
);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
}
);
}
if (is_callable($error)) {
$httpAdapterName = $this->getName();
$request->getEmitter()->on(
'error',
function (ErrorEvent $event) use ($error, $internalRequest, $httpAdapterName) {
$exception = HttpAdapterException::cannotFetchUri(
$event->getException()->getRequest()->getUrl(),
$httpAdapterName,
$event->getException()->getMessage()
);
$exception->setRequest($internalRequest);
call_user_func($error, $exception);
}
);
}
return $request;
} | [
"private",
"function",
"createRequest",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
",",
"$",
"success",
"=",
"null",
",",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
",",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"[",
"'exceptions'",
"=>",
"false",
",",
"'allow_redirects'",
"=>",
"false",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'connect_timeout'",
"=>",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getTimeout",
"(",
")",
",",
"'version'",
"=>",
"$",
"internalRequest",
"->",
"getProtocolVersion",
"(",
")",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"prepareHeaders",
"(",
"$",
"internalRequest",
")",
",",
"'body'",
"=>",
"$",
"this",
"->",
"prepareContent",
"(",
"$",
"internalRequest",
")",
",",
"]",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"success",
")",
")",
"{",
"$",
"messageFactory",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
";",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"on",
"(",
"'complete'",
",",
"function",
"(",
"CompleteEvent",
"$",
"event",
")",
"use",
"(",
"$",
"success",
",",
"$",
"internalRequest",
",",
"$",
"messageFactory",
")",
"{",
"$",
"response",
"=",
"$",
"messageFactory",
"->",
"createResponse",
"(",
"(",
"int",
")",
"$",
"event",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"event",
"->",
"getResponse",
"(",
")",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"event",
"->",
"getResponse",
"(",
")",
"->",
"getHeaders",
"(",
")",
",",
"BodyNormalizer",
"::",
"normalize",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"event",
")",
"{",
"return",
"$",
"event",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
"->",
"detach",
"(",
")",
";",
"}",
",",
"$",
"internalRequest",
"->",
"getMethod",
"(",
")",
")",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withParameter",
"(",
"'request'",
",",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"error",
")",
")",
"{",
"$",
"httpAdapterName",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"on",
"(",
"'error'",
",",
"function",
"(",
"ErrorEvent",
"$",
"event",
")",
"use",
"(",
"$",
"error",
",",
"$",
"internalRequest",
",",
"$",
"httpAdapterName",
")",
"{",
"$",
"exception",
"=",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"$",
"event",
"->",
"getException",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getUrl",
"(",
")",
",",
"$",
"httpAdapterName",
",",
"$",
"event",
"->",
"getException",
"(",
")",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"exception",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"exception",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"request",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@param callable|null $success
@param callable|null $error
@return RequestInterface the request | [
"@param",
"InternalRequestInterface",
"$internalRequest",
"@param",
"callable|null",
"$success",
"@param",
"callable|null",
"$error"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Guzzle4HttpAdapter.php#L111-L169 |
egeloen/ivory-http-adapter | src/Event/Timer/Timer.php | Timer.start | public function start(InternalRequestInterface $internalRequest)
{
return $internalRequest
->withParameter(self::START_TIME, $this->getTime())
->withoutParameter(self::TIME);
} | php | public function start(InternalRequestInterface $internalRequest)
{
return $internalRequest
->withParameter(self::START_TIME, $this->getTime())
->withoutParameter(self::TIME);
} | [
"public",
"function",
"start",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"return",
"$",
"internalRequest",
"->",
"withParameter",
"(",
"self",
"::",
"START_TIME",
",",
"$",
"this",
"->",
"getTime",
"(",
")",
")",
"->",
"withoutParameter",
"(",
"self",
"::",
"TIME",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Timer/Timer.php#L24-L29 |
egeloen/ivory-http-adapter | src/Event/Timer/Timer.php | Timer.stop | public function stop(InternalRequestInterface $internalRequest)
{
if ($internalRequest->hasParameter(self::START_TIME) && !$internalRequest->hasParameter(self::TIME)) {
return $internalRequest->withParameter(
self::TIME,
$this->getTime() - $internalRequest->getParameter(self::START_TIME)
);
}
return $internalRequest;
} | php | public function stop(InternalRequestInterface $internalRequest)
{
if ($internalRequest->hasParameter(self::START_TIME) && !$internalRequest->hasParameter(self::TIME)) {
return $internalRequest->withParameter(
self::TIME,
$this->getTime() - $internalRequest->getParameter(self::START_TIME)
);
}
return $internalRequest;
} | [
"public",
"function",
"stop",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"if",
"(",
"$",
"internalRequest",
"->",
"hasParameter",
"(",
"self",
"::",
"START_TIME",
")",
"&&",
"!",
"$",
"internalRequest",
"->",
"hasParameter",
"(",
"self",
"::",
"TIME",
")",
")",
"{",
"return",
"$",
"internalRequest",
"->",
"withParameter",
"(",
"self",
"::",
"TIME",
",",
"$",
"this",
"->",
"getTime",
"(",
")",
"-",
"$",
"internalRequest",
"->",
"getParameter",
"(",
"self",
"::",
"START_TIME",
")",
")",
";",
"}",
"return",
"$",
"internalRequest",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Timer/Timer.php#L34-L44 |
egeloen/ivory-http-adapter | src/Event/Retry/Strategy/CallbackRetryStrategy.php | CallbackRetryStrategy.doVerify | protected function doVerify(InternalRequestInterface $request)
{
if ($this->hasVerifyCallback()) {
return call_user_func($this->verifyCallback, $request);
}
return parent::doVerify($request);
} | php | protected function doVerify(InternalRequestInterface $request)
{
if ($this->hasVerifyCallback()) {
return call_user_func($this->verifyCallback, $request);
}
return parent::doVerify($request);
} | [
"protected",
"function",
"doVerify",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasVerifyCallback",
"(",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"verifyCallback",
",",
"$",
"request",
")",
";",
"}",
"return",
"parent",
"::",
"doVerify",
"(",
"$",
"request",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Retry/Strategy/CallbackRetryStrategy.php#L95-L102 |
egeloen/ivory-http-adapter | src/Event/Retry/Strategy/CallbackRetryStrategy.php | CallbackRetryStrategy.doDelay | protected function doDelay(InternalRequestInterface $request)
{
if ($this->hasDelayCallback()) {
return call_user_func($this->delayCallback, $request);
}
return parent::doDelay($request);
} | php | protected function doDelay(InternalRequestInterface $request)
{
if ($this->hasDelayCallback()) {
return call_user_func($this->delayCallback, $request);
}
return parent::doDelay($request);
} | [
"protected",
"function",
"doDelay",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasDelayCallback",
"(",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"delayCallback",
",",
"$",
"request",
")",
";",
"}",
"return",
"parent",
"::",
"doDelay",
"(",
"$",
"request",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Retry/Strategy/CallbackRetryStrategy.php#L107-L114 |
egeloen/ivory-http-adapter | src/Message/InternalRequest.php | InternalRequest.withAddedData | public function withAddedData($name, $value)
{
$new = clone $this;
$new->datas[$name] = $new->hasData($name)
? array_merge((array) $new->datas[$name], (array) $value)
: $value;
return $new;
} | php | public function withAddedData($name, $value)
{
$new = clone $this;
$new->datas[$name] = $new->hasData($name)
? array_merge((array) $new->datas[$name], (array) $value)
: $value;
return $new;
} | [
"public",
"function",
"withAddedData",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"datas",
"[",
"$",
"name",
"]",
"=",
"$",
"new",
"->",
"hasData",
"(",
"$",
"name",
")",
"?",
"array_merge",
"(",
"(",
"array",
")",
"$",
"new",
"->",
"datas",
"[",
"$",
"name",
"]",
",",
"(",
"array",
")",
"$",
"value",
")",
":",
"$",
"value",
";",
"return",
"$",
"new",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/InternalRequest.php#L94-L102 |
egeloen/ivory-http-adapter | src/Message/InternalRequest.php | InternalRequest.withAddedFile | public function withAddedFile($name, $file)
{
$new = clone $this;
$new->files[$name] = $new->hasFile($name)
? array_merge((array) $new->files[$name], (array) $file)
: $file;
return $new;
} | php | public function withAddedFile($name, $file)
{
$new = clone $this;
$new->files[$name] = $new->hasFile($name)
? array_merge((array) $new->files[$name], (array) $file)
: $file;
return $new;
} | [
"public",
"function",
"withAddedFile",
"(",
"$",
"name",
",",
"$",
"file",
")",
"{",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"$",
"new",
"->",
"files",
"[",
"$",
"name",
"]",
"=",
"$",
"new",
"->",
"hasFile",
"(",
"$",
"name",
")",
"?",
"array_merge",
"(",
"(",
"array",
")",
"$",
"new",
"->",
"files",
"[",
"$",
"name",
"]",
",",
"(",
"array",
")",
"$",
"file",
")",
":",
"$",
"file",
";",
"return",
"$",
"new",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Message/InternalRequest.php#L153-L161 |
egeloen/ivory-http-adapter | src/Event/Formatter/Formatter.php | Formatter.formatRequest | public function formatRequest(InternalRequestInterface $request)
{
return [
'protocol_version' => $request->getProtocolVersion(),
'uri' => (string) $request->getUri(),
'method' => $request->getMethod(),
'headers' => $request->getHeaders(),
'body' => utf8_encode((string) $request->getBody()),
'datas' => $request->getDatas(),
'files' => $request->getFiles(),
'parameters' => $this->filterParameters($request->getParameters()),
];
} | php | public function formatRequest(InternalRequestInterface $request)
{
return [
'protocol_version' => $request->getProtocolVersion(),
'uri' => (string) $request->getUri(),
'method' => $request->getMethod(),
'headers' => $request->getHeaders(),
'body' => utf8_encode((string) $request->getBody()),
'datas' => $request->getDatas(),
'files' => $request->getFiles(),
'parameters' => $this->filterParameters($request->getParameters()),
];
} | [
"public",
"function",
"formatRequest",
"(",
"InternalRequestInterface",
"$",
"request",
")",
"{",
"return",
"[",
"'protocol_version'",
"=>",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
",",
"'uri'",
"=>",
"(",
"string",
")",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"'method'",
"=>",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"'headers'",
"=>",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"'body'",
"=>",
"utf8_encode",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
",",
"'datas'",
"=>",
"$",
"request",
"->",
"getDatas",
"(",
")",
",",
"'files'",
"=>",
"$",
"request",
"->",
"getFiles",
"(",
")",
",",
"'parameters'",
"=>",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"request",
"->",
"getParameters",
"(",
")",
")",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Formatter/Formatter.php#L26-L38 |
egeloen/ivory-http-adapter | src/Event/Formatter/Formatter.php | Formatter.formatResponse | public function formatResponse(ResponseInterface $response)
{
return [
'protocol_version' => $response->getProtocolVersion(),
'status_code' => $response->getStatusCode(),
'reason_phrase' => $response->getReasonPhrase(),
'headers' => $response->getHeaders(),
'body' => utf8_encode((string) $response->getBody()),
'parameters' => $this->filterParameters($response->getParameters()),
];
} | php | public function formatResponse(ResponseInterface $response)
{
return [
'protocol_version' => $response->getProtocolVersion(),
'status_code' => $response->getStatusCode(),
'reason_phrase' => $response->getReasonPhrase(),
'headers' => $response->getHeaders(),
'body' => utf8_encode((string) $response->getBody()),
'parameters' => $this->filterParameters($response->getParameters()),
];
} | [
"public",
"function",
"formatResponse",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"return",
"[",
"'protocol_version'",
"=>",
"$",
"response",
"->",
"getProtocolVersion",
"(",
")",
",",
"'status_code'",
"=>",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"'reason_phrase'",
"=>",
"$",
"response",
"->",
"getReasonPhrase",
"(",
")",
",",
"'headers'",
"=>",
"$",
"response",
"->",
"getHeaders",
"(",
")",
",",
"'body'",
"=>",
"utf8_encode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
",",
"'parameters'",
"=>",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"response",
"->",
"getParameters",
"(",
")",
")",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Formatter/Formatter.php#L43-L53 |
egeloen/ivory-http-adapter | src/Event/Formatter/Formatter.php | Formatter.formatException | public function formatException(HttpAdapterException $exception)
{
return [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
];
} | php | public function formatException(HttpAdapterException $exception)
{
return [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
];
} | [
"public",
"function",
"formatException",
"(",
"HttpAdapterException",
"$",
"exception",
")",
"{",
"return",
"[",
"'code'",
"=>",
"$",
"exception",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'line'",
"=>",
"$",
"exception",
"->",
"getLine",
"(",
")",
",",
"'file'",
"=>",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Formatter/Formatter.php#L58-L66 |
egeloen/ivory-http-adapter | src/HttpAdapterException.php | HttpAdapterException.maxRedirectsExceeded | public static function maxRedirectsExceeded($uri, $maxRedirects, $adapter)
{
return self::cannotFetchUri($uri, $adapter, sprintf('Max redirects exceeded (%d)', $maxRedirects));
} | php | public static function maxRedirectsExceeded($uri, $maxRedirects, $adapter)
{
return self::cannotFetchUri($uri, $adapter, sprintf('Max redirects exceeded (%d)', $maxRedirects));
} | [
"public",
"static",
"function",
"maxRedirectsExceeded",
"(",
"$",
"uri",
",",
"$",
"maxRedirects",
",",
"$",
"adapter",
")",
"{",
"return",
"self",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"adapter",
",",
"sprintf",
"(",
"'Max redirects exceeded (%d)'",
",",
"$",
"maxRedirects",
")",
")",
";",
"}"
] | @param string $uri
@param int $maxRedirects
@param string $adapter
@return HttpAdapterException | [
"@param",
"string",
"$uri",
"@param",
"int",
"$maxRedirects",
"@param",
"string",
"$adapter"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterException.php#L184-L187 |
egeloen/ivory-http-adapter | src/HttpAdapterException.php | HttpAdapterException.requestIsNotValid | public static function requestIsNotValid($request)
{
return new self(sprintf(
'The request must be a string, an array or implement "Psr\Http\Message\RequestInterface" ("%s" given).',
is_object($request) ? get_class($request) : gettype($request)
));
} | php | public static function requestIsNotValid($request)
{
return new self(sprintf(
'The request must be a string, an array or implement "Psr\Http\Message\RequestInterface" ("%s" given).',
is_object($request) ? get_class($request) : gettype($request)
));
} | [
"public",
"static",
"function",
"requestIsNotValid",
"(",
"$",
"request",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'The request must be a string, an array or implement \"Psr\\Http\\Message\\RequestInterface\" (\"%s\" given).'",
",",
"is_object",
"(",
"$",
"request",
")",
"?",
"get_class",
"(",
"$",
"request",
")",
":",
"gettype",
"(",
"$",
"request",
")",
")",
")",
";",
"}"
] | @param mixed $request
@return HttpAdapterException | [
"@param",
"mixed",
"$request"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterException.php#L194-L200 |
egeloen/ivory-http-adapter | src/HttpAdapterException.php | HttpAdapterException.streamIsNotValid | public static function streamIsNotValid($stream, $wrapper, $expected)
{
return new self(sprintf(
'The stream "%s" only accepts a "%s" (current: "%s")',
$wrapper,
$expected,
is_object($stream) ? get_class($stream) : gettype($stream)
));
} | php | public static function streamIsNotValid($stream, $wrapper, $expected)
{
return new self(sprintf(
'The stream "%s" only accepts a "%s" (current: "%s")',
$wrapper,
$expected,
is_object($stream) ? get_class($stream) : gettype($stream)
));
} | [
"public",
"static",
"function",
"streamIsNotValid",
"(",
"$",
"stream",
",",
"$",
"wrapper",
",",
"$",
"expected",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'The stream \"%s\" only accepts a \"%s\" (current: \"%s\")'",
",",
"$",
"wrapper",
",",
"$",
"expected",
",",
"is_object",
"(",
"$",
"stream",
")",
"?",
"get_class",
"(",
"$",
"stream",
")",
":",
"gettype",
"(",
"$",
"stream",
")",
")",
")",
";",
"}"
] | @param mixed $stream
@param string $wrapper
@param string $expected
@return HttpAdapterException | [
"@param",
"mixed",
"$stream",
"@param",
"string",
"$wrapper",
"@param",
"string",
"$expected"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterException.php#L209-L217 |
egeloen/ivory-http-adapter | src/HttpAdapterException.php | HttpAdapterException.timeoutExceeded | public static function timeoutExceeded($uri, $timeout, $adapter)
{
return self::cannotFetchUri($uri, $adapter, sprintf('Timeout exceeded (%.2f)', $timeout));
} | php | public static function timeoutExceeded($uri, $timeout, $adapter)
{
return self::cannotFetchUri($uri, $adapter, sprintf('Timeout exceeded (%.2f)', $timeout));
} | [
"public",
"static",
"function",
"timeoutExceeded",
"(",
"$",
"uri",
",",
"$",
"timeout",
",",
"$",
"adapter",
")",
"{",
"return",
"self",
"::",
"cannotFetchUri",
"(",
"$",
"uri",
",",
"$",
"adapter",
",",
"sprintf",
"(",
"'Timeout exceeded (%.2f)'",
",",
"$",
"timeout",
")",
")",
";",
"}"
] | @param string $uri
@param float $timeout
@param string $adapter
@return HttpAdapterException | [
"@param",
"string",
"$uri",
"@param",
"float",
"$timeout",
"@param",
"string",
"$adapter"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterException.php#L226-L229 |
egeloen/ivory-http-adapter | src/Event/Subscriber/HistorySubscriber.php | HistorySubscriber.record | private function record(InternalRequestInterface $internalRequest, ResponseInterface $response)
{
$internalRequest = $this->getTimer()->stop($internalRequest);
$this->journal->record($internalRequest, $response);
return $internalRequest;
} | php | private function record(InternalRequestInterface $internalRequest, ResponseInterface $response)
{
$internalRequest = $this->getTimer()->stop($internalRequest);
$this->journal->record($internalRequest, $response);
return $internalRequest;
} | [
"private",
"function",
"record",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"this",
"->",
"getTimer",
"(",
")",
"->",
"stop",
"(",
"$",
"internalRequest",
")",
";",
"$",
"this",
"->",
"journal",
"->",
"record",
"(",
"$",
"internalRequest",
",",
"$",
"response",
")",
";",
"return",
"$",
"internalRequest",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@param ResponseInterface $response
@return InternalRequestInterface | [
"@param",
"InternalRequestInterface",
"$internalRequest",
"@param",
"ResponseInterface",
"$response"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Subscriber/HistorySubscriber.php#L113-L119 |
egeloen/ivory-http-adapter | src/AbstractHttpAdapter.php | AbstractHttpAdapter.prepareHeaders | protected function prepareHeaders(
InternalRequestInterface &$internalRequest,
$associative = true,
$contentType = true,
$contentLength = false
) {
if (!$internalRequest->hasHeader('Connection')) {
$internalRequest = $internalRequest->withHeader(
'Connection',
$this->configuration->getKeepAlive() ? 'keep-alive' : 'close'
);
}
if (!$internalRequest->hasHeader('Content-Type')) {
$rawDatas = (string) $internalRequest->getBody();
$datas = $internalRequest->getDatas();
$files = $internalRequest->getFiles();
if ($this->configuration->hasEncodingType()) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
$this->configuration->getEncodingType()
);
} elseif ($contentType && !empty($files)) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_FORMDATA.'; boundary='.$this->configuration->getBoundary()
);
} elseif ($contentType && (!empty($datas) || !empty($rawDatas))) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_URLENCODED
);
}
}
if ($contentLength && !$internalRequest->hasHeader('Content-Length')
&& ($length = strlen($this->prepareBody($internalRequest))) > 0) {
$internalRequest = $internalRequest->withHeader('Content-Length', (string) $length);
}
if (!$internalRequest->hasHeader('User-Agent')) {
$internalRequest = $internalRequest->withHeader('User-Agent', $this->configuration->getUserAgent());
}
return HeadersNormalizer::normalize($internalRequest->getHeaders(), $associative);
} | php | protected function prepareHeaders(
InternalRequestInterface &$internalRequest,
$associative = true,
$contentType = true,
$contentLength = false
) {
if (!$internalRequest->hasHeader('Connection')) {
$internalRequest = $internalRequest->withHeader(
'Connection',
$this->configuration->getKeepAlive() ? 'keep-alive' : 'close'
);
}
if (!$internalRequest->hasHeader('Content-Type')) {
$rawDatas = (string) $internalRequest->getBody();
$datas = $internalRequest->getDatas();
$files = $internalRequest->getFiles();
if ($this->configuration->hasEncodingType()) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
$this->configuration->getEncodingType()
);
} elseif ($contentType && !empty($files)) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_FORMDATA.'; boundary='.$this->configuration->getBoundary()
);
} elseif ($contentType && (!empty($datas) || !empty($rawDatas))) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_URLENCODED
);
}
}
if ($contentLength && !$internalRequest->hasHeader('Content-Length')
&& ($length = strlen($this->prepareBody($internalRequest))) > 0) {
$internalRequest = $internalRequest->withHeader('Content-Length', (string) $length);
}
if (!$internalRequest->hasHeader('User-Agent')) {
$internalRequest = $internalRequest->withHeader('User-Agent', $this->configuration->getUserAgent());
}
return HeadersNormalizer::normalize($internalRequest->getHeaders(), $associative);
} | [
"protected",
"function",
"prepareHeaders",
"(",
"InternalRequestInterface",
"&",
"$",
"internalRequest",
",",
"$",
"associative",
"=",
"true",
",",
"$",
"contentType",
"=",
"true",
",",
"$",
"contentLength",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"internalRequest",
"->",
"hasHeader",
"(",
"'Connection'",
")",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'Connection'",
",",
"$",
"this",
"->",
"configuration",
"->",
"getKeepAlive",
"(",
")",
"?",
"'keep-alive'",
":",
"'close'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"internalRequest",
"->",
"hasHeader",
"(",
"'Content-Type'",
")",
")",
"{",
"$",
"rawDatas",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getBody",
"(",
")",
";",
"$",
"datas",
"=",
"$",
"internalRequest",
"->",
"getDatas",
"(",
")",
";",
"$",
"files",
"=",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"hasEncodingType",
"(",
")",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"$",
"this",
"->",
"configuration",
"->",
"getEncodingType",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"contentType",
"&&",
"!",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"ConfigurationInterface",
"::",
"ENCODING_TYPE_FORMDATA",
".",
"'; boundary='",
".",
"$",
"this",
"->",
"configuration",
"->",
"getBoundary",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"contentType",
"&&",
"(",
"!",
"empty",
"(",
"$",
"datas",
")",
"||",
"!",
"empty",
"(",
"$",
"rawDatas",
")",
")",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"ConfigurationInterface",
"::",
"ENCODING_TYPE_URLENCODED",
")",
";",
"}",
"}",
"if",
"(",
"$",
"contentLength",
"&&",
"!",
"$",
"internalRequest",
"->",
"hasHeader",
"(",
"'Content-Length'",
")",
"&&",
"(",
"$",
"length",
"=",
"strlen",
"(",
"$",
"this",
"->",
"prepareBody",
"(",
"$",
"internalRequest",
")",
")",
")",
">",
"0",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'Content-Length'",
",",
"(",
"string",
")",
"$",
"length",
")",
";",
"}",
"if",
"(",
"!",
"$",
"internalRequest",
"->",
"hasHeader",
"(",
"'User-Agent'",
")",
")",
"{",
"$",
"internalRequest",
"=",
"$",
"internalRequest",
"->",
"withHeader",
"(",
"'User-Agent'",
",",
"$",
"this",
"->",
"configuration",
"->",
"getUserAgent",
"(",
")",
")",
";",
"}",
"return",
"HeadersNormalizer",
"::",
"normalize",
"(",
"$",
"internalRequest",
"->",
"getHeaders",
"(",
")",
",",
"$",
"associative",
")",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@param bool $associative
@param bool $contentType
@param bool $contentLength
@return array the prepared headers | [
"@param",
"InternalRequestInterface",
"$internalRequest",
"@param",
"bool",
"$associative",
"@param",
"bool",
"$contentType",
"@param",
"bool",
"$contentLength"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractHttpAdapter.php#L61-L107 |
egeloen/ivory-http-adapter | src/AbstractHttpAdapter.php | AbstractHttpAdapter.prepareBody | protected function prepareBody(InternalRequestInterface $internalRequest)
{
$body = (string) $internalRequest->getBody();
if (!empty($body)) {
return $body;
}
$files = $internalRequest->getFiles();
if (empty($files)) {
return http_build_query($internalRequest->getDatas(), null, '&');
}
$body = '';
foreach ($internalRequest->getDatas() as $name => $value) {
$body .= $this->prepareRawBody($name, $value);
}
foreach ($internalRequest->getFiles() as $name => $file) {
$body .= $this->prepareRawBody($name, $file, true);
}
$body .= '--'.$this->configuration->getBoundary().'--'."\r\n";
return $body;
} | php | protected function prepareBody(InternalRequestInterface $internalRequest)
{
$body = (string) $internalRequest->getBody();
if (!empty($body)) {
return $body;
}
$files = $internalRequest->getFiles();
if (empty($files)) {
return http_build_query($internalRequest->getDatas(), null, '&');
}
$body = '';
foreach ($internalRequest->getDatas() as $name => $value) {
$body .= $this->prepareRawBody($name, $value);
}
foreach ($internalRequest->getFiles() as $name => $file) {
$body .= $this->prepareRawBody($name, $file, true);
}
$body .= '--'.$this->configuration->getBoundary().'--'."\r\n";
return $body;
} | [
"protected",
"function",
"prepareBody",
"(",
"InternalRequestInterface",
"$",
"internalRequest",
")",
"{",
"$",
"body",
"=",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"return",
"$",
"body",
";",
"}",
"$",
"files",
"=",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"return",
"http_build_query",
"(",
"$",
"internalRequest",
"->",
"getDatas",
"(",
")",
",",
"null",
",",
"'&'",
")",
";",
"}",
"$",
"body",
"=",
"''",
";",
"foreach",
"(",
"$",
"internalRequest",
"->",
"getDatas",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"body",
".=",
"$",
"this",
"->",
"prepareRawBody",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"internalRequest",
"->",
"getFiles",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"file",
")",
"{",
"$",
"body",
".=",
"$",
"this",
"->",
"prepareRawBody",
"(",
"$",
"name",
",",
"$",
"file",
",",
"true",
")",
";",
"}",
"$",
"body",
".=",
"'--'",
".",
"$",
"this",
"->",
"configuration",
"->",
"getBoundary",
"(",
")",
".",
"'--'",
".",
"\"\\r\\n\"",
";",
"return",
"$",
"body",
";",
"}"
] | @param InternalRequestInterface $internalRequest
@return string | [
"@param",
"InternalRequestInterface",
"$internalRequest"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractHttpAdapter.php#L114-L141 |
egeloen/ivory-http-adapter | src/AbstractHttpAdapter.php | AbstractHttpAdapter.prepareRawBody | private function prepareRawBody($name, $data, $isFile = false)
{
if (is_array($data)) {
$body = '';
foreach ($data as $subName => $subData) {
$body .= $this->prepareRawBody($this->prepareName($name, $subName), $subData, $isFile);
}
return $body;
}
$body = '--'.$this->configuration->getBoundary()."\r\n".'Content-Disposition: form-data; name="'.$name.'"';
if ($isFile) {
$body .= '; filename="'.basename($data).'"';
$data = file_get_contents($data);
}
return $body."\r\n\r\n".$data."\r\n";
} | php | private function prepareRawBody($name, $data, $isFile = false)
{
if (is_array($data)) {
$body = '';
foreach ($data as $subName => $subData) {
$body .= $this->prepareRawBody($this->prepareName($name, $subName), $subData, $isFile);
}
return $body;
}
$body = '--'.$this->configuration->getBoundary()."\r\n".'Content-Disposition: form-data; name="'.$name.'"';
if ($isFile) {
$body .= '; filename="'.basename($data).'"';
$data = file_get_contents($data);
}
return $body."\r\n\r\n".$data."\r\n";
} | [
"private",
"function",
"prepareRawBody",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"isFile",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"body",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"subName",
"=>",
"$",
"subData",
")",
"{",
"$",
"body",
".=",
"$",
"this",
"->",
"prepareRawBody",
"(",
"$",
"this",
"->",
"prepareName",
"(",
"$",
"name",
",",
"$",
"subName",
")",
",",
"$",
"subData",
",",
"$",
"isFile",
")",
";",
"}",
"return",
"$",
"body",
";",
"}",
"$",
"body",
"=",
"'--'",
".",
"$",
"this",
"->",
"configuration",
"->",
"getBoundary",
"(",
")",
".",
"\"\\r\\n\"",
".",
"'Content-Disposition: form-data; name=\"'",
".",
"$",
"name",
".",
"'\"'",
";",
"if",
"(",
"$",
"isFile",
")",
"{",
"$",
"body",
".=",
"'; filename=\"'",
".",
"basename",
"(",
"$",
"data",
")",
".",
"'\"'",
";",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"body",
".",
"\"\\r\\n\\r\\n\"",
".",
"$",
"data",
".",
"\"\\r\\n\"",
";",
"}"
] | @param string $name
@param array|string $data
@param bool $isFile
@return string | [
"@param",
"string",
"$name",
"@param",
"array|string",
"$data",
"@param",
"bool",
"$isFile"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/AbstractHttpAdapter.php#L161-L181 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.post | public function post($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_POST, $headers, $datas, $files);
} | php | public function post($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_POST, $headers, $datas, $files);
} | [
"public",
"function",
"post",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"uri",
",",
"InternalRequestInterface",
"::",
"METHOD_POST",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
";",
"}"
] | @param string|object $uri
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L72-L75 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.put | public function put($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_PUT, $headers, $datas, $files);
} | php | public function put($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_PUT, $headers, $datas, $files);
} | [
"public",
"function",
"put",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"uri",
",",
"InternalRequestInterface",
"::",
"METHOD_PUT",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
";",
"}"
] | @param string|object $uri
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L87-L90 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.patch | public function patch($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_PATCH, $headers, $datas, $files);
} | php | public function patch($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_PATCH, $headers, $datas, $files);
} | [
"public",
"function",
"patch",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"uri",
",",
"InternalRequestInterface",
"::",
"METHOD_PATCH",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
";",
"}"
] | @param string|object $uri
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L102-L105 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.delete | public function delete($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_DELETE, $headers, $datas, $files);
} | php | public function delete($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_DELETE, $headers, $datas, $files);
} | [
"public",
"function",
"delete",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"uri",
",",
"InternalRequestInterface",
"::",
"METHOD_DELETE",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
";",
"}"
] | @param string|object $uri
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L117-L120 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.options | public function options($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_OPTIONS, $headers, $datas, $files);
} | php | public function options($uri, array $headers = [], $datas = [], array $files = [])
{
return $this->send($uri, InternalRequestInterface::METHOD_OPTIONS, $headers, $datas, $files);
} | [
"public",
"function",
"options",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"uri",
",",
"InternalRequestInterface",
"::",
"METHOD_OPTIONS",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
";",
"}"
] | @param string|object $uri
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L132-L135 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.send | public function send($uri, $method, array $headers = [], $datas = [], array $files = [])
{
return $this->sendRequest($this->getConfiguration()->getMessageFactory()->createInternalRequest(
$uri,
$method,
$this->getConfiguration()->getProtocolVersion(),
$headers,
$datas,
$files
));
} | php | public function send($uri, $method, array $headers = [], $datas = [], array $files = [])
{
return $this->sendRequest($this->getConfiguration()->getMessageFactory()->createInternalRequest(
$uri,
$method,
$this->getConfiguration()->getProtocolVersion(),
$headers,
$datas,
$files
));
} | [
"public",
"function",
"send",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"datas",
"=",
"[",
"]",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createInternalRequest",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"headers",
",",
"$",
"datas",
",",
"$",
"files",
")",
")",
";",
"}"
] | @param string|object $uri
@param string $method
@param array $headers
@param array|string $datas
@param array $files
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"string|object",
"$uri",
"@param",
"string",
"$method",
"@param",
"array",
"$headers",
"@param",
"array|string",
"$datas",
"@param",
"array",
"$files"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L148-L158 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.sendRequest | public function sendRequest(RequestInterface $request)
{
if ($request instanceof InternalRequestInterface) {
return $this->sendInternalRequest($request);
}
$protocolVersion = $this->getConfiguration()->getProtocolVersion();
$this->getConfiguration()->setProtocolVersion($request->getProtocolVersion());
$response = $this->send(
$request->getUri(),
$request->getMethod(),
$request->getHeaders(),
$request->getBody()
);
$this->getConfiguration()->setProtocolVersion($protocolVersion);
return $response;
} | php | public function sendRequest(RequestInterface $request)
{
if ($request instanceof InternalRequestInterface) {
return $this->sendInternalRequest($request);
}
$protocolVersion = $this->getConfiguration()->getProtocolVersion();
$this->getConfiguration()->setProtocolVersion($request->getProtocolVersion());
$response = $this->send(
$request->getUri(),
$request->getMethod(),
$request->getHeaders(),
$request->getBody()
);
$this->getConfiguration()->setProtocolVersion($protocolVersion);
return $response;
} | [
"public",
"function",
"sendRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"instanceof",
"InternalRequestInterface",
")",
"{",
"return",
"$",
"this",
"->",
"sendInternalRequest",
"(",
"$",
"request",
")",
";",
"}",
"$",
"protocolVersion",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getProtocolVersion",
"(",
")",
";",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"setProtocolVersion",
"(",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"setProtocolVersion",
"(",
"$",
"protocolVersion",
")",
";",
"return",
"$",
"response",
";",
"}"
] | @param RequestInterface $request
@throws HttpAdapterException
@return ResponseInterface | [
"@param",
"RequestInterface",
"$request"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L167-L186 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.sendRequests | public function sendRequests(array $requests)
{
$responses = $exceptions = [];
foreach ($requests as $index => &$request) {
if (is_string($request)) {
$request = [$request];
}
if (is_array($request)) {
$request = call_user_func_array(
[$this->getConfiguration()->getMessageFactory(), 'createInternalRequest'],
$request
);
}
if (!$request instanceof RequestInterface) {
$exceptions[] = HttpAdapterException::requestIsNotValid($request);
unset($requests[$index]);
} elseif (!$request instanceof InternalRequestInterface) {
$request = $this->getConfiguration()->getMessageFactory()->createInternalRequest(
$request->getUri(),
$request->getMethod(),
$request->getProtocolVersion(),
$request->getHeaders(),
$request->getBody()
);
}
}
$success = function (ResponseInterface $response) use (&$responses) {
$responses[] = $response;
};
$error = function (HttpAdapterException $exception) use (&$exceptions) {
$exceptions[] = $exception;
};
$this->sendInternalRequests($requests, $success, $error);
if (!empty($exceptions)) {
throw new MultiHttpAdapterException($exceptions, $responses);
}
return $responses;
} | php | public function sendRequests(array $requests)
{
$responses = $exceptions = [];
foreach ($requests as $index => &$request) {
if (is_string($request)) {
$request = [$request];
}
if (is_array($request)) {
$request = call_user_func_array(
[$this->getConfiguration()->getMessageFactory(), 'createInternalRequest'],
$request
);
}
if (!$request instanceof RequestInterface) {
$exceptions[] = HttpAdapterException::requestIsNotValid($request);
unset($requests[$index]);
} elseif (!$request instanceof InternalRequestInterface) {
$request = $this->getConfiguration()->getMessageFactory()->createInternalRequest(
$request->getUri(),
$request->getMethod(),
$request->getProtocolVersion(),
$request->getHeaders(),
$request->getBody()
);
}
}
$success = function (ResponseInterface $response) use (&$responses) {
$responses[] = $response;
};
$error = function (HttpAdapterException $exception) use (&$exceptions) {
$exceptions[] = $exception;
};
$this->sendInternalRequests($requests, $success, $error);
if (!empty($exceptions)) {
throw new MultiHttpAdapterException($exceptions, $responses);
}
return $responses;
} | [
"public",
"function",
"sendRequests",
"(",
"array",
"$",
"requests",
")",
"{",
"$",
"responses",
"=",
"$",
"exceptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"index",
"=>",
"&",
"$",
"request",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"[",
"$",
"request",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
",",
"'createInternalRequest'",
"]",
",",
"$",
"request",
")",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"instanceof",
"RequestInterface",
")",
"{",
"$",
"exceptions",
"[",
"]",
"=",
"HttpAdapterException",
"::",
"requestIsNotValid",
"(",
"$",
"request",
")",
";",
"unset",
"(",
"$",
"requests",
"[",
"$",
"index",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"request",
"instanceof",
"InternalRequestInterface",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"->",
"getMessageFactory",
"(",
")",
"->",
"createInternalRequest",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"}",
"$",
"success",
"=",
"function",
"(",
"ResponseInterface",
"$",
"response",
")",
"use",
"(",
"&",
"$",
"responses",
")",
"{",
"$",
"responses",
"[",
"]",
"=",
"$",
"response",
";",
"}",
";",
"$",
"error",
"=",
"function",
"(",
"HttpAdapterException",
"$",
"exception",
")",
"use",
"(",
"&",
"$",
"exceptions",
")",
"{",
"$",
"exceptions",
"[",
"]",
"=",
"$",
"exception",
";",
"}",
";",
"$",
"this",
"->",
"sendInternalRequests",
"(",
"$",
"requests",
",",
"$",
"success",
",",
"$",
"error",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"exceptions",
")",
")",
"{",
"throw",
"new",
"MultiHttpAdapterException",
"(",
"$",
"exceptions",
",",
"$",
"responses",
")",
";",
"}",
"return",
"$",
"responses",
";",
"}"
] | @param array $requests
@throws MultiHttpAdapterException
@return array | [
"@param",
"array",
"$requests"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L195-L240 |
egeloen/ivory-http-adapter | src/HttpAdapterTrait.php | HttpAdapterTrait.sendInternalRequests | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
foreach ($internalRequests as $internalRequest) {
try {
$response = $this->sendInternalRequest($internalRequest);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
$e->setResponse(isset($response) ? $response : null);
call_user_func($error, $e);
}
}
} | php | protected function sendInternalRequests(array $internalRequests, $success, $error)
{
foreach ($internalRequests as $internalRequest) {
try {
$response = $this->sendInternalRequest($internalRequest);
$response = $response->withParameter('request', $internalRequest);
call_user_func($success, $response);
} catch (HttpAdapterException $e) {
$e->setRequest($internalRequest);
$e->setResponse(isset($response) ? $response : null);
call_user_func($error, $e);
}
}
} | [
"protected",
"function",
"sendInternalRequests",
"(",
"array",
"$",
"internalRequests",
",",
"$",
"success",
",",
"$",
"error",
")",
"{",
"foreach",
"(",
"$",
"internalRequests",
"as",
"$",
"internalRequest",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"sendInternalRequest",
"(",
"$",
"internalRequest",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withParameter",
"(",
"'request'",
",",
"$",
"internalRequest",
")",
";",
"call_user_func",
"(",
"$",
"success",
",",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"HttpAdapterException",
"$",
"e",
")",
"{",
"$",
"e",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"isset",
"(",
"$",
"response",
")",
"?",
"$",
"response",
":",
"null",
")",
";",
"call_user_func",
"(",
"$",
"error",
",",
"$",
"e",
")",
";",
"}",
"}",
"}"
] | @param array $internalRequests
@param callable $success
@param callable $error
@throws MultiHttpAdapterException
@return array | [
"@param",
"array",
"$internalRequests",
"@param",
"callable",
"$success",
"@param",
"callable",
"$error"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/HttpAdapterTrait.php#L260-L273 |
egeloen/ivory-http-adapter | src/Event/Subscriber/StatusCodeSubscriber.php | StatusCodeSubscriber.createStatusCodeException | private function createStatusCodeException(
ResponseInterface $response,
InternalRequestInterface $internalRequest,
HttpAdapterInterface $httpAdapter
) {
$exception = HttpAdapterException::cannotFetchUri(
(string) $internalRequest->getUri(),
$httpAdapter->getName(),
sprintf('Status code: %d', $response->getStatusCode())
);
$exception->setRequest($internalRequest);
$exception->setResponse($response);
return $exception;
} | php | private function createStatusCodeException(
ResponseInterface $response,
InternalRequestInterface $internalRequest,
HttpAdapterInterface $httpAdapter
) {
$exception = HttpAdapterException::cannotFetchUri(
(string) $internalRequest->getUri(),
$httpAdapter->getName(),
sprintf('Status code: %d', $response->getStatusCode())
);
$exception->setRequest($internalRequest);
$exception->setResponse($response);
return $exception;
} | [
"private",
"function",
"createStatusCodeException",
"(",
"ResponseInterface",
"$",
"response",
",",
"InternalRequestInterface",
"$",
"internalRequest",
",",
"HttpAdapterInterface",
"$",
"httpAdapter",
")",
"{",
"$",
"exception",
"=",
"HttpAdapterException",
"::",
"cannotFetchUri",
"(",
"(",
"string",
")",
"$",
"internalRequest",
"->",
"getUri",
"(",
")",
",",
"$",
"httpAdapter",
"->",
"getName",
"(",
")",
",",
"sprintf",
"(",
"'Status code: %d'",
",",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
")",
";",
"$",
"exception",
"->",
"setRequest",
"(",
"$",
"internalRequest",
")",
";",
"$",
"exception",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"return",
"$",
"exception",
";",
"}"
] | @param ResponseInterface $response
@param InternalRequestInterface $internalRequest
@param HttpAdapterInterface $httpAdapter
@return HttpAdapterException | [
"@param",
"ResponseInterface",
"$response",
"@param",
"InternalRequestInterface",
"$internalRequest",
"@param",
"HttpAdapterInterface",
"$httpAdapter"
] | train | https://github.com/egeloen/ivory-http-adapter/blob/2387f532049d8c6c439e68097abc6f7b33f027a4/src/Event/Subscriber/StatusCodeSubscriber.php#L101-L116 |
multidots/cakephp-rest-api | src/View/ApiView.php | ApiView.render | public function render($view = null, $layout = null)
{
if ($this->hasRendered) {
return null;
}
$this->layout = "RestApi.{$this->_responseLayout}";
$this->Blocks->set('content', $this->renderLayout('', $this->layout));
$this->hasRendered = true;
return $this->Blocks->get('content');
} | php | public function render($view = null, $layout = null)
{
if ($this->hasRendered) {
return null;
}
$this->layout = "RestApi.{$this->_responseLayout}";
$this->Blocks->set('content', $this->renderLayout('', $this->layout));
$this->hasRendered = true;
return $this->Blocks->get('content');
} | [
"public",
"function",
"render",
"(",
"$",
"view",
"=",
"null",
",",
"$",
"layout",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasRendered",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"layout",
"=",
"\"RestApi.{$this->_responseLayout}\"",
";",
"$",
"this",
"->",
"Blocks",
"->",
"set",
"(",
"'content'",
",",
"$",
"this",
"->",
"renderLayout",
"(",
"''",
",",
"$",
"this",
"->",
"layout",
")",
")",
";",
"$",
"this",
"->",
"hasRendered",
"=",
"true",
";",
"return",
"$",
"this",
"->",
"Blocks",
"->",
"get",
"(",
"'content'",
")",
";",
"}"
] | Renders api response
@param string|null $view Name of view file to use
@param string|null $layout Layout to use.
@return string|null Rendered content or null if content already rendered and returned earlier.
@throws Exception If there is an error in the view. | [
"Renders",
"api",
"response"
] | train | https://github.com/multidots/cakephp-rest-api/blob/6c2a73bbe3073c58ade3f24cd015dd58e71ebd50/src/View/ApiView.php#L49-L62 |
multidots/cakephp-rest-api | src/Controller/Component/AccessControlComponent.php | AccessControlComponent._performTokenValidation | protected function _performTokenValidation(Event $event)
{
$request = $event->getSubject()->request;
if (!empty($request->getParam('allowWithoutToken')) && $request->getParam('allowWithoutToken')) {
return true;
}
$token = '';
$header = $request->getHeader('Authorization');
if (!empty($header[0])) {
$parts = explode(' ', $header[0]);
if (count($parts) < 2 || empty($parts[0]) || !preg_match('/^Bearer$/i', $parts[0])) {
throw new InvalidTokenFormatException();
}
$token = $parts[1];
} elseif (!empty($this->request->getQuery('token'))) {
$token = $this->request->getQuery('token');
} elseif (!empty($request->getParam('token'))) {
$token = $request->getParam('token');
} else {
throw new MissingTokenException();
}
try {
$payload = JWT::decode($token, Configure::read('ApiRequest.jwtAuth.cypherKey'), [Configure::read('ApiRequest.jwtAuth.tokenAlgorithm')]);
} catch (\Exception $e) {
throw new InvalidTokenException();
}
if (empty($payload)) {
throw new InvalidTokenException();
}
$controller = $this->_registry->getController();
$controller->jwtPayload = $payload;
$controller->jwtToken = $token;
Configure::write('accessToken', $token);
return true;
} | php | protected function _performTokenValidation(Event $event)
{
$request = $event->getSubject()->request;
if (!empty($request->getParam('allowWithoutToken')) && $request->getParam('allowWithoutToken')) {
return true;
}
$token = '';
$header = $request->getHeader('Authorization');
if (!empty($header[0])) {
$parts = explode(' ', $header[0]);
if (count($parts) < 2 || empty($parts[0]) || !preg_match('/^Bearer$/i', $parts[0])) {
throw new InvalidTokenFormatException();
}
$token = $parts[1];
} elseif (!empty($this->request->getQuery('token'))) {
$token = $this->request->getQuery('token');
} elseif (!empty($request->getParam('token'))) {
$token = $request->getParam('token');
} else {
throw new MissingTokenException();
}
try {
$payload = JWT::decode($token, Configure::read('ApiRequest.jwtAuth.cypherKey'), [Configure::read('ApiRequest.jwtAuth.tokenAlgorithm')]);
} catch (\Exception $e) {
throw new InvalidTokenException();
}
if (empty($payload)) {
throw new InvalidTokenException();
}
$controller = $this->_registry->getController();
$controller->jwtPayload = $payload;
$controller->jwtToken = $token;
Configure::write('accessToken', $token);
return true;
} | [
"protected",
"function",
"_performTokenValidation",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"request",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'allowWithoutToken'",
")",
")",
"&&",
"$",
"request",
"->",
"getParam",
"(",
"'allowWithoutToken'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"token",
"=",
"''",
";",
"$",
"header",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Authorization'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"header",
"[",
"0",
"]",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"header",
"[",
"0",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"<",
"2",
"||",
"empty",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"||",
"!",
"preg_match",
"(",
"'/^Bearer$/i'",
",",
"$",
"parts",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidTokenFormatException",
"(",
")",
";",
"}",
"$",
"token",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"request",
"->",
"getQuery",
"(",
"'token'",
")",
")",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"request",
"->",
"getQuery",
"(",
"'token'",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'token'",
")",
")",
")",
"{",
"$",
"token",
"=",
"$",
"request",
"->",
"getParam",
"(",
"'token'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"MissingTokenException",
"(",
")",
";",
"}",
"try",
"{",
"$",
"payload",
"=",
"JWT",
"::",
"decode",
"(",
"$",
"token",
",",
"Configure",
"::",
"read",
"(",
"'ApiRequest.jwtAuth.cypherKey'",
")",
",",
"[",
"Configure",
"::",
"read",
"(",
"'ApiRequest.jwtAuth.tokenAlgorithm'",
")",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidTokenException",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"payload",
")",
")",
"{",
"throw",
"new",
"InvalidTokenException",
"(",
")",
";",
"}",
"$",
"controller",
"=",
"$",
"this",
"->",
"_registry",
"->",
"getController",
"(",
")",
";",
"$",
"controller",
"->",
"jwtPayload",
"=",
"$",
"payload",
";",
"$",
"controller",
"->",
"jwtToken",
"=",
"$",
"token",
";",
"Configure",
"::",
"write",
"(",
"'accessToken'",
",",
"$",
"token",
")",
";",
"return",
"true",
";",
"}"
] | Performs token validation.
@param Event $event The startup event
@return bool
@throws UnauthorizedException If missing or invalid token | [
"Performs",
"token",
"validation",
"."
] | train | https://github.com/multidots/cakephp-rest-api/blob/6c2a73bbe3073c58ade3f24cd015dd58e71ebd50/src/Controller/Component/AccessControlComponent.php#L47-L94 |
multidots/cakephp-rest-api | src/Event/ApiRequestHandler.php | ApiRequestHandler.beforeDispatch | public function beforeDispatch(Event $event)
{
$this->buildResponse($event);
Configure::write('requestLogged', false);
$request = $event->getData()['request'];
if ('OPTIONS' === $request->getMethod()) {
$event->stopPropagation();
$response = $event->getData()['response'];
$response->getStatusCode(200);
return $response;
}
if (empty($request->getData())) {
// $request->data = $request->input('json_decode', true);
}
} | php | public function beforeDispatch(Event $event)
{
$this->buildResponse($event);
Configure::write('requestLogged', false);
$request = $event->getData()['request'];
if ('OPTIONS' === $request->getMethod()) {
$event->stopPropagation();
$response = $event->getData()['response'];
$response->getStatusCode(200);
return $response;
}
if (empty($request->getData())) {
// $request->data = $request->input('json_decode', true);
}
} | [
"public",
"function",
"beforeDispatch",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"buildResponse",
"(",
"$",
"event",
")",
";",
"Configure",
"::",
"write",
"(",
"'requestLogged'",
",",
"false",
")",
";",
"$",
"request",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
"[",
"'request'",
"]",
";",
"if",
"(",
"'OPTIONS'",
"===",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
"[",
"'response'",
"]",
";",
"$",
"response",
"->",
"getStatusCode",
"(",
"200",
")",
";",
"return",
"$",
"response",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"request",
"->",
"getData",
"(",
")",
")",
")",
"{",
"// $request->data = $request->input('json_decode', true);",
"}",
"}"
] | Handles incoming request and its data.
@param Event $event The beforeDispatch event | [
"Handles",
"incoming",
"request",
"and",
"its",
"data",
"."
] | train | https://github.com/multidots/cakephp-rest-api/blob/6c2a73bbe3073c58ade3f24cd015dd58e71ebd50/src/Event/ApiRequestHandler.php#L46-L62 |
multidots/cakephp-rest-api | src/Event/ApiRequestHandler.php | ApiRequestHandler.shutdown | public function shutdown(Event $event)
{
$request = $event->getSubject()->request;
if ('OPTIONS' === $request->getMethod()) {
return;
}
if (!Configure::read('requestLogged') && Configure::read('ApiRequest.log')) {
if (Configure::read('ApiRequest.logOnlyErrors')) {
$responseCode = $event->getSubject()->httpStatusCode;
$logOnlyErrorCodes = Configure::read('ApiRequest.logOnlyErrorCodes');
if (empty($logOnlyErrorCodes) && $responseCode !== 200) {
ApiRequestLogger::log($request, $event->getSubject()->response);
} elseif (in_array($responseCode, $logOnlyErrorCodes)) {
ApiRequestLogger::log($request, $event->getSubject()->response);
}
} else {
ApiRequestLogger::log($request, $event->getSubject()->response);
}
}
} | php | public function shutdown(Event $event)
{
$request = $event->getSubject()->request;
if ('OPTIONS' === $request->getMethod()) {
return;
}
if (!Configure::read('requestLogged') && Configure::read('ApiRequest.log')) {
if (Configure::read('ApiRequest.logOnlyErrors')) {
$responseCode = $event->getSubject()->httpStatusCode;
$logOnlyErrorCodes = Configure::read('ApiRequest.logOnlyErrorCodes');
if (empty($logOnlyErrorCodes) && $responseCode !== 200) {
ApiRequestLogger::log($request, $event->getSubject()->response);
} elseif (in_array($responseCode, $logOnlyErrorCodes)) {
ApiRequestLogger::log($request, $event->getSubject()->response);
}
} else {
ApiRequestLogger::log($request, $event->getSubject()->response);
}
}
} | [
"public",
"function",
"shutdown",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"request",
";",
"if",
"(",
"'OPTIONS'",
"===",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"Configure",
"::",
"read",
"(",
"'requestLogged'",
")",
"&&",
"Configure",
"::",
"read",
"(",
"'ApiRequest.log'",
")",
")",
"{",
"if",
"(",
"Configure",
"::",
"read",
"(",
"'ApiRequest.logOnlyErrors'",
")",
")",
"{",
"$",
"responseCode",
"=",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"httpStatusCode",
";",
"$",
"logOnlyErrorCodes",
"=",
"Configure",
"::",
"read",
"(",
"'ApiRequest.logOnlyErrorCodes'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"logOnlyErrorCodes",
")",
"&&",
"$",
"responseCode",
"!==",
"200",
")",
"{",
"ApiRequestLogger",
"::",
"log",
"(",
"$",
"request",
",",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"response",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"responseCode",
",",
"$",
"logOnlyErrorCodes",
")",
")",
"{",
"ApiRequestLogger",
"::",
"log",
"(",
"$",
"request",
",",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"response",
")",
";",
"}",
"}",
"else",
"{",
"ApiRequestLogger",
"::",
"log",
"(",
"$",
"request",
",",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"response",
")",
";",
"}",
"}",
"}"
] | Logs the request and response data into database.
@param Event $event The shutdown event | [
"Logs",
"the",
"request",
"and",
"response",
"data",
"into",
"database",
"."
] | train | https://github.com/multidots/cakephp-rest-api/blob/6c2a73bbe3073c58ade3f24cd015dd58e71ebd50/src/Event/ApiRequestHandler.php#L79-L99 |
multidots/cakephp-rest-api | src/Event/ApiRequestHandler.php | ApiRequestHandler.buildResponse | private function buildResponse(Event $event)
{
$request = $event->getData()['request'];
$response = $event->getData()['response'];
if ('xml' === Configure::read('ApiRequest.responseType')) {
$response->withType('xml');
} else {
$response->withType('json');
}
$response->cors($request)
->allowOrigin(Configure::read('ApiRequest.cors.origin'))
->allowMethods(Configure::read('ApiRequest.cors.allowedMethods'))
->allowHeaders(Configure::read('ApiRequest.cors.allowedHeaders'))
->allowCredentials()
->maxAge(Configure::read('ApiRequest.cors.maxAge'))
->build();
return true;
} | php | private function buildResponse(Event $event)
{
$request = $event->getData()['request'];
$response = $event->getData()['response'];
if ('xml' === Configure::read('ApiRequest.responseType')) {
$response->withType('xml');
} else {
$response->withType('json');
}
$response->cors($request)
->allowOrigin(Configure::read('ApiRequest.cors.origin'))
->allowMethods(Configure::read('ApiRequest.cors.allowedMethods'))
->allowHeaders(Configure::read('ApiRequest.cors.allowedHeaders'))
->allowCredentials()
->maxAge(Configure::read('ApiRequest.cors.maxAge'))
->build();
return true;
} | [
"private",
"function",
"buildResponse",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
"[",
"'request'",
"]",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
"[",
"'response'",
"]",
";",
"if",
"(",
"'xml'",
"===",
"Configure",
"::",
"read",
"(",
"'ApiRequest.responseType'",
")",
")",
"{",
"$",
"response",
"->",
"withType",
"(",
"'xml'",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"withType",
"(",
"'json'",
")",
";",
"}",
"$",
"response",
"->",
"cors",
"(",
"$",
"request",
")",
"->",
"allowOrigin",
"(",
"Configure",
"::",
"read",
"(",
"'ApiRequest.cors.origin'",
")",
")",
"->",
"allowMethods",
"(",
"Configure",
"::",
"read",
"(",
"'ApiRequest.cors.allowedMethods'",
")",
")",
"->",
"allowHeaders",
"(",
"Configure",
"::",
"read",
"(",
"'ApiRequest.cors.allowedHeaders'",
")",
")",
"->",
"allowCredentials",
"(",
")",
"->",
"maxAge",
"(",
"Configure",
"::",
"read",
"(",
"'ApiRequest.cors.maxAge'",
")",
")",
"->",
"build",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Prepares the response object with content type and cors headers.
@param Event $event The event object either beforeDispatch or afterDispatch
@return bool true | [
"Prepares",
"the",
"response",
"object",
"with",
"content",
"type",
"and",
"cors",
"headers",
"."
] | train | https://github.com/multidots/cakephp-rest-api/blob/6c2a73bbe3073c58ade3f24cd015dd58e71ebd50/src/Event/ApiRequestHandler.php#L108-L128 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.