repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.fromMessage | public static function fromMessage($message)
{
$data = ParserRegistry::getInstance()->getParser('message')->parseResponse($message);
if (!$data) {
return false;
}
$response = new static($data['code'], $data['headers'], $data['body']);
$response->setProtocol($data['protocol'], $data['version'])
->setStatus($data['code'], $data['reason_phrase']);
// Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X)
$contentLength = (string) $response->getHeader('Content-Length');
$actualLength = strlen($data['body']);
if (strlen($data['body']) > 0 && $contentLength != $actualLength) {
$response->setHeader('Content-Length', $actualLength);
}
return $response;
} | php | public static function fromMessage($message)
{
$data = ParserRegistry::getInstance()->getParser('message')->parseResponse($message);
if (!$data) {
return false;
}
$response = new static($data['code'], $data['headers'], $data['body']);
$response->setProtocol($data['protocol'], $data['version'])
->setStatus($data['code'], $data['reason_phrase']);
// Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X)
$contentLength = (string) $response->getHeader('Content-Length');
$actualLength = strlen($data['body']);
if (strlen($data['body']) > 0 && $contentLength != $actualLength) {
$response->setHeader('Content-Length', $actualLength);
}
return $response;
} | [
"public",
"static",
"function",
"fromMessage",
"(",
"$",
"message",
")",
"{",
"$",
"data",
"=",
"ParserRegistry",
"::",
"getInstance",
"(",
")",
"->",
"getParser",
"(",
"'message'",
")",
"->",
"parseResponse",
"(",
"$",
"message",
")",
";",
"if",
"(",
"!... | Create a new Response based on a raw response message
@param string $message Response message
@return self|bool Returns false on error | [
"Create",
"a",
"new",
"Response",
"based",
"on",
"a",
"raw",
"response",
"message"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L108-L127 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.setProtocol | public function setProtocol($protocol, $version)
{
$this->protocol = $protocol;
$this->protocolVersion = $version;
return $this;
} | php | public function setProtocol($protocol, $version)
{
$this->protocol = $protocol;
$this->protocolVersion = $version;
return $this;
} | [
"public",
"function",
"setProtocol",
"(",
"$",
"protocol",
",",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"protocol",
"=",
"$",
"protocol",
";",
"$",
"this",
"->",
"protocolVersion",
"=",
"$",
"version",
";",
"return",
"$",
"this",
";",
"}"
] | Set the protocol and protocol version of the response
@param string $protocol Response protocol
@param string $version Protocol version
@return self | [
"Set",
"the",
"protocol",
"and",
"protocol",
"version",
"of",
"the",
"response"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L212-L218 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.getInfo | public function getInfo($key = null)
{
if ($key === null) {
return $this->info;
} elseif (array_key_exists($key, $this->info)) {
return $this->info[$key];
} else {
return null;
}
} | php | public function getInfo($key = null)
{
if ($key === null) {
return $this->info;
} elseif (array_key_exists($key, $this->info)) {
return $this->info[$key];
} else {
return null;
}
} | [
"public",
"function",
"getInfo",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"info",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"i... | Get a cURL transfer information
@param string $key A single statistic to check
@return array|string|null Returns all stats if no key is set, a single stat if a key is set, or null if a key
is set and not found
@link http://www.php.net/manual/en/function.curl-getinfo.php | [
"Get",
"a",
"cURL",
"transfer",
"information"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L249-L258 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.setStatus | public function setStatus($statusCode, $reasonPhrase = '')
{
$this->statusCode = (int) $statusCode;
if (!$reasonPhrase && isset(self::$statusTexts[$this->statusCode])) {
$this->reasonPhrase = self::$statusTexts[$this->statusCode];
} else {
$this->reasonPhrase = $reasonPhrase;
}
return $this;
} | php | public function setStatus($statusCode, $reasonPhrase = '')
{
$this->statusCode = (int) $statusCode;
if (!$reasonPhrase && isset(self::$statusTexts[$this->statusCode])) {
$this->reasonPhrase = self::$statusTexts[$this->statusCode];
} else {
$this->reasonPhrase = $reasonPhrase;
}
return $this;
} | [
"public",
"function",
"setStatus",
"(",
"$",
"statusCode",
",",
"$",
"reasonPhrase",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"statusCode",
"=",
"(",
"int",
")",
"$",
"statusCode",
";",
"if",
"(",
"!",
"$",
"reasonPhrase",
"&&",
"isset",
"(",
"self",
... | Set the response status
@param int $statusCode Response status code to set
@param string $reasonPhrase Response reason phrase
@return self
@throws BadResponseException when an invalid response code is received | [
"Set",
"the",
"response",
"status"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L283-L294 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.getMessage | public function getMessage()
{
$message = $this->getRawHeaders();
// Only include the body in the message if the size is < 2MB
$size = $this->body->getSize();
if ($size < 2097152) {
$message .= (string) $this->body;
}
return $message;
} | php | public function getMessage()
{
$message = $this->getRawHeaders();
// Only include the body in the message if the size is < 2MB
$size = $this->body->getSize();
if ($size < 2097152) {
$message .= (string) $this->body;
}
return $message;
} | [
"public",
"function",
"getMessage",
"(",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getRawHeaders",
"(",
")",
";",
"// Only include the body in the message if the size is < 2MB",
"$",
"size",
"=",
"$",
"this",
"->",
"body",
"->",
"getSize",
"(",
")",
"... | Get the entire response as a string
@return string | [
"Get",
"the",
"entire",
"response",
"as",
"a",
"string"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L311-L322 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.getRawHeaders | public function getRawHeaders()
{
$headers = 'HTTP/1.1 ' . $this->statusCode . ' ' . $this->reasonPhrase . "\r\n";
$lines = $this->getHeaderLines();
if (!empty($lines)) {
$headers .= implode("\r\n", $lines) . "\r\n";
}
return $headers . "\r\n";
} | php | public function getRawHeaders()
{
$headers = 'HTTP/1.1 ' . $this->statusCode . ' ' . $this->reasonPhrase . "\r\n";
$lines = $this->getHeaderLines();
if (!empty($lines)) {
$headers .= implode("\r\n", $lines) . "\r\n";
}
return $headers . "\r\n";
} | [
"public",
"function",
"getRawHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"'HTTP/1.1 '",
".",
"$",
"this",
"->",
"statusCode",
".",
"' '",
".",
"$",
"this",
"->",
"reasonPhrase",
".",
"\"\\r\\n\"",
";",
"$",
"lines",
"=",
"$",
"this",
"->",
"getHeaderLi... | Get the the raw message headers as a string
@return string | [
"Get",
"the",
"the",
"raw",
"message",
"headers",
"as",
"a",
"string"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L329-L338 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.calculateAge | public function calculateAge()
{
$age = $this->getHeader('Age');
if ($age === null && $this->getDate()) {
$age = time() - strtotime($this->getDate());
}
return $age === null ? null : (int) (string) $age;
} | php | public function calculateAge()
{
$age = $this->getHeader('Age');
if ($age === null && $this->getDate()) {
$age = time() - strtotime($this->getDate());
}
return $age === null ? null : (int) (string) $age;
} | [
"public",
"function",
"calculateAge",
"(",
")",
"{",
"$",
"age",
"=",
"$",
"this",
"->",
"getHeader",
"(",
"'Age'",
")",
";",
"if",
"(",
"$",
"age",
"===",
"null",
"&&",
"$",
"this",
"->",
"getDate",
"(",
")",
")",
"{",
"$",
"age",
"=",
"time",
... | Calculate the age of the response
@return integer | [
"Calculate",
"the",
"age",
"of",
"the",
"response"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L366-L375 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.isMethodAllowed | public function isMethodAllowed($method)
{
$allow = $this->getHeader('Allow');
if ($allow) {
foreach (explode(',', $allow) as $allowable) {
if (!strcasecmp(trim($allowable), $method)) {
return true;
}
}
}
return false;
} | php | public function isMethodAllowed($method)
{
$allow = $this->getHeader('Allow');
if ($allow) {
foreach (explode(',', $allow) as $allowable) {
if (!strcasecmp(trim($allowable), $method)) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"isMethodAllowed",
"(",
"$",
"method",
")",
"{",
"$",
"allow",
"=",
"$",
"this",
"->",
"getHeader",
"(",
"'Allow'",
")",
";",
"if",
"(",
"$",
"allow",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"allow",
")",
"a... | Check if an HTTP method is allowed by checking the Allow response header
@param string $method Method to check
@return bool | [
"Check",
"if",
"an",
"HTTP",
"method",
"is",
"allowed",
"by",
"checking",
"the",
"Allow",
"response",
"header"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L404-L416 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.canCache | public function canCache()
{
// Check if the response is cacheable based on the code
if (!in_array((int) $this->getStatusCode(), self::$cacheResponseCodes)) {
return false;
}
// Make sure a valid body was returned and can be cached
if ((!$this->getBody()->isReadable() || !$this->getBody()->isSeekable())
&& ($this->getContentLength() > 0 || $this->getTransferEncoding() == 'chunked')) {
return false;
}
// Never cache no-store resources (this is a private cache, so private
// can be cached)
if ($this->getHeader('Cache-Control') && $this->getHeader('Cache-Control')->hasDirective('no-store')) {
return false;
}
return $this->isFresh() || $this->getFreshness() === null || $this->canValidate();
} | php | public function canCache()
{
// Check if the response is cacheable based on the code
if (!in_array((int) $this->getStatusCode(), self::$cacheResponseCodes)) {
return false;
}
// Make sure a valid body was returned and can be cached
if ((!$this->getBody()->isReadable() || !$this->getBody()->isSeekable())
&& ($this->getContentLength() > 0 || $this->getTransferEncoding() == 'chunked')) {
return false;
}
// Never cache no-store resources (this is a private cache, so private
// can be cached)
if ($this->getHeader('Cache-Control') && $this->getHeader('Cache-Control')->hasDirective('no-store')) {
return false;
}
return $this->isFresh() || $this->getFreshness() === null || $this->canValidate();
} | [
"public",
"function",
"canCache",
"(",
")",
"{",
"// Check if the response is cacheable based on the code",
"if",
"(",
"!",
"in_array",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"self",
"::",
"$",
"cacheResponseCodes",
")",
")",
... | Check if the response can be cached based on the response headers
@return bool Returns TRUE if the response can be cached or false if not | [
"Check",
"if",
"the",
"response",
"can",
"be",
"cached",
"based",
"on",
"the",
"response",
"headers"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L762-L782 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.getMaxAge | public function getMaxAge()
{
if ($header = $this->getHeader('Cache-Control')) {
// s-max-age, then max-age, then Expires
if ($age = $header->getDirective('s-maxage')) {
return $age;
}
if ($age = $header->getDirective('max-age')) {
return $age;
}
}
if ($this->getHeader('Expires')) {
return strtotime($this->getExpires()) - time();
}
return null;
} | php | public function getMaxAge()
{
if ($header = $this->getHeader('Cache-Control')) {
// s-max-age, then max-age, then Expires
if ($age = $header->getDirective('s-maxage')) {
return $age;
}
if ($age = $header->getDirective('max-age')) {
return $age;
}
}
if ($this->getHeader('Expires')) {
return strtotime($this->getExpires()) - time();
}
return null;
} | [
"public",
"function",
"getMaxAge",
"(",
")",
"{",
"if",
"(",
"$",
"header",
"=",
"$",
"this",
"->",
"getHeader",
"(",
"'Cache-Control'",
")",
")",
"{",
"// s-max-age, then max-age, then Expires",
"if",
"(",
"$",
"age",
"=",
"$",
"header",
"->",
"getDirective... | Gets the number of seconds from the current time in which this response is still considered fresh
@return int|null Returns the number of seconds | [
"Gets",
"the",
"number",
"of",
"seconds",
"from",
"the",
"current",
"time",
"in",
"which",
"this",
"response",
"is",
"still",
"considered",
"fresh"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L789-L806 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.json | public function json()
{
$data = json_decode((string) $this->body, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
}
return $data === null ? array() : $data;
} | php | public function json()
{
$data = json_decode((string) $this->body, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
}
return $data === null ? array() : $data;
} | [
"public",
"function",
"json",
"(",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"body",
",",
"true",
")",
";",
"if",
"(",
"JSON_ERROR_NONE",
"!==",
"json_last_error",
"(",
")",
")",
"{",
"throw",
"new",
"Runt... | Parse the JSON response body and return an array
@return array|string|int|bool|float
@throws RuntimeException if the response body is not in JSON format | [
"Parse",
"the",
"JSON",
"response",
"body",
"and",
"return",
"an",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L857-L865 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Response.php | Response.xml | public function xml()
{
$errorMessage = null;
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
libxml_clear_errors();
try {
$xml = new \SimpleXMLElement((string) $this->body ?: '<root />', LIBXML_NONET);
if ($error = libxml_get_last_error()) {
$errorMessage = $error->message;
}
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
}
libxml_clear_errors();
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if ($errorMessage) {
throw new RuntimeException('Unable to parse response body into XML: ' . $errorMessage);
}
return $xml;
} | php | public function xml()
{
$errorMessage = null;
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
libxml_clear_errors();
try {
$xml = new \SimpleXMLElement((string) $this->body ?: '<root />', LIBXML_NONET);
if ($error = libxml_get_last_error()) {
$errorMessage = $error->message;
}
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
}
libxml_clear_errors();
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if ($errorMessage) {
throw new RuntimeException('Unable to parse response body into XML: ' . $errorMessage);
}
return $xml;
} | [
"public",
"function",
"xml",
"(",
")",
"{",
"$",
"errorMessage",
"=",
"null",
";",
"$",
"internalErrors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"disableEntities",
"=",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"libxml_clear_... | Parse the XML response body and return a \SimpleXMLElement.
In order to prevent XXE attacks, this method disables loading external
entities. If you rely on external entities, then you must parse the
XML response manually by accessing the response body directly.
@return \SimpleXMLElement
@throws RuntimeException if the response body is not in XML format
@link http://websec.io/2012/08/27/Preventing-XXE-in-PHP.html | [
"Parse",
"the",
"XML",
"response",
"body",
"and",
"return",
"a",
"\\",
"SimpleXMLElement",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Response.php#L878-L903 | train |
guzzle/guzzle3 | src/Guzzle/Http/EntityBody.php | EntityBody.factory | public static function factory($resource = '', $size = null)
{
if ($resource instanceof EntityBodyInterface) {
return $resource;
}
switch (gettype($resource)) {
case 'string':
return self::fromString($resource);
case 'resource':
return new static($resource, $size);
case 'object':
if (method_exists($resource, '__toString')) {
return self::fromString((string) $resource);
}
break;
case 'array':
return self::fromString(http_build_query($resource));
}
throw new InvalidArgumentException('Invalid resource type');
} | php | public static function factory($resource = '', $size = null)
{
if ($resource instanceof EntityBodyInterface) {
return $resource;
}
switch (gettype($resource)) {
case 'string':
return self::fromString($resource);
case 'resource':
return new static($resource, $size);
case 'object':
if (method_exists($resource, '__toString')) {
return self::fromString((string) $resource);
}
break;
case 'array':
return self::fromString(http_build_query($resource));
}
throw new InvalidArgumentException('Invalid resource type');
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"resource",
"=",
"''",
",",
"$",
"size",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"resource",
"instanceof",
"EntityBodyInterface",
")",
"{",
"return",
"$",
"resource",
";",
"}",
"switch",
"(",
"gettype",... | Create a new EntityBody based on the input type
@param resource|string|EntityBody $resource Entity body data
@param int $size Size of the data contained in the resource
@return EntityBody
@throws InvalidArgumentException if the $resource arg is not a resource or string | [
"Create",
"a",
"new",
"EntityBody",
"based",
"on",
"the",
"input",
"type"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/EntityBody.php#L30-L51 | train |
guzzle/guzzle3 | src/Guzzle/Http/EntityBody.php | EntityBody.fromString | public static function fromString($string)
{
$stream = fopen('php://temp', 'r+');
if ($string !== '') {
fwrite($stream, $string);
rewind($stream);
}
return new static($stream);
} | php | public static function fromString($string)
{
$stream = fopen('php://temp', 'r+');
if ($string !== '') {
fwrite($stream, $string);
rewind($stream);
}
return new static($stream);
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"string",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'r+'",
")",
";",
"if",
"(",
"$",
"string",
"!==",
"''",
")",
"{",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"string",
... | Create a new EntityBody from a string
@param string $string String of data
@return EntityBody | [
"Create",
"a",
"new",
"EntityBody",
"from",
"a",
"string"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/EntityBody.php#L76-L85 | train |
guzzle/guzzle3 | src/Guzzle/Http/EntityBody.php | EntityBody.calculateMd5 | public static function calculateMd5(EntityBodyInterface $body, $rawOutput = false, $base64Encode = false)
{
Version::warn(__CLASS__ . ' is deprecated. Use getContentMd5()');
return $body->getContentMd5($rawOutput, $base64Encode);
} | php | public static function calculateMd5(EntityBodyInterface $body, $rawOutput = false, $base64Encode = false)
{
Version::warn(__CLASS__ . ' is deprecated. Use getContentMd5()');
return $body->getContentMd5($rawOutput, $base64Encode);
} | [
"public",
"static",
"function",
"calculateMd5",
"(",
"EntityBodyInterface",
"$",
"body",
",",
"$",
"rawOutput",
"=",
"false",
",",
"$",
"base64Encode",
"=",
"false",
")",
"{",
"Version",
"::",
"warn",
"(",
"__CLASS__",
".",
"' is deprecated. Use getContentMd5()'",... | Calculate the MD5 hash of an entity body
@param EntityBodyInterface $body Entity body to calculate the hash for
@param bool $rawOutput Whether or not to use raw output
@param bool $base64Encode Whether or not to base64 encode raw output (only if raw output is true)
@return bool|string Returns an MD5 string on success or FALSE on failure
@deprecated This will be deprecated soon
@codeCoverageIgnore | [
"Calculate",
"the",
"MD5",
"hash",
"of",
"an",
"entity",
"body"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/EntityBody.php#L147-L151 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.setContextValue | protected function setContextValue($wrapper, $name, $value, $overwrite = false)
{
if (!isset($this->contextOptions[$wrapper])) {
$this->contextOptions[$wrapper] = array($name => $value);
} elseif (!$overwrite && isset($this->contextOptions[$wrapper][$name])) {
return;
}
$this->contextOptions[$wrapper][$name] = $value;
stream_context_set_option($this->context, $wrapper, $name, $value);
} | php | protected function setContextValue($wrapper, $name, $value, $overwrite = false)
{
if (!isset($this->contextOptions[$wrapper])) {
$this->contextOptions[$wrapper] = array($name => $value);
} elseif (!$overwrite && isset($this->contextOptions[$wrapper][$name])) {
return;
}
$this->contextOptions[$wrapper][$name] = $value;
stream_context_set_option($this->context, $wrapper, $name, $value);
} | [
"protected",
"function",
"setContextValue",
"(",
"$",
"wrapper",
",",
"$",
"name",
",",
"$",
"value",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"contextOptions",
"[",
"$",
"wrapper",
"]",
")",
")"... | Set an option on the context and the internal options array
@param string $wrapper Stream wrapper name of http
@param string $name Context name
@param mixed $value Context value
@param bool $overwrite Set to true to overwrite an existing value | [
"Set",
"an",
"option",
"on",
"the",
"context",
"and",
"the",
"internal",
"options",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L75-L84 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.createContext | protected function createContext(array $params)
{
$options = $this->contextOptions;
$this->context = $this->createResource(function () use ($params, $options) {
return stream_context_create($options, $params);
});
} | php | protected function createContext(array $params)
{
$options = $this->contextOptions;
$this->context = $this->createResource(function () use ($params, $options) {
return stream_context_create($options, $params);
});
} | [
"protected",
"function",
"createContext",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"contextOptions",
";",
"$",
"this",
"->",
"context",
"=",
"$",
"this",
"->",
"createResource",
"(",
"function",
"(",
")",
"use",
"(",... | Create a stream context
@param array $params Parameter array | [
"Create",
"a",
"stream",
"context"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L91-L97 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.setUrl | protected function setUrl(RequestInterface $request)
{
$this->url = $request->getUrl(true);
// Check for basic Auth username
if ($request->getUsername()) {
$this->url->setUsername($request->getUsername());
}
// Check for basic Auth password
if ($request->getPassword()) {
$this->url->setPassword($request->getPassword());
}
} | php | protected function setUrl(RequestInterface $request)
{
$this->url = $request->getUrl(true);
// Check for basic Auth username
if ($request->getUsername()) {
$this->url->setUsername($request->getUsername());
}
// Check for basic Auth password
if ($request->getPassword()) {
$this->url->setPassword($request->getPassword());
}
} | [
"protected",
"function",
"setUrl",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"request",
"->",
"getUrl",
"(",
"true",
")",
";",
"// Check for basic Auth username",
"if",
"(",
"$",
"request",
"->",
"getUsername",
"(... | Set the URL to use with the factory
@param RequestInterface $request Request that owns the URL | [
"Set",
"the",
"URL",
"to",
"use",
"with",
"the",
"factory"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L134-L147 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.addSslOptions | protected function addSslOptions(RequestInterface $request)
{
if ($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER)) {
$this->setContextValue('ssl', 'verify_peer', true, true);
if ($cafile = $request->getCurlOptions()->get(CURLOPT_CAINFO)) {
$this->setContextValue('ssl', 'cafile', $cafile, true);
}
} else {
$this->setContextValue('ssl', 'verify_peer', false, true);
}
} | php | protected function addSslOptions(RequestInterface $request)
{
if ($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER)) {
$this->setContextValue('ssl', 'verify_peer', true, true);
if ($cafile = $request->getCurlOptions()->get(CURLOPT_CAINFO)) {
$this->setContextValue('ssl', 'cafile', $cafile, true);
}
} else {
$this->setContextValue('ssl', 'verify_peer', false, true);
}
} | [
"protected",
"function",
"addSslOptions",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"getCurlOptions",
"(",
")",
"->",
"get",
"(",
"CURLOPT_SSL_VERIFYPEER",
")",
")",
"{",
"$",
"this",
"->",
"setContextValue",
"(",
"'... | Add SSL options to the stream context
@param RequestInterface $request Request | [
"Add",
"SSL",
"options",
"to",
"the",
"stream",
"context"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L154-L164 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.addProxyOptions | protected function addProxyOptions(RequestInterface $request)
{
if ($proxy = $request->getCurlOptions()->get(CURLOPT_PROXY)) {
$this->setContextValue('http', 'proxy', $proxy);
}
} | php | protected function addProxyOptions(RequestInterface $request)
{
if ($proxy = $request->getCurlOptions()->get(CURLOPT_PROXY)) {
$this->setContextValue('http', 'proxy', $proxy);
}
} | [
"protected",
"function",
"addProxyOptions",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"proxy",
"=",
"$",
"request",
"->",
"getCurlOptions",
"(",
")",
"->",
"get",
"(",
"CURLOPT_PROXY",
")",
")",
"{",
"$",
"this",
"->",
"setContextV... | Add proxy parameters to the context if needed
@param RequestInterface $request Request | [
"Add",
"proxy",
"parameters",
"to",
"the",
"context",
"if",
"needed"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L197-L202 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.createStream | protected function createStream(array $params)
{
$http_response_header = null;
$url = $this->url;
$context = $this->context;
$fp = $this->createResource(function () use ($context, $url, &$http_response_header) {
return fopen((string) $url, 'r', false, $context);
});
// Determine the class to instantiate
$className = isset($params['stream_class']) ? $params['stream_class'] : __NAMESPACE__ . '\\Stream';
/** @var $stream StreamInterface */
$stream = new $className($fp);
// Track the response headers of the request
if (isset($http_response_header)) {
$this->lastResponseHeaders = $http_response_header;
$this->processResponseHeaders($stream);
}
return $stream;
} | php | protected function createStream(array $params)
{
$http_response_header = null;
$url = $this->url;
$context = $this->context;
$fp = $this->createResource(function () use ($context, $url, &$http_response_header) {
return fopen((string) $url, 'r', false, $context);
});
// Determine the class to instantiate
$className = isset($params['stream_class']) ? $params['stream_class'] : __NAMESPACE__ . '\\Stream';
/** @var $stream StreamInterface */
$stream = new $className($fp);
// Track the response headers of the request
if (isset($http_response_header)) {
$this->lastResponseHeaders = $http_response_header;
$this->processResponseHeaders($stream);
}
return $stream;
} | [
"protected",
"function",
"createStream",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"http_response_header",
"=",
"null",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"context",
";",
"$",
"fp",
"=",
"$"... | Create the stream for the request with the context options
@param array $params Parameters of the stream
@return StreamInterface | [
"Create",
"the",
"stream",
"for",
"the",
"request",
"with",
"the",
"context",
"options"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L211-L233 | train |
guzzle/guzzle3 | src/Guzzle/Stream/PhpStreamRequestFactory.php | PhpStreamRequestFactory.processResponseHeaders | protected function processResponseHeaders(StreamInterface $stream)
{
// Set the size on the stream if it was returned in the response
foreach ($this->lastResponseHeaders as $header) {
if ((stripos($header, 'Content-Length:')) === 0) {
$stream->setSize(trim(substr($header, 15)));
}
}
} | php | protected function processResponseHeaders(StreamInterface $stream)
{
// Set the size on the stream if it was returned in the response
foreach ($this->lastResponseHeaders as $header) {
if ((stripos($header, 'Content-Length:')) === 0) {
$stream->setSize(trim(substr($header, 15)));
}
}
} | [
"protected",
"function",
"processResponseHeaders",
"(",
"StreamInterface",
"$",
"stream",
")",
"{",
"// Set the size on the stream if it was returned in the response",
"foreach",
"(",
"$",
"this",
"->",
"lastResponseHeaders",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"(... | Process response headers
@param StreamInterface $stream | [
"Process",
"response",
"headers"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Stream/PhpStreamRequestFactory.php#L240-L248 | train |
guzzle/guzzle3 | src/Guzzle/Cache/CacheAdapterFactory.php | CacheAdapterFactory.createObject | private static function createObject($className, array $args = null)
{
try {
if (!$args) {
return new $className;
} else {
$c = new \ReflectionClass($className);
return $c->newInstanceArgs($args);
}
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
} | php | private static function createObject($className, array $args = null)
{
try {
if (!$args) {
return new $className;
} else {
$c = new \ReflectionClass($className);
return $c->newInstanceArgs($args);
}
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
} | [
"private",
"static",
"function",
"createObject",
"(",
"$",
"className",
",",
"array",
"$",
"args",
"=",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"args",
")",
"{",
"return",
"new",
"$",
"className",
";",
"}",
"else",
"{",
"$",
"c",
"=",
... | Create a class using an array of constructor arguments
@param string $className Class name
@param array $args Arguments for the class constructor
@return mixed
@throws RuntimeException
@deprecated
@codeCoverageIgnore | [
"Create",
"a",
"class",
"using",
"an",
"array",
"of",
"constructor",
"arguments"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Cache/CacheAdapterFactory.php#L104-L116 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php | AbstractRequestVisitor.resolveRecursively | protected function resolveRecursively(array $value, Parameter $param)
{
foreach ($value as $name => &$v) {
switch ($param->getType()) {
case 'object':
if ($subParam = $param->getProperty($name)) {
$key = $subParam->getWireName();
$value[$key] = $this->prepareValue($v, $subParam);
if ($name != $key) {
unset($value[$name]);
}
} elseif ($param->getAdditionalProperties() instanceof Parameter) {
$v = $this->prepareValue($v, $param->getAdditionalProperties());
}
break;
case 'array':
if ($items = $param->getItems()) {
$v = $this->prepareValue($v, $items);
}
break;
}
}
return $param->filter($value);
} | php | protected function resolveRecursively(array $value, Parameter $param)
{
foreach ($value as $name => &$v) {
switch ($param->getType()) {
case 'object':
if ($subParam = $param->getProperty($name)) {
$key = $subParam->getWireName();
$value[$key] = $this->prepareValue($v, $subParam);
if ($name != $key) {
unset($value[$name]);
}
} elseif ($param->getAdditionalProperties() instanceof Parameter) {
$v = $this->prepareValue($v, $param->getAdditionalProperties());
}
break;
case 'array':
if ($items = $param->getItems()) {
$v = $this->prepareValue($v, $items);
}
break;
}
}
return $param->filter($value);
} | [
"protected",
"function",
"resolveRecursively",
"(",
"array",
"$",
"value",
",",
"Parameter",
"$",
"param",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"name",
"=>",
"&",
"$",
"v",
")",
"{",
"switch",
"(",
"$",
"param",
"->",
"getType",
"(",
")... | Map nested parameters into the location_key based parameters
@param array $value Value to map
@param Parameter $param Parameter that holds information about the current key
@return array Returns the mapped array | [
"Map",
"nested",
"parameters",
"into",
"the",
"location_key",
"based",
"parameters"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php#L44-L68 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/ErrorResponse/ErrorResponsePlugin.php | ErrorResponsePlugin.onCommandBeforeSend | public function onCommandBeforeSend(Event $event)
{
$command = $event['command'];
if ($operation = $command->getOperation()) {
if ($operation->getErrorResponses()) {
$request = $command->getRequest();
$request->getEventDispatcher()
->addListener('request.complete', $this->getErrorClosure($request, $command, $operation));
}
}
} | php | public function onCommandBeforeSend(Event $event)
{
$command = $event['command'];
if ($operation = $command->getOperation()) {
if ($operation->getErrorResponses()) {
$request = $command->getRequest();
$request->getEventDispatcher()
->addListener('request.complete', $this->getErrorClosure($request, $command, $operation));
}
}
} | [
"public",
"function",
"onCommandBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"command",
"=",
"$",
"event",
"[",
"'command'",
"]",
";",
"if",
"(",
"$",
"operation",
"=",
"$",
"command",
"->",
"getOperation",
"(",
")",
")",
"{",
"if",
"(",
"... | Adds a listener to requests before they sent from a command
@param Event $event Event emitted | [
"Adds",
"a",
"listener",
"to",
"requests",
"before",
"they",
"sent",
"from",
"a",
"command"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/ErrorResponse/ErrorResponsePlugin.php#L27-L37 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Log/LogPlugin.php | LogPlugin.getDebugPlugin | public static function getDebugPlugin($wireBodies = true, $stream = null)
{
if ($stream === null) {
if (defined('STDERR')) {
$stream = STDERR;
} else {
$stream = fopen('php://output', 'w');
}
}
return new self(new ClosureLogAdapter(function ($m) use ($stream) {
fwrite($stream, $m . PHP_EOL);
}), "# Request:\n{request}\n\n# Response:\n{response}\n\n# Errors: {curl_code} {curl_error}", $wireBodies);
} | php | public static function getDebugPlugin($wireBodies = true, $stream = null)
{
if ($stream === null) {
if (defined('STDERR')) {
$stream = STDERR;
} else {
$stream = fopen('php://output', 'w');
}
}
return new self(new ClosureLogAdapter(function ($m) use ($stream) {
fwrite($stream, $m . PHP_EOL);
}), "# Request:\n{request}\n\n# Response:\n{response}\n\n# Errors: {curl_code} {curl_error}", $wireBodies);
} | [
"public",
"static",
"function",
"getDebugPlugin",
"(",
"$",
"wireBodies",
"=",
"true",
",",
"$",
"stream",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"stream",
"===",
"null",
")",
"{",
"if",
"(",
"defined",
"(",
"'STDERR'",
")",
")",
"{",
"$",
"stream",
... | Get a log plugin that outputs full request, response, and curl error information to stderr
@param bool $wireBodies Set to false to disable request/response body output when they use are not repeatable
@param resource $stream Stream to write to when logging. Defaults to STDERR when it is available
@return self | [
"Get",
"a",
"log",
"plugin",
"that",
"outputs",
"full",
"request",
"response",
"and",
"curl",
"error",
"information",
"to",
"stderr"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Log/LogPlugin.php#L55-L68 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Log/LogPlugin.php | LogPlugin.onCurlRead | public function onCurlRead(Event $event)
{
// Stream the request body to the log if the body is not repeatable
if ($wire = $event['request']->getParams()->get('request_wire')) {
$wire->write($event['read']);
}
} | php | public function onCurlRead(Event $event)
{
// Stream the request body to the log if the body is not repeatable
if ($wire = $event['request']->getParams()->get('request_wire')) {
$wire->write($event['read']);
}
} | [
"public",
"function",
"onCurlRead",
"(",
"Event",
"$",
"event",
")",
"{",
"// Stream the request body to the log if the body is not repeatable",
"if",
"(",
"$",
"wire",
"=",
"$",
"event",
"[",
"'request'",
"]",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"'re... | Event triggered when curl data is read from a request
@param Event $event | [
"Event",
"triggered",
"when",
"curl",
"data",
"is",
"read",
"from",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Log/LogPlugin.php#L85-L91 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Log/LogPlugin.php | LogPlugin.onCurlWrite | public function onCurlWrite(Event $event)
{
// Stream the response body to the log if the body is not repeatable
if ($wire = $event['request']->getParams()->get('response_wire')) {
$wire->write($event['write']);
}
} | php | public function onCurlWrite(Event $event)
{
// Stream the response body to the log if the body is not repeatable
if ($wire = $event['request']->getParams()->get('response_wire')) {
$wire->write($event['write']);
}
} | [
"public",
"function",
"onCurlWrite",
"(",
"Event",
"$",
"event",
")",
"{",
"// Stream the response body to the log if the body is not repeatable",
"if",
"(",
"$",
"wire",
"=",
"$",
"event",
"[",
"'request'",
"]",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"'... | Event triggered when curl data is written to a response
@param Event $event | [
"Event",
"triggered",
"when",
"curl",
"data",
"is",
"written",
"to",
"a",
"response"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Log/LogPlugin.php#L98-L104 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Log/LogPlugin.php | LogPlugin.onRequestBeforeSend | public function onRequestBeforeSend(Event $event)
{
if ($this->wireBodies) {
$request = $event['request'];
// Ensure that curl IO events are emitted
$request->getCurlOptions()->set('emit_io', true);
// We need to make special handling for content wiring and non-repeatable streams.
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
&& (!$request->getBody()->isSeekable() || !$request->getBody()->isReadable())
) {
// The body of the request cannot be recalled so logging the body will require us to buffer it
$request->getParams()->set('request_wire', EntityBody::factory());
}
if (!$request->getResponseBody()->isRepeatable()) {
// The body of the response cannot be recalled so logging the body will require us to buffer it
$request->getParams()->set('response_wire', EntityBody::factory());
}
}
} | php | public function onRequestBeforeSend(Event $event)
{
if ($this->wireBodies) {
$request = $event['request'];
// Ensure that curl IO events are emitted
$request->getCurlOptions()->set('emit_io', true);
// We need to make special handling for content wiring and non-repeatable streams.
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
&& (!$request->getBody()->isSeekable() || !$request->getBody()->isReadable())
) {
// The body of the request cannot be recalled so logging the body will require us to buffer it
$request->getParams()->set('request_wire', EntityBody::factory());
}
if (!$request->getResponseBody()->isRepeatable()) {
// The body of the response cannot be recalled so logging the body will require us to buffer it
$request->getParams()->set('response_wire', EntityBody::factory());
}
}
} | [
"public",
"function",
"onRequestBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"wireBodies",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"// Ensure that curl IO events are emitted",
"$",
"request",... | Called before a request is sent
@param Event $event | [
"Called",
"before",
"a",
"request",
"is",
"sent"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Log/LogPlugin.php#L111-L129 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Log/LogPlugin.php | LogPlugin.onRequestSent | public function onRequestSent(Event $event)
{
$request = $event['request'];
$response = $event['response'];
$handle = $event['handle'];
if ($wire = $request->getParams()->get('request_wire')) {
$request = clone $request;
$request->setBody($wire);
}
if ($wire = $request->getParams()->get('response_wire')) {
$response = clone $response;
$response->setBody($wire);
}
// Send the log message to the adapter, adding a category and host
$priority = $response && $response->isError() ? LOG_ERR : LOG_DEBUG;
$message = $this->formatter->format($request, $response, $handle);
$this->logAdapter->log($message, $priority, array(
'request' => $request,
'response' => $response,
'handle' => $handle
));
} | php | public function onRequestSent(Event $event)
{
$request = $event['request'];
$response = $event['response'];
$handle = $event['handle'];
if ($wire = $request->getParams()->get('request_wire')) {
$request = clone $request;
$request->setBody($wire);
}
if ($wire = $request->getParams()->get('response_wire')) {
$response = clone $response;
$response->setBody($wire);
}
// Send the log message to the adapter, adding a category and host
$priority = $response && $response->isError() ? LOG_ERR : LOG_DEBUG;
$message = $this->formatter->format($request, $response, $handle);
$this->logAdapter->log($message, $priority, array(
'request' => $request,
'response' => $response,
'handle' => $handle
));
} | [
"public",
"function",
"onRequestSent",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"$",
"response",
"=",
"$",
"event",
"[",
"'response'",
"]",
";",
"$",
"handle",
"=",
"$",
"event",
"[",
"'hand... | Triggers the actual log write when a request completes
@param Event $event | [
"Triggers",
"the",
"actual",
"log",
"write",
"when",
"a",
"request",
"completes"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Log/LogPlugin.php#L136-L160 | train |
guzzle/guzzle3 | src/Guzzle/Http/StaticClient.php | StaticClient.mount | public static function mount($className = 'Guzzle', ClientInterface $client = null)
{
class_alias(__CLASS__, $className);
if ($client) {
self::$client = $client;
}
} | php | public static function mount($className = 'Guzzle', ClientInterface $client = null)
{
class_alias(__CLASS__, $className);
if ($client) {
self::$client = $client;
}
} | [
"public",
"static",
"function",
"mount",
"(",
"$",
"className",
"=",
"'Guzzle'",
",",
"ClientInterface",
"$",
"client",
"=",
"null",
")",
"{",
"class_alias",
"(",
"__CLASS__",
",",
"$",
"className",
")",
";",
"if",
"(",
"$",
"client",
")",
"{",
"self",
... | Mount the client to a simpler class name for a specific client
@param string $className Class name to use to mount
@param ClientInterface $client Client used to send requests | [
"Mount",
"the",
"client",
"to",
"a",
"simpler",
"class",
"name",
"for",
"a",
"specific",
"client"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/StaticClient.php#L24-L30 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/History/HistoryPlugin.php | HistoryPlugin.getIterator | public function getIterator()
{
// Return an iterator just like the old iteration of the HistoryPlugin for BC compatibility (use getAll())
return new \ArrayIterator(array_map(function ($entry) {
$entry['request']->getParams()->set('actual_response', $entry['response']);
return $entry['request'];
}, $this->transactions));
} | php | public function getIterator()
{
// Return an iterator just like the old iteration of the HistoryPlugin for BC compatibility (use getAll())
return new \ArrayIterator(array_map(function ($entry) {
$entry['request']->getParams()->set('actual_response', $entry['response']);
return $entry['request'];
}, $this->transactions));
} | [
"public",
"function",
"getIterator",
"(",
")",
"{",
"// Return an iterator just like the old iteration of the HistoryPlugin for BC compatibility (use getAll())",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"array_map",
"(",
"function",
"(",
"$",
"entry",
")",
"{",
"$",
"en... | Get the requests in the history
@return \ArrayIterator | [
"Get",
"the",
"requests",
"in",
"the",
"history"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/History/HistoryPlugin.php#L104-L111 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMulti.php | CurlMulti.createCurlHandle | protected function createCurlHandle(RequestInterface $request)
{
$wrapper = CurlHandle::factory($request);
$this->handles[$request] = $wrapper;
$this->resourceHash[(int) $wrapper->getHandle()] = $request;
return $wrapper;
} | php | protected function createCurlHandle(RequestInterface $request)
{
$wrapper = CurlHandle::factory($request);
$this->handles[$request] = $wrapper;
$this->resourceHash[(int) $wrapper->getHandle()] = $request;
return $wrapper;
} | [
"protected",
"function",
"createCurlHandle",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"wrapper",
"=",
"CurlHandle",
"::",
"factory",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"handles",
"[",
"$",
"request",
"]",
"=",
"$",
"wrapper",
... | Create a curl handle for a request
@param RequestInterface $request Request
@return CurlHandle | [
"Create",
"a",
"curl",
"handle",
"for",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMulti.php#L192-L199 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMulti.php | CurlMulti.executeHandles | private function executeHandles()
{
// The first curl_multi_select often times out no matter what, but is usually required for fast transfers
$selectTimeout = 0.001;
$active = false;
do {
while (($mrc = curl_multi_exec($this->multiHandle, $active)) == CURLM_CALL_MULTI_PERFORM);
$this->checkCurlResult($mrc);
$this->processMessages();
if ($active && curl_multi_select($this->multiHandle, $selectTimeout) === -1) {
// Perform a usleep if a select returns -1: https://bugs.php.net/bug.php?id=61141
usleep(150);
}
$selectTimeout = $this->selectTimeout;
} while ($active);
} | php | private function executeHandles()
{
// The first curl_multi_select often times out no matter what, but is usually required for fast transfers
$selectTimeout = 0.001;
$active = false;
do {
while (($mrc = curl_multi_exec($this->multiHandle, $active)) == CURLM_CALL_MULTI_PERFORM);
$this->checkCurlResult($mrc);
$this->processMessages();
if ($active && curl_multi_select($this->multiHandle, $selectTimeout) === -1) {
// Perform a usleep if a select returns -1: https://bugs.php.net/bug.php?id=61141
usleep(150);
}
$selectTimeout = $this->selectTimeout;
} while ($active);
} | [
"private",
"function",
"executeHandles",
"(",
")",
"{",
"// The first curl_multi_select often times out no matter what, but is usually required for fast transfers",
"$",
"selectTimeout",
"=",
"0.001",
";",
"$",
"active",
"=",
"false",
";",
"do",
"{",
"while",
"(",
"(",
"$... | Execute and select curl handles | [
"Execute",
"and",
"select",
"curl",
"handles"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMulti.php#L232-L247 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMulti.php | CurlMulti.processMessages | private function processMessages()
{
while ($done = curl_multi_info_read($this->multiHandle)) {
$request = $this->resourceHash[(int) $done['handle']];
try {
$this->processResponse($request, $this->handles[$request], $done);
$this->successful[] = $request;
} catch (\Exception $e) {
$this->removeErroredRequest($request, $e);
}
}
} | php | private function processMessages()
{
while ($done = curl_multi_info_read($this->multiHandle)) {
$request = $this->resourceHash[(int) $done['handle']];
try {
$this->processResponse($request, $this->handles[$request], $done);
$this->successful[] = $request;
} catch (\Exception $e) {
$this->removeErroredRequest($request, $e);
}
}
} | [
"private",
"function",
"processMessages",
"(",
")",
"{",
"while",
"(",
"$",
"done",
"=",
"curl_multi_info_read",
"(",
"$",
"this",
"->",
"multiHandle",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"resourceHash",
"[",
"(",
"int",
")",
"$",
"d... | Process any received curl multi messages | [
"Process",
"any",
"received",
"curl",
"multi",
"messages"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMulti.php#L252-L263 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMulti.php | CurlMulti.isCurlException | private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl)
{
if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) {
return false;
}
$handle->setErrorNo($curl['result']);
$e = new CurlException(sprintf('[curl] %s: %s [url] %s',
$handle->getErrorNo(), $handle->getError(), $handle->getUrl()));
$e->setCurlHandle($handle)
->setRequest($request)
->setCurlInfo($handle->getInfo())
->setError($handle->getError(), $handle->getErrorNo());
return $e;
} | php | private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl)
{
if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) {
return false;
}
$handle->setErrorNo($curl['result']);
$e = new CurlException(sprintf('[curl] %s: %s [url] %s',
$handle->getErrorNo(), $handle->getError(), $handle->getUrl()));
$e->setCurlHandle($handle)
->setRequest($request)
->setCurlInfo($handle->getInfo())
->setError($handle->getError(), $handle->getErrorNo());
return $e;
} | [
"private",
"function",
"isCurlException",
"(",
"RequestInterface",
"$",
"request",
",",
"CurlHandle",
"$",
"handle",
",",
"array",
"$",
"curl",
")",
"{",
"if",
"(",
"CURLM_OK",
"==",
"$",
"curl",
"[",
"'result'",
"]",
"||",
"CURLM_CALL_MULTI_PERFORM",
"==",
... | Check if a cURL transfer resulted in what should be an exception
@param RequestInterface $request Request to check
@param CurlHandle $handle Curl handle object
@param array $curl Array returned from curl_multi_info_read
@return CurlException|bool | [
"Check",
"if",
"a",
"cURL",
"transfer",
"resulted",
"in",
"what",
"should",
"be",
"an",
"exception"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMulti.php#L352-L367 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlMulti.php | CurlMulti.checkCurlResult | private function checkCurlResult($code)
{
if ($code != CURLM_OK && $code != CURLM_CALL_MULTI_PERFORM) {
throw new CurlException(isset($this->multiErrors[$code])
? "cURL error: {$code} ({$this->multiErrors[$code][0]}): cURL message: {$this->multiErrors[$code][1]}"
: 'Unexpected cURL error: ' . $code
);
}
} | php | private function checkCurlResult($code)
{
if ($code != CURLM_OK && $code != CURLM_CALL_MULTI_PERFORM) {
throw new CurlException(isset($this->multiErrors[$code])
? "cURL error: {$code} ({$this->multiErrors[$code][0]}): cURL message: {$this->multiErrors[$code][1]}"
: 'Unexpected cURL error: ' . $code
);
}
} | [
"private",
"function",
"checkCurlResult",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"code",
"!=",
"CURLM_OK",
"&&",
"$",
"code",
"!=",
"CURLM_CALL_MULTI_PERFORM",
")",
"{",
"throw",
"new",
"CurlException",
"(",
"isset",
"(",
"$",
"this",
"->",
"multiErro... | Throw an exception for a cURL multi response if needed
@param int $code Curl response code
@throws CurlException | [
"Throw",
"an",
"exception",
"for",
"a",
"cURL",
"multi",
"response",
"if",
"needed"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlMulti.php#L375-L383 | train |
guzzle/guzzle3 | src/Guzzle/Service/Resource/ResourceIteratorApplyBatched.php | ResourceIteratorApplyBatched.apply | public function apply($perBatch = 50)
{
$this->iterated = $this->batches = $batches = 0;
$that = $this;
$it = $this->iterator;
$callback = $this->callback;
$batch = BatchBuilder::factory()
->createBatchesWith(new BatchSizeDivisor($perBatch))
->transferWith(new BatchClosureTransfer(function (array $batch) use ($that, $callback, &$batches, $it) {
$batches++;
$that->dispatch('iterator_batch.before_batch', array('iterator' => $it, 'batch' => $batch));
call_user_func_array($callback, array($it, $batch));
$that->dispatch('iterator_batch.after_batch', array('iterator' => $it, 'batch' => $batch));
}))
->autoFlushAt($perBatch)
->build();
$this->dispatch('iterator_batch.created_batch', array('batch' => $batch));
foreach ($this->iterator as $resource) {
$this->iterated++;
$batch->add($resource);
}
$batch->flush();
$this->batches = $batches;
return $this->iterated;
} | php | public function apply($perBatch = 50)
{
$this->iterated = $this->batches = $batches = 0;
$that = $this;
$it = $this->iterator;
$callback = $this->callback;
$batch = BatchBuilder::factory()
->createBatchesWith(new BatchSizeDivisor($perBatch))
->transferWith(new BatchClosureTransfer(function (array $batch) use ($that, $callback, &$batches, $it) {
$batches++;
$that->dispatch('iterator_batch.before_batch', array('iterator' => $it, 'batch' => $batch));
call_user_func_array($callback, array($it, $batch));
$that->dispatch('iterator_batch.after_batch', array('iterator' => $it, 'batch' => $batch));
}))
->autoFlushAt($perBatch)
->build();
$this->dispatch('iterator_batch.created_batch', array('batch' => $batch));
foreach ($this->iterator as $resource) {
$this->iterated++;
$batch->add($resource);
}
$batch->flush();
$this->batches = $batches;
return $this->iterated;
} | [
"public",
"function",
"apply",
"(",
"$",
"perBatch",
"=",
"50",
")",
"{",
"$",
"this",
"->",
"iterated",
"=",
"$",
"this",
"->",
"batches",
"=",
"$",
"batches",
"=",
"0",
";",
"$",
"that",
"=",
"$",
"this",
";",
"$",
"it",
"=",
"$",
"this",
"->... | Apply the callback to the contents of the resource iterator
@param int $perBatch The number of records to group per batch transfer
@return int Returns the number of iterated resources | [
"Apply",
"the",
"callback",
"to",
"the",
"contents",
"of",
"the",
"resource",
"iterator"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Resource/ResourceIteratorApplyBatched.php#L61-L90 | train |
guzzle/guzzle3 | src/Guzzle/Service/Builder/ServiceBuilder.php | ServiceBuilder.factory | public static function factory($config = null, array $globalParameters = array())
{
// @codeCoverageIgnoreStart
if (!static::$cachedFactory) {
static::$cachedFactory = new ServiceBuilderLoader();
}
// @codeCoverageIgnoreEnd
return self::$cachedFactory->load($config, $globalParameters);
} | php | public static function factory($config = null, array $globalParameters = array())
{
// @codeCoverageIgnoreStart
if (!static::$cachedFactory) {
static::$cachedFactory = new ServiceBuilderLoader();
}
// @codeCoverageIgnoreEnd
return self::$cachedFactory->load($config, $globalParameters);
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"config",
"=",
"null",
",",
"array",
"$",
"globalParameters",
"=",
"array",
"(",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"static",
"::",
"$",
"cachedFactory",
")",
"{",
"static",
":... | Create a new ServiceBuilder using configuration data sourced from an
array, .js|.json or .php file.
@param array|string $config The full path to an .json|.js or .php file, or an associative array
@param array $globalParameters Array of global parameters to pass to every service as it is instantiated.
@return ServiceBuilderInterface
@throws ServiceBuilderException if a file cannot be opened
@throws ServiceNotFoundException when trying to extend a missing client | [
"Create",
"a",
"new",
"ServiceBuilder",
"using",
"configuration",
"data",
"sourced",
"from",
"an",
"array",
".",
"js|",
".",
"json",
"or",
".",
"php",
"file",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Builder/ServiceBuilder.php#L41-L50 | train |
guzzle/guzzle3 | src/Guzzle/Service/Builder/ServiceBuilder.php | ServiceBuilder.getData | public function getData($name)
{
return isset($this->builderConfig[$name]) ? $this->builderConfig[$name] : null;
} | php | public function getData($name)
{
return isset($this->builderConfig[$name]) ? $this->builderConfig[$name] : null;
} | [
"public",
"function",
"getData",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"builderConfig",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"builderConfig",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Get data from the service builder without triggering the building of a service
@param string $name Name of the service to retrieve
@return array|null | [
"Get",
"data",
"from",
"the",
"service",
"builder",
"without",
"triggering",
"the",
"building",
"of",
"a",
"service"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Builder/ServiceBuilder.php#L99-L102 | train |
guzzle/guzzle3 | src/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.cleanupRequest | public function cleanupRequest(Event $event)
{
$params = $event['request']->getParams();
unset($params[self::REDIRECT_COUNT]);
unset($params[self::PARENT_REQUEST]);
} | php | public function cleanupRequest(Event $event)
{
$params = $event['request']->getParams();
unset($params[self::REDIRECT_COUNT]);
unset($params[self::PARENT_REQUEST]);
} | [
"public",
"function",
"cleanupRequest",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"params",
"=",
"$",
"event",
"[",
"'request'",
"]",
"->",
"getParams",
"(",
")",
";",
"unset",
"(",
"$",
"params",
"[",
"self",
"::",
"REDIRECT_COUNT",
"]",
")",
";",
... | Clean up the parameters of a request when it is cloned
@param Event $event Event emitted | [
"Clean",
"up",
"the",
"parameters",
"of",
"a",
"request",
"when",
"it",
"is",
"cloned"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/RedirectPlugin.php#L46-L51 | train |
guzzle/guzzle3 | src/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.getOriginalRequest | protected function getOriginalRequest(RequestInterface $request)
{
$original = $request;
// The number of redirects is held on the original request, so determine which request that is
while ($parent = $original->getParams()->get(self::PARENT_REQUEST)) {
$original = $parent;
}
return $original;
} | php | protected function getOriginalRequest(RequestInterface $request)
{
$original = $request;
// The number of redirects is held on the original request, so determine which request that is
while ($parent = $original->getParams()->get(self::PARENT_REQUEST)) {
$original = $parent;
}
return $original;
} | [
"protected",
"function",
"getOriginalRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"original",
"=",
"$",
"request",
";",
"// The number of redirects is held on the original request, so determine which request that is",
"while",
"(",
"$",
"parent",
"=",
"... | Get the original request that initiated a series of redirects
@param RequestInterface $request Request to get the original request from
@return RequestInterface | [
"Get",
"the",
"original",
"request",
"that",
"initiated",
"a",
"series",
"of",
"redirects"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/RedirectPlugin.php#L92-L101 | train |
guzzle/guzzle3 | src/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.prepareRedirection | protected function prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response)
{
$params = $original->getParams();
// This is a new redirect, so increment the redirect counter
$current = $params[self::REDIRECT_COUNT] + 1;
$params[self::REDIRECT_COUNT] = $current;
// Use a provided maximum value or default to a max redirect count of 5
$max = isset($params[self::MAX_REDIRECTS]) ? $params[self::MAX_REDIRECTS] : $this->defaultMaxRedirects;
// Throw an exception if the redirect count is exceeded
if ($current > $max) {
$this->throwTooManyRedirectsException($original, $max);
return false;
} else {
// Create a redirect request based on the redirect rules set on the request
return $this->createRedirectRequest(
$request,
$response->getStatusCode(),
trim($response->getLocation()),
$original
);
}
} | php | protected function prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response)
{
$params = $original->getParams();
// This is a new redirect, so increment the redirect counter
$current = $params[self::REDIRECT_COUNT] + 1;
$params[self::REDIRECT_COUNT] = $current;
// Use a provided maximum value or default to a max redirect count of 5
$max = isset($params[self::MAX_REDIRECTS]) ? $params[self::MAX_REDIRECTS] : $this->defaultMaxRedirects;
// Throw an exception if the redirect count is exceeded
if ($current > $max) {
$this->throwTooManyRedirectsException($original, $max);
return false;
} else {
// Create a redirect request based on the redirect rules set on the request
return $this->createRedirectRequest(
$request,
$response->getStatusCode(),
trim($response->getLocation()),
$original
);
}
} | [
"protected",
"function",
"prepareRedirection",
"(",
"RequestInterface",
"$",
"original",
",",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"params",
"=",
"$",
"original",
"->",
"getParams",
"(",
")",
";",
"// This is a new... | Prepare the request for redirection and enforce the maximum number of allowed redirects per client
@param RequestInterface $original Original request
@param RequestInterface $request Request to prepare and validate
@param Response $response The current response
@return RequestInterface | [
"Prepare",
"the",
"request",
"for",
"redirection",
"and",
"enforce",
"the",
"maximum",
"number",
"of",
"allowed",
"redirects",
"per",
"client"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/RedirectPlugin.php#L183-L205 | train |
guzzle/guzzle3 | src/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.sendRedirectRequest | protected function sendRedirectRequest(RequestInterface $original, RequestInterface $request, Response $response)
{
// Validate and create a redirect request based on the original request and current response
if ($redirectRequest = $this->prepareRedirection($original, $request, $response)) {
try {
$redirectRequest->send();
} catch (BadResponseException $e) {
$e->getResponse();
if (!$e->getResponse()) {
throw $e;
}
}
}
} | php | protected function sendRedirectRequest(RequestInterface $original, RequestInterface $request, Response $response)
{
// Validate and create a redirect request based on the original request and current response
if ($redirectRequest = $this->prepareRedirection($original, $request, $response)) {
try {
$redirectRequest->send();
} catch (BadResponseException $e) {
$e->getResponse();
if (!$e->getResponse()) {
throw $e;
}
}
}
} | [
"protected",
"function",
"sendRedirectRequest",
"(",
"RequestInterface",
"$",
"original",
",",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"// Validate and create a redirect request based on the original request and current response",
"if",
"... | Send a redirect request and handle any errors
@param RequestInterface $original The originating request
@param RequestInterface $request The current request being redirected
@param Response $response The response of the current request
@throws BadResponseException|\Exception | [
"Send",
"a",
"redirect",
"request",
"and",
"handle",
"any",
"errors"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/RedirectPlugin.php#L216-L229 | train |
guzzle/guzzle3 | src/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.throwTooManyRedirectsException | protected function throwTooManyRedirectsException(RequestInterface $original, $max)
{
$original->getEventDispatcher()->addListener(
'request.complete',
$func = function ($e) use (&$func, $original, $max) {
$original->getEventDispatcher()->removeListener('request.complete', $func);
$str = "{$max} redirects were issued for this request:\n" . $e['request']->getRawHeaders();
throw new TooManyRedirectsException($str);
}
);
} | php | protected function throwTooManyRedirectsException(RequestInterface $original, $max)
{
$original->getEventDispatcher()->addListener(
'request.complete',
$func = function ($e) use (&$func, $original, $max) {
$original->getEventDispatcher()->removeListener('request.complete', $func);
$str = "{$max} redirects were issued for this request:\n" . $e['request']->getRawHeaders();
throw new TooManyRedirectsException($str);
}
);
} | [
"protected",
"function",
"throwTooManyRedirectsException",
"(",
"RequestInterface",
"$",
"original",
",",
"$",
"max",
")",
"{",
"$",
"original",
"->",
"getEventDispatcher",
"(",
")",
"->",
"addListener",
"(",
"'request.complete'",
",",
"$",
"func",
"=",
"function"... | Throw a too many redirects exception for a request
@param RequestInterface $original Request
@param int $max Max allowed redirects
@throws TooManyRedirectsException when too many redirects have been issued | [
"Throw",
"a",
"too",
"many",
"redirects",
"exception",
"for",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/RedirectPlugin.php#L239-L249 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php | HeaderVisitor.processPrefixedHeaders | protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
// Grab prefixed headers that should be placed into an array with the prefix stripped
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
// Find all matching headers and place them into the containing element
foreach ($response->getHeaders()->toArray() as $key => $header) {
if (stripos($key, $prefix) === 0) {
// Account for multi-value headers
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
} | php | protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
// Grab prefixed headers that should be placed into an array with the prefix stripped
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
// Find all matching headers and place them into the containing element
foreach ($response->getHeaders()->toArray() as $key => $header) {
if (stripos($key, $prefix) === 0) {
// Account for multi-value headers
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
} | [
"protected",
"function",
"processPrefixedHeaders",
"(",
"Response",
"$",
"response",
",",
"Parameter",
"$",
"param",
",",
"&",
"$",
"value",
")",
"{",
"// Grab prefixed headers that should be placed into an array with the prefix stripped",
"if",
"(",
"$",
"prefix",
"=",
... | Process a prefixed header array
@param Response $response Response that contains the headers
@param Parameter $param Parameter object
@param array $value Value response array to modify | [
"Process",
"a",
"prefixed",
"header",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php#L35-L49 | train |
guzzle/guzzle3 | src/Guzzle/Batch/AbstractBatchDecorator.php | AbstractBatchDecorator.getDecorators | public function getDecorators()
{
$found = array($this);
if (method_exists($this->decoratedBatch, 'getDecorators')) {
$found = array_merge($found, $this->decoratedBatch->getDecorators());
}
return $found;
} | php | public function getDecorators()
{
$found = array($this);
if (method_exists($this->decoratedBatch, 'getDecorators')) {
$found = array_merge($found, $this->decoratedBatch->getDecorators());
}
return $found;
} | [
"public",
"function",
"getDecorators",
"(",
")",
"{",
"$",
"found",
"=",
"array",
"(",
"$",
"this",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"decoratedBatch",
",",
"'getDecorators'",
")",
")",
"{",
"$",
"found",
"=",
"array_merge",
... | Trace the decorators associated with the batch
@return array | [
"Trace",
"the",
"decorators",
"associated",
"with",
"the",
"batch"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Batch/AbstractBatchDecorator.php#L57-L65 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php | XmlVisitor.createRootElement | protected function createRootElement(Operation $operation)
{
static $defaultRoot = array('name' => 'Request');
// If no root element was specified, then just wrap the XML in 'Request'
$root = $operation->getData('xmlRoot') ?: $defaultRoot;
// Allow the XML declaration to be customized with xmlEncoding
$encoding = $operation->getData('xmlEncoding');
$xmlWriter = $this->startDocument($encoding);
$xmlWriter->startElement($root['name']);
// Create the wrapping element with no namespaces if no namespaces were present
if (!empty($root['namespaces'])) {
// Create the wrapping element with an array of one or more namespaces
foreach ((array) $root['namespaces'] as $prefix => $uri) {
$nsLabel = 'xmlns';
if (!is_numeric($prefix)) {
$nsLabel .= ':'.$prefix;
}
$xmlWriter->writeAttribute($nsLabel, $uri);
}
}
return $xmlWriter;
} | php | protected function createRootElement(Operation $operation)
{
static $defaultRoot = array('name' => 'Request');
// If no root element was specified, then just wrap the XML in 'Request'
$root = $operation->getData('xmlRoot') ?: $defaultRoot;
// Allow the XML declaration to be customized with xmlEncoding
$encoding = $operation->getData('xmlEncoding');
$xmlWriter = $this->startDocument($encoding);
$xmlWriter->startElement($root['name']);
// Create the wrapping element with no namespaces if no namespaces were present
if (!empty($root['namespaces'])) {
// Create the wrapping element with an array of one or more namespaces
foreach ((array) $root['namespaces'] as $prefix => $uri) {
$nsLabel = 'xmlns';
if (!is_numeric($prefix)) {
$nsLabel .= ':'.$prefix;
}
$xmlWriter->writeAttribute($nsLabel, $uri);
}
}
return $xmlWriter;
} | [
"protected",
"function",
"createRootElement",
"(",
"Operation",
"$",
"operation",
")",
"{",
"static",
"$",
"defaultRoot",
"=",
"array",
"(",
"'name'",
"=>",
"'Request'",
")",
";",
"// If no root element was specified, then just wrap the XML in 'Request'",
"$",
"root",
"... | Create the root XML element to use with a request
@param Operation $operation Operation object
@return \XMLWriter | [
"Create",
"the",
"root",
"XML",
"element",
"to",
"use",
"with",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php#L83-L106 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php | XmlVisitor.addXmlArray | protected function addXmlArray(\XMLWriter $xmlWriter, Parameter $param, &$value)
{
if ($items = $param->getItems()) {
foreach ($value as $v) {
$this->addXml($xmlWriter, $items, $v);
}
}
} | php | protected function addXmlArray(\XMLWriter $xmlWriter, Parameter $param, &$value)
{
if ($items = $param->getItems()) {
foreach ($value as $v) {
$this->addXml($xmlWriter, $items, $v);
}
}
} | [
"protected",
"function",
"addXmlArray",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"Parameter",
"$",
"param",
",",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"items",
"=",
"$",
"param",
"->",
"getItems",
"(",
")",
")",
"{",
"foreach",
"(",
"$",... | Add an array to the XML | [
"Add",
"an",
"array",
"to",
"the",
"XML"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php#L222-L229 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php | XmlVisitor.addXmlObject | protected function addXmlObject(\XMLWriter $xmlWriter, Parameter $param, &$value)
{
$noAttributes = array();
// add values which have attributes
foreach ($value as $name => $v) {
if ($property = $param->getProperty($name)) {
if ($property->getData('xmlAttribute')) {
$this->addXml($xmlWriter, $property, $v);
} else {
$noAttributes[] = array('value' => $v, 'property' => $property);
}
}
}
// now add values with no attributes
foreach ($noAttributes as $element) {
$this->addXml($xmlWriter, $element['property'], $element['value']);
}
} | php | protected function addXmlObject(\XMLWriter $xmlWriter, Parameter $param, &$value)
{
$noAttributes = array();
// add values which have attributes
foreach ($value as $name => $v) {
if ($property = $param->getProperty($name)) {
if ($property->getData('xmlAttribute')) {
$this->addXml($xmlWriter, $property, $v);
} else {
$noAttributes[] = array('value' => $v, 'property' => $property);
}
}
}
// now add values with no attributes
foreach ($noAttributes as $element) {
$this->addXml($xmlWriter, $element['property'], $element['value']);
}
} | [
"protected",
"function",
"addXmlObject",
"(",
"\\",
"XMLWriter",
"$",
"xmlWriter",
",",
"Parameter",
"$",
"param",
",",
"&",
"$",
"value",
")",
"{",
"$",
"noAttributes",
"=",
"array",
"(",
")",
";",
"// add values which have attributes",
"foreach",
"(",
"$",
... | Add an object to the XML | [
"Add",
"an",
"object",
"to",
"the",
"XML"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php#L234-L251 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Backoff/BackoffLogger.php | BackoffLogger.onRequestRetry | public function onRequestRetry(Event $event)
{
$this->logger->log($this->formatter->format(
$event['request'],
$event['response'],
$event['handle'],
array(
'retries' => $event['retries'],
'delay' => $event['delay']
)
));
} | php | public function onRequestRetry(Event $event)
{
$this->logger->log($this->formatter->format(
$event['request'],
$event['response'],
$event['handle'],
array(
'retries' => $event['retries'],
'delay' => $event['delay']
)
));
} | [
"public",
"function",
"onRequestRetry",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"event",
"[",
"'request'",
"]",
",",
"$",
"event",
"[",
"'response'",... | Called when a request is being retried
@param Event $event Event emitted | [
"Called",
"when",
"a",
"request",
"is",
"being",
"retried"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Backoff/BackoffLogger.php#L64-L75 | train |
guzzle/guzzle3 | src/Guzzle/Http/Url.php | Url.setHost | public function setHost($host)
{
if (strpos($host, ':') === false) {
$this->host = $host;
} else {
list($host, $port) = explode(':', $host);
$this->host = $host;
$this->setPort($port);
}
return $this;
} | php | public function setHost($host)
{
if (strpos($host, ':') === false) {
$this->host = $host;
} else {
list($host, $port) = explode(':', $host);
$this->host = $host;
$this->setPort($port);
}
return $this;
} | [
"public",
"function",
"setHost",
"(",
"$",
"host",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"host",
",",
"':'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"host",
",",
... | Set the host of the request.
@param string $host Host to set (e.g. www.yahoo.com, yahoo.com)
@return Url | [
"Set",
"the",
"host",
"of",
"the",
"request",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Url.php#L184-L195 | train |
guzzle/guzzle3 | src/Guzzle/Http/Url.php | Url.combine | public function combine($url, $strictRfc3986 = false)
{
$url = self::factory($url);
// Use the more absolute URL as the base URL
if (!$this->isAbsolute() && $url->isAbsolute()) {
$url = $url->combine($this);
}
// Passing a URL with a scheme overrides everything
if ($buffer = $url->getScheme()) {
$this->scheme = $buffer;
$this->host = $url->getHost();
$this->port = $url->getPort();
$this->username = $url->getUsername();
$this->password = $url->getPassword();
$this->path = $url->getPath();
$this->query = $url->getQuery();
$this->fragment = $url->getFragment();
return $this;
}
// Setting a host overrides the entire rest of the URL
if ($buffer = $url->getHost()) {
$this->host = $buffer;
$this->port = $url->getPort();
$this->username = $url->getUsername();
$this->password = $url->getPassword();
$this->path = $url->getPath();
$this->query = $url->getQuery();
$this->fragment = $url->getFragment();
return $this;
}
$path = $url->getPath();
$query = $url->getQuery();
if (!$path) {
if (count($query)) {
$this->addQuery($query, $strictRfc3986);
}
} else {
if ($path[0] == '/') {
$this->path = $path;
} elseif ($strictRfc3986) {
$this->path .= '/../' . $path;
} else {
$this->path .= '/' . $path;
}
$this->normalizePath();
$this->addQuery($query, $strictRfc3986);
}
$this->fragment = $url->getFragment();
return $this;
} | php | public function combine($url, $strictRfc3986 = false)
{
$url = self::factory($url);
// Use the more absolute URL as the base URL
if (!$this->isAbsolute() && $url->isAbsolute()) {
$url = $url->combine($this);
}
// Passing a URL with a scheme overrides everything
if ($buffer = $url->getScheme()) {
$this->scheme = $buffer;
$this->host = $url->getHost();
$this->port = $url->getPort();
$this->username = $url->getUsername();
$this->password = $url->getPassword();
$this->path = $url->getPath();
$this->query = $url->getQuery();
$this->fragment = $url->getFragment();
return $this;
}
// Setting a host overrides the entire rest of the URL
if ($buffer = $url->getHost()) {
$this->host = $buffer;
$this->port = $url->getPort();
$this->username = $url->getUsername();
$this->password = $url->getPassword();
$this->path = $url->getPath();
$this->query = $url->getQuery();
$this->fragment = $url->getFragment();
return $this;
}
$path = $url->getPath();
$query = $url->getQuery();
if (!$path) {
if (count($query)) {
$this->addQuery($query, $strictRfc3986);
}
} else {
if ($path[0] == '/') {
$this->path = $path;
} elseif ($strictRfc3986) {
$this->path .= '/../' . $path;
} else {
$this->path .= '/' . $path;
}
$this->normalizePath();
$this->addQuery($query, $strictRfc3986);
}
$this->fragment = $url->getFragment();
return $this;
} | [
"public",
"function",
"combine",
"(",
"$",
"url",
",",
"$",
"strictRfc3986",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"factory",
"(",
"$",
"url",
")",
";",
"// Use the more absolute URL as the base URL",
"if",
"(",
"!",
"$",
"this",
"->",
"... | Combine the URL with another URL. Follows the rules specific in RFC 3986 section 5.4.
@param string $url Relative URL to combine with
@param bool $strictRfc3986 Set to true to use strict RFC 3986 compliance when merging paths. When first
released, Guzzle used an incorrect algorithm for combining relative URL paths. In
order to not break users, we introduced this flag to allow the merging of URLs based
on strict RFC 3986 section 5.4.1. This means that "http://a.com/foo/baz" merged with
"bar" would become "http://a.com/foo/bar". When this value is set to false, it would
become "http://a.com/foo/baz/bar".
@return Url
@throws InvalidArgumentException
@link http://tools.ietf.org/html/rfc3986#section-5.4 | [
"Combine",
"the",
"URL",
"with",
"another",
"URL",
".",
"Follows",
"the",
"rules",
"specific",
"in",
"RFC",
"3986",
"section",
"5",
".",
"4",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Url.php#L488-L544 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header.php | Header.normalize | public function normalize()
{
$values = $this->toArray();
for ($i = 0, $total = count($values); $i < $total; $i++) {
if (strpos($values[$i], $this->glue) !== false) {
// Explode on glue when the glue is not inside of a comma
foreach (preg_split('/' . preg_quote($this->glue) . '(?=([^"]*"[^"]*")*[^"]*$)/', $values[$i]) as $v) {
$values[] = trim($v);
}
unset($values[$i]);
}
}
$this->values = array_values($values);
return $this;
} | php | public function normalize()
{
$values = $this->toArray();
for ($i = 0, $total = count($values); $i < $total; $i++) {
if (strpos($values[$i], $this->glue) !== false) {
// Explode on glue when the glue is not inside of a comma
foreach (preg_split('/' . preg_quote($this->glue) . '(?=([^"]*"[^"]*")*[^"]*$)/', $values[$i]) as $v) {
$values[] = trim($v);
}
unset($values[$i]);
}
}
$this->values = array_values($values);
return $this;
} | [
"public",
"function",
"normalize",
"(",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"total",
"=",
"count",
"(",
"$",
"values",
")",
";",
"$",
"i",
"<",
"$",
"total",
";"... | Normalize the header to be a single header with an array of values.
If any values of the header contains the glue string value (e.g. ","), then the value will be exploded into
multiple entries in the header.
@return self | [
"Normalize",
"the",
"header",
"to",
"be",
"a",
"single",
"header",
"with",
"an",
"array",
"of",
"values",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header.php#L78-L95 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultRevalidation.php | DefaultRevalidation.handleBadResponse | protected function handleBadResponse(BadResponseException $e)
{
// 404 errors mean the resource no longer exists, so remove from
// cache, and prevent an additional request by throwing the exception
if ($e->getResponse()->getStatusCode() == 404) {
$this->storage->delete($e->getRequest());
throw $e;
}
} | php | protected function handleBadResponse(BadResponseException $e)
{
// 404 errors mean the resource no longer exists, so remove from
// cache, and prevent an additional request by throwing the exception
if ($e->getResponse()->getStatusCode() == 404) {
$this->storage->delete($e->getRequest());
throw $e;
}
} | [
"protected",
"function",
"handleBadResponse",
"(",
"BadResponseException",
"$",
"e",
")",
"{",
"// 404 errors mean the resource no longer exists, so remove from",
"// cache, and prevent an additional request by throwing the exception",
"if",
"(",
"$",
"e",
"->",
"getResponse",
"(",... | Handles a bad response when attempting to revalidate
@param BadResponseException $e Exception encountered
@throws BadResponseException | [
"Handles",
"a",
"bad",
"response",
"when",
"attempting",
"to",
"revalidate"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultRevalidation.php#L77-L85 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultRevalidation.php | DefaultRevalidation.createRevalidationRequest | protected function createRevalidationRequest(RequestInterface $request, Response $response)
{
$revalidate = clone $request;
$revalidate->removeHeader('Pragma')->removeHeader('Cache-Control');
if ($response->getLastModified()) {
$revalidate->setHeader('If-Modified-Since', $response->getLastModified());
}
if ($response->getEtag()) {
$revalidate->setHeader('If-None-Match', $response->getEtag());
}
// Remove any cache plugins that might be on the request to prevent infinite recursive revalidations
$dispatcher = $revalidate->getEventDispatcher();
foreach ($dispatcher->getListeners() as $eventName => $listeners) {
foreach ($listeners as $listener) {
if (is_array($listener) && $listener[0] instanceof CachePlugin) {
$dispatcher->removeListener($eventName, $listener);
}
}
}
return $revalidate;
} | php | protected function createRevalidationRequest(RequestInterface $request, Response $response)
{
$revalidate = clone $request;
$revalidate->removeHeader('Pragma')->removeHeader('Cache-Control');
if ($response->getLastModified()) {
$revalidate->setHeader('If-Modified-Since', $response->getLastModified());
}
if ($response->getEtag()) {
$revalidate->setHeader('If-None-Match', $response->getEtag());
}
// Remove any cache plugins that might be on the request to prevent infinite recursive revalidations
$dispatcher = $revalidate->getEventDispatcher();
foreach ($dispatcher->getListeners() as $eventName => $listeners) {
foreach ($listeners as $listener) {
if (is_array($listener) && $listener[0] instanceof CachePlugin) {
$dispatcher->removeListener($eventName, $listener);
}
}
}
return $revalidate;
} | [
"protected",
"function",
"createRevalidationRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"revalidate",
"=",
"clone",
"$",
"request",
";",
"$",
"revalidate",
"->",
"removeHeader",
"(",
"'Pragma'",
")",
"->",
... | Creates a request to use for revalidation
@param RequestInterface $request Request
@param Response $response Response to revalidate
@return RequestInterface returns a revalidation request | [
"Creates",
"a",
"request",
"to",
"use",
"for",
"revalidation"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultRevalidation.php#L95-L119 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultRevalidation.php | DefaultRevalidation.handle200Response | protected function handle200Response(RequestInterface $request, Response $validateResponse)
{
$request->setResponse($validateResponse);
if ($this->canCache->canCacheResponse($validateResponse)) {
$this->storage->cache($request, $validateResponse);
}
return false;
} | php | protected function handle200Response(RequestInterface $request, Response $validateResponse)
{
$request->setResponse($validateResponse);
if ($this->canCache->canCacheResponse($validateResponse)) {
$this->storage->cache($request, $validateResponse);
}
return false;
} | [
"protected",
"function",
"handle200Response",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"validateResponse",
")",
"{",
"$",
"request",
"->",
"setResponse",
"(",
"$",
"validateResponse",
")",
";",
"if",
"(",
"$",
"this",
"->",
"canCache",
"-... | Handles a 200 response response from revalidating. The server does not support validation, so use this response.
@param RequestInterface $request Request that was sent
@param Response $validateResponse Response received
@return bool Returns true if valid, false if invalid | [
"Handles",
"a",
"200",
"response",
"response",
"from",
"revalidating",
".",
"The",
"server",
"does",
"not",
"support",
"validation",
"so",
"use",
"this",
"response",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultRevalidation.php#L129-L137 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/DefaultRevalidation.php | DefaultRevalidation.handle304Response | protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
{
static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');
// Make sure that this response has the same ETag
if ($validateResponse->getEtag() != $response->getEtag()) {
return false;
}
// Replace cached headers with any of these headers from the
// origin server that might be more up to date
$modified = false;
foreach ($replaceHeaders as $name) {
if ($validateResponse->hasHeader($name)) {
$modified = true;
$response->setHeader($name, $validateResponse->getHeader($name));
}
}
// Store the updated response in cache
if ($modified && $this->canCache->canCacheResponse($response)) {
$this->storage->cache($request, $response);
}
return true;
} | php | protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
{
static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');
// Make sure that this response has the same ETag
if ($validateResponse->getEtag() != $response->getEtag()) {
return false;
}
// Replace cached headers with any of these headers from the
// origin server that might be more up to date
$modified = false;
foreach ($replaceHeaders as $name) {
if ($validateResponse->hasHeader($name)) {
$modified = true;
$response->setHeader($name, $validateResponse->getHeader($name));
}
}
// Store the updated response in cache
if ($modified && $this->canCache->canCacheResponse($response)) {
$this->storage->cache($request, $response);
}
return true;
} | [
"protected",
"function",
"handle304Response",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"validateResponse",
",",
"Response",
"$",
"response",
")",
"{",
"static",
"$",
"replaceHeaders",
"=",
"array",
"(",
"'Date'",
",",
"'Expires'",
",",
"'Ca... | Handle a 304 response and ensure that it is still valid
@param RequestInterface $request Request that was sent
@param Response $validateResponse Response received
@param Response $response Original cached response
@return bool Returns true if valid, false if invalid | [
"Handle",
"a",
"304",
"response",
"and",
"ensure",
"that",
"it",
"is",
"still",
"valid"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/DefaultRevalidation.php#L148-L173 | train |
guzzle/guzzle3 | src/Guzzle/Http/Exception/MultiTransferException.php | MultiTransferException.addFailedRequestWithException | public function addFailedRequestWithException(RequestInterface $request, \Exception $exception)
{
$this->add($exception)
->addFailedRequest($request)
->exceptionForRequest[spl_object_hash($request)] = $exception;
return $this;
} | php | public function addFailedRequestWithException(RequestInterface $request, \Exception $exception)
{
$this->add($exception)
->addFailedRequest($request)
->exceptionForRequest[spl_object_hash($request)] = $exception;
return $this;
} | [
"public",
"function",
"addFailedRequestWithException",
"(",
"RequestInterface",
"$",
"request",
",",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"exception",
")",
"->",
"addFailedRequest",
"(",
"$",
"request",
")",
"->",
... | Add to the array of failed requests and associate with exceptions
@param RequestInterface $request Failed request
@param \Exception $exception Exception to add and associate with
@return self | [
"Add",
"to",
"the",
"array",
"of",
"failed",
"requests",
"and",
"associate",
"with",
"exceptions"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Exception/MultiTransferException.php#L63-L70 | train |
guzzle/guzzle3 | src/Guzzle/Http/Exception/MultiTransferException.php | MultiTransferException.containsRequest | public function containsRequest(RequestInterface $request)
{
return in_array($request, $this->failedRequests, true) || in_array($request, $this->successfulRequests, true);
} | php | public function containsRequest(RequestInterface $request)
{
return in_array($request, $this->failedRequests, true) || in_array($request, $this->successfulRequests, true);
} | [
"public",
"function",
"containsRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"return",
"in_array",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"failedRequests",
",",
"true",
")",
"||",
"in_array",
"(",
"$",
"request",
",",
"$",
"this",
"->"... | Check if the exception object contains a request
@param RequestInterface $request Request to check
@return bool | [
"Check",
"if",
"the",
"exception",
"object",
"contains",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Exception/MultiTransferException.php#L141-L144 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Async/AsyncPlugin.php | AsyncPlugin.onCurlProgress | public function onCurlProgress(Event $event)
{
if ($event['handle'] &&
($event['downloaded'] || (isset($event['uploaded']) && $event['upload_size'] === $event['uploaded']))
) {
// Timeout after 1ms
curl_setopt($event['handle'], CURLOPT_TIMEOUT_MS, 1);
// Even if the response is quick, tell curl not to download the body.
// - Note that we can only perform this shortcut if the request transmitted a body so as to ensure that the
// request method is not converted to a HEAD request before the request was sent via curl.
if ($event['uploaded']) {
curl_setopt($event['handle'], CURLOPT_NOBODY, true);
}
}
} | php | public function onCurlProgress(Event $event)
{
if ($event['handle'] &&
($event['downloaded'] || (isset($event['uploaded']) && $event['upload_size'] === $event['uploaded']))
) {
// Timeout after 1ms
curl_setopt($event['handle'], CURLOPT_TIMEOUT_MS, 1);
// Even if the response is quick, tell curl not to download the body.
// - Note that we can only perform this shortcut if the request transmitted a body so as to ensure that the
// request method is not converted to a HEAD request before the request was sent via curl.
if ($event['uploaded']) {
curl_setopt($event['handle'], CURLOPT_NOBODY, true);
}
}
} | [
"public",
"function",
"onCurlProgress",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"[",
"'handle'",
"]",
"&&",
"(",
"$",
"event",
"[",
"'downloaded'",
"]",
"||",
"(",
"isset",
"(",
"$",
"event",
"[",
"'uploaded'",
"]",
")",
"&&",
... | Event emitted when a curl progress function is called. When the amount of data uploaded == the amount of data to
upload OR any bytes have been downloaded, then time the request out after 1ms because we're done with
transmitting the request, and tell curl not download a body.
@param Event $event | [
"Event",
"emitted",
"when",
"a",
"curl",
"progress",
"function",
"is",
"called",
".",
"When",
"the",
"amount",
"of",
"data",
"uploaded",
"==",
"the",
"amount",
"of",
"data",
"to",
"upload",
"OR",
"any",
"bytes",
"have",
"been",
"downloaded",
"then",
"time"... | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Async/AsyncPlugin.php#L43-L57 | train |
guzzle/guzzle3 | src/Guzzle/Http/QueryString.php | QueryString.setAggregator | public function setAggregator(QueryAggregatorInterface $aggregator = null)
{
// Use the default aggregator if none was set
if (!$aggregator) {
if (!self::$defaultAggregator) {
self::$defaultAggregator = new PhpAggregator();
}
$aggregator = self::$defaultAggregator;
}
$this->aggregator = $aggregator;
return $this;
} | php | public function setAggregator(QueryAggregatorInterface $aggregator = null)
{
// Use the default aggregator if none was set
if (!$aggregator) {
if (!self::$defaultAggregator) {
self::$defaultAggregator = new PhpAggregator();
}
$aggregator = self::$defaultAggregator;
}
$this->aggregator = $aggregator;
return $this;
} | [
"public",
"function",
"setAggregator",
"(",
"QueryAggregatorInterface",
"$",
"aggregator",
"=",
"null",
")",
"{",
"// Use the default aggregator if none was set",
"if",
"(",
"!",
"$",
"aggregator",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"defaultAggregator",
... | Provide a function for combining multi-valued query string parameters into a single or multiple fields
@param null|QueryAggregatorInterface $aggregator Pass in a QueryAggregatorInterface object to handle converting
deeply nested query string variables into a flattened array.
Pass null to use the default PHP style aggregator. For legacy
reasons, this function accepts a callable that must accepts a
$key, $value, and query object.
@return self
@see \Guzzle\Http\QueryString::aggregateUsingComma() | [
"Provide",
"a",
"function",
"for",
"combining",
"multi",
"-",
"valued",
"query",
"string",
"parameters",
"into",
"a",
"single",
"or",
"multiple",
"fields"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/QueryString.php#L160-L173 | train |
guzzle/guzzle3 | src/Guzzle/Http/QueryString.php | QueryString.useUrlEncoding | public function useUrlEncoding($encode)
{
$this->urlEncode = ($encode === true) ? self::RFC_3986 : $encode;
return $this;
} | php | public function useUrlEncoding($encode)
{
$this->urlEncode = ($encode === true) ? self::RFC_3986 : $encode;
return $this;
} | [
"public",
"function",
"useUrlEncoding",
"(",
"$",
"encode",
")",
"{",
"$",
"this",
"->",
"urlEncode",
"=",
"(",
"$",
"encode",
"===",
"true",
")",
"?",
"self",
"::",
"RFC_3986",
":",
"$",
"encode",
";",
"return",
"$",
"this",
";",
"}"
] | Set whether or not field names and values should be rawurlencoded
@param bool|string $encode Set to TRUE to use RFC 3986 encoding (rawurlencode), false to disable encoding, or
form_urlencoding to use application/x-www-form-urlencoded encoding (urlencode)
@return self | [
"Set",
"whether",
"or",
"not",
"field",
"names",
"and",
"values",
"should",
"be",
"rawurlencoded"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/QueryString.php#L182-L187 | train |
guzzle/guzzle3 | src/Guzzle/Http/QueryString.php | QueryString.encodeValue | public function encodeValue($value)
{
if ($this->urlEncode == self::RFC_3986) {
return rawurlencode($value);
} elseif ($this->urlEncode == self::FORM_URLENCODED) {
return urlencode($value);
} else {
return (string) $value;
}
} | php | public function encodeValue($value)
{
if ($this->urlEncode == self::RFC_3986) {
return rawurlencode($value);
} elseif ($this->urlEncode == self::FORM_URLENCODED) {
return urlencode($value);
} else {
return (string) $value;
}
} | [
"public",
"function",
"encodeValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"urlEncode",
"==",
"self",
"::",
"RFC_3986",
")",
"{",
"return",
"rawurlencode",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"urlE... | URL encodes a value based on the url encoding type of the query string object
@param string $value Value to encode
@return string | [
"URL",
"encodes",
"a",
"value",
"based",
"on",
"the",
"url",
"encoding",
"type",
"of",
"the",
"query",
"string",
"object"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/QueryString.php#L234-L243 | train |
guzzle/guzzle3 | src/Guzzle/Http/QueryString.php | QueryString.prepareData | protected function prepareData(array $data)
{
// If no aggregator is present then set the default
if (!$this->aggregator) {
$this->setAggregator(null);
}
$temp = array();
foreach ($data as $key => $value) {
if ($value === false || $value === null) {
// False and null will not include the "=". Use an empty string to include the "=".
$temp[$this->encodeValue($key)] = $value;
} elseif (is_array($value)) {
$temp = array_merge($temp, $this->aggregator->aggregate($key, $value, $this));
} else {
$temp[$this->encodeValue($key)] = $this->encodeValue($value);
}
}
return $temp;
} | php | protected function prepareData(array $data)
{
// If no aggregator is present then set the default
if (!$this->aggregator) {
$this->setAggregator(null);
}
$temp = array();
foreach ($data as $key => $value) {
if ($value === false || $value === null) {
// False and null will not include the "=". Use an empty string to include the "=".
$temp[$this->encodeValue($key)] = $value;
} elseif (is_array($value)) {
$temp = array_merge($temp, $this->aggregator->aggregate($key, $value, $this));
} else {
$temp[$this->encodeValue($key)] = $this->encodeValue($value);
}
}
return $temp;
} | [
"protected",
"function",
"prepareData",
"(",
"array",
"$",
"data",
")",
"{",
"// If no aggregator is present then set the default",
"if",
"(",
"!",
"$",
"this",
"->",
"aggregator",
")",
"{",
"$",
"this",
"->",
"setAggregator",
"(",
"null",
")",
";",
"}",
"$",
... | Url encode parameter data and convert nested query strings into a flattened hash.
@param array $data The data to encode
@return array Returns an array of encoded values and keys | [
"Url",
"encode",
"parameter",
"data",
"and",
"convert",
"nested",
"query",
"strings",
"into",
"a",
"flattened",
"hash",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/QueryString.php#L252-L272 | train |
guzzle/guzzle3 | src/Guzzle/Http/QueryString.php | QueryString.convertKvp | private function convertKvp($name, $value)
{
if ($value === self::BLANK || $value === null || $value === false) {
return $name;
} elseif (!is_array($value)) {
return $name . $this->valueSeparator . $value;
}
$result = '';
foreach ($value as $v) {
$result .= $this->convertKvp($name, $v) . $this->fieldSeparator;
}
return rtrim($result, $this->fieldSeparator);
} | php | private function convertKvp($name, $value)
{
if ($value === self::BLANK || $value === null || $value === false) {
return $name;
} elseif (!is_array($value)) {
return $name . $this->valueSeparator . $value;
}
$result = '';
foreach ($value as $v) {
$result .= $this->convertKvp($name, $v) . $this->fieldSeparator;
}
return rtrim($result, $this->fieldSeparator);
} | [
"private",
"function",
"convertKvp",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"self",
"::",
"BLANK",
"||",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"false",
")",
"{",
"return",
"$",
"name",
";",
... | Converts a key value pair that can contain strings, nulls, false, or arrays
into a single string.
@param string $name Name of the field
@param mixed $value Value of the field
@return string | [
"Converts",
"a",
"key",
"value",
"pair",
"that",
"can",
"contain",
"strings",
"nulls",
"false",
"or",
"arrays",
"into",
"a",
"single",
"string",
"."
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/QueryString.php#L282-L296 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/AbstractCommand.php | AbstractCommand.process | protected function process()
{
$this->result = $this[self::RESPONSE_PROCESSING] != self::TYPE_RAW
? DefaultResponseParser::getInstance()->parse($this)
: $this->request->getResponse();
} | php | protected function process()
{
$this->result = $this[self::RESPONSE_PROCESSING] != self::TYPE_RAW
? DefaultResponseParser::getInstance()->parse($this)
: $this->request->getResponse();
} | [
"protected",
"function",
"process",
"(",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"$",
"this",
"[",
"self",
"::",
"RESPONSE_PROCESSING",
"]",
"!=",
"self",
"::",
"TYPE_RAW",
"?",
"DefaultResponseParser",
"::",
"getInstance",
"(",
")",
"->",
"parse",
"("... | Create the result of the command after the request has been completed.
Override this method in subclasses to customize this behavior | [
"Create",
"the",
"result",
"of",
"the",
"command",
"after",
"the",
"request",
"has",
"been",
"completed",
".",
"Override",
"this",
"method",
"in",
"subclasses",
"to",
"customize",
"this",
"behavior"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/AbstractCommand.php#L307-L312 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/AbstractCommand.php | AbstractCommand.validate | protected function validate()
{
// Do not perform request validation/transformation if it is disable
if ($this[self::DISABLE_VALIDATION]) {
return;
}
$errors = array();
$validator = $this->getValidator();
foreach ($this->operation->getParams() as $name => $schema) {
$value = $this[$name];
if (!$validator->validate($schema, $value)) {
$errors = array_merge($errors, $validator->getErrors());
} elseif ($value !== $this[$name]) {
// Update the config value if it changed and no validation errors were encountered
$this->data[$name] = $value;
}
}
// Validate additional parameters
$hidden = $this[self::HIDDEN_PARAMS];
if ($properties = $this->operation->getAdditionalParameters()) {
foreach ($this->toArray() as $name => $value) {
// It's only additional if it isn't defined in the schema
if (!$this->operation->hasParam($name) && !in_array($name, $hidden)) {
// Always set the name so that error messages are useful
$properties->setName($name);
if (!$validator->validate($properties, $value)) {
$errors = array_merge($errors, $validator->getErrors());
} elseif ($value !== $this[$name]) {
$this->data[$name] = $value;
}
}
}
}
if (!empty($errors)) {
$e = new ValidationException('Validation errors: ' . implode("\n", $errors));
$e->setErrors($errors);
throw $e;
}
} | php | protected function validate()
{
// Do not perform request validation/transformation if it is disable
if ($this[self::DISABLE_VALIDATION]) {
return;
}
$errors = array();
$validator = $this->getValidator();
foreach ($this->operation->getParams() as $name => $schema) {
$value = $this[$name];
if (!$validator->validate($schema, $value)) {
$errors = array_merge($errors, $validator->getErrors());
} elseif ($value !== $this[$name]) {
// Update the config value if it changed and no validation errors were encountered
$this->data[$name] = $value;
}
}
// Validate additional parameters
$hidden = $this[self::HIDDEN_PARAMS];
if ($properties = $this->operation->getAdditionalParameters()) {
foreach ($this->toArray() as $name => $value) {
// It's only additional if it isn't defined in the schema
if (!$this->operation->hasParam($name) && !in_array($name, $hidden)) {
// Always set the name so that error messages are useful
$properties->setName($name);
if (!$validator->validate($properties, $value)) {
$errors = array_merge($errors, $validator->getErrors());
} elseif ($value !== $this[$name]) {
$this->data[$name] = $value;
}
}
}
}
if (!empty($errors)) {
$e = new ValidationException('Validation errors: ' . implode("\n", $errors));
$e->setErrors($errors);
throw $e;
}
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"// Do not perform request validation/transformation if it is disable",
"if",
"(",
"$",
"this",
"[",
"self",
"::",
"DISABLE_VALIDATION",
"]",
")",
"{",
"return",
";",
"}",
"$",
"errors",
"=",
"array",
"(",
")",
... | Validate and prepare the command based on the schema and rules defined by the command's Operation object
@throws ValidationException when validation errors occur | [
"Validate",
"and",
"prepare",
"the",
"command",
"based",
"on",
"the",
"schema",
"and",
"rules",
"defined",
"by",
"the",
"command",
"s",
"Operation",
"object"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/AbstractCommand.php#L319-L361 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php | VisitorFlyweight.getKey | private function getKey($key)
{
if (!isset($this->cache[$key])) {
if (!isset($this->mappings[$key])) {
list($type, $name) = explode('.', $key);
throw new InvalidArgumentException("No {$type} visitor has been mapped for {$name}");
}
$this->cache[$key] = new $this->mappings[$key];
}
return $this->cache[$key];
} | php | private function getKey($key)
{
if (!isset($this->cache[$key])) {
if (!isset($this->mappings[$key])) {
list($type, $name) = explode('.', $key);
throw new InvalidArgumentException("No {$type} visitor has been mapped for {$name}");
}
$this->cache[$key] = new $this->mappings[$key];
}
return $this->cache[$key];
} | [
"private",
"function",
"getKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
")",... | Get a visitor by key value name
@param string $key Key name to retrieve
@return mixed
@throws InvalidArgumentException | [
"Get",
"a",
"visitor",
"by",
"key",
"value",
"name"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php#L126-L137 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlVersion.php | CurlVersion.get | public function get($type)
{
$version = $this->getAll();
return isset($version[$type]) ? $version[$type] : false;
} | php | public function get($type)
{
$version = $this->getAll();
return isset($version[$type]) ? $version[$type] : false;
} | [
"public",
"function",
"get",
"(",
"$",
"type",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"version",
"[",
"$",
"type",
"]",
")",
"?",
"$",
"version",
"[",
"$",
"type",
"]",
":",
"fals... | Get a specific type of curl information
@param string $type Version information to retrieve. This value is one of:
- version_number: cURL 24 bit version number
- version: cURL version number, as a string
- ssl_version_number: OpenSSL 24 bit version number
- ssl_version: OpenSSL version number, as a string
- libz_version: zlib version number, as a string
- host: Information about the host where cURL was built
- features: A bitmask of the CURL_VERSION_XXX constants
- protocols: An array of protocols names supported by cURL
@return string|float|bool if the $type is found, and false if not found | [
"Get",
"a",
"specific",
"type",
"of",
"curl",
"information"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlVersion.php#L60-L65 | train |
guzzle/guzzle3 | src/Guzzle/Service/Client.php | Client.executeMultiple | protected function executeMultiple($commands)
{
$requests = array();
$commandRequests = new \SplObjectStorage();
foreach ($commands as $command) {
$request = $this->prepareCommand($command);
$commandRequests[$request] = $command;
$requests[] = $request;
}
try {
$this->send($requests);
foreach ($commands as $command) {
$this->dispatch('command.after_send', array('command' => $command));
}
return $commands;
} catch (MultiTransferException $failureException) {
// Throw a CommandTransferException using the successful and failed commands
$e = CommandTransferException::fromMultiTransferException($failureException);
// Remove failed requests from the successful requests array and add to the failures array
foreach ($failureException->getFailedRequests() as $request) {
if (isset($commandRequests[$request])) {
$e->addFailedCommand($commandRequests[$request]);
unset($commandRequests[$request]);
}
}
// Always emit the command after_send events for successful commands
foreach ($commandRequests as $success) {
$e->addSuccessfulCommand($commandRequests[$success]);
$this->dispatch('command.after_send', array('command' => $commandRequests[$success]));
}
throw $e;
}
} | php | protected function executeMultiple($commands)
{
$requests = array();
$commandRequests = new \SplObjectStorage();
foreach ($commands as $command) {
$request = $this->prepareCommand($command);
$commandRequests[$request] = $command;
$requests[] = $request;
}
try {
$this->send($requests);
foreach ($commands as $command) {
$this->dispatch('command.after_send', array('command' => $command));
}
return $commands;
} catch (MultiTransferException $failureException) {
// Throw a CommandTransferException using the successful and failed commands
$e = CommandTransferException::fromMultiTransferException($failureException);
// Remove failed requests from the successful requests array and add to the failures array
foreach ($failureException->getFailedRequests() as $request) {
if (isset($commandRequests[$request])) {
$e->addFailedCommand($commandRequests[$request]);
unset($commandRequests[$request]);
}
}
// Always emit the command after_send events for successful commands
foreach ($commandRequests as $success) {
$e->addSuccessfulCommand($commandRequests[$success]);
$this->dispatch('command.after_send', array('command' => $commandRequests[$success]));
}
throw $e;
}
} | [
"protected",
"function",
"executeMultiple",
"(",
"$",
"commands",
")",
"{",
"$",
"requests",
"=",
"array",
"(",
")",
";",
"$",
"commandRequests",
"=",
"new",
"\\",
"SplObjectStorage",
"(",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
... | Execute multiple commands in parallel
@param array|Traversable $commands Array of CommandInterface objects to execute
@return array Returns an array of the executed commands
@throws Exception\CommandTransferException | [
"Execute",
"multiple",
"commands",
"in",
"parallel"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Client.php#L221-L258 | train |
guzzle/guzzle3 | src/Guzzle/Service/Client.php | Client.getCommandFactory | protected function getCommandFactory()
{
if (!$this->commandFactory) {
$this->commandFactory = CompositeFactory::getDefaultChain($this);
}
return $this->commandFactory;
} | php | protected function getCommandFactory()
{
if (!$this->commandFactory) {
$this->commandFactory = CompositeFactory::getDefaultChain($this);
}
return $this->commandFactory;
} | [
"protected",
"function",
"getCommandFactory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"commandFactory",
")",
"{",
"$",
"this",
"->",
"commandFactory",
"=",
"CompositeFactory",
"::",
"getDefaultChain",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$... | Get the command factory associated with the client
@return CommandFactoryInterface | [
"Get",
"the",
"command",
"factory",
"associated",
"with",
"the",
"client"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Client.php#L280-L287 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Mock/MockPlugin.php | MockPlugin.getMockFile | public static function getMockFile($path)
{
if (!file_exists($path)) {
throw new InvalidArgumentException('Unable to open mock file: ' . $path);
}
return Response::fromMessage(file_get_contents($path));
} | php | public static function getMockFile($path)
{
if (!file_exists($path)) {
throw new InvalidArgumentException('Unable to open mock file: ' . $path);
}
return Response::fromMessage(file_get_contents($path));
} | [
"public",
"static",
"function",
"getMockFile",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unable to open mock file: '",
".",
"$",
"path",
")",
";",
"}",
"re... | Get a mock response from a file
@param string $path File to retrieve a mock response from
@return Response
@throws InvalidArgumentException if the file is not found | [
"Get",
"a",
"mock",
"response",
"from",
"a",
"file"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Mock/MockPlugin.php#L70-L77 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Mock/MockPlugin.php | MockPlugin.dequeue | public function dequeue(RequestInterface $request)
{
$this->dispatch('mock.request', array('plugin' => $this, 'request' => $request));
$item = array_shift($this->queue);
if ($item instanceof Response) {
if ($this->readBodies && $request instanceof EntityEnclosingRequestInterface) {
$request->getEventDispatcher()->addListener('request.sent', $f = function (Event $event) use (&$f) {
while ($data = $event['request']->getBody()->read(8096));
// Remove the listener after one-time use
$event['request']->getEventDispatcher()->removeListener('request.sent', $f);
});
}
$request->setResponse($item);
} elseif ($item instanceof CurlException) {
// Emulates exceptions encountered while transferring requests
$item->setRequest($request);
$state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $item));
// Only throw if the exception wasn't handled
if ($state == RequestInterface::STATE_ERROR) {
throw $item;
}
}
return $this;
} | php | public function dequeue(RequestInterface $request)
{
$this->dispatch('mock.request', array('plugin' => $this, 'request' => $request));
$item = array_shift($this->queue);
if ($item instanceof Response) {
if ($this->readBodies && $request instanceof EntityEnclosingRequestInterface) {
$request->getEventDispatcher()->addListener('request.sent', $f = function (Event $event) use (&$f) {
while ($data = $event['request']->getBody()->read(8096));
// Remove the listener after one-time use
$event['request']->getEventDispatcher()->removeListener('request.sent', $f);
});
}
$request->setResponse($item);
} elseif ($item instanceof CurlException) {
// Emulates exceptions encountered while transferring requests
$item->setRequest($request);
$state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $item));
// Only throw if the exception wasn't handled
if ($state == RequestInterface::STATE_ERROR) {
throw $item;
}
}
return $this;
} | [
"public",
"function",
"dequeue",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"dispatch",
"(",
"'mock.request'",
",",
"array",
"(",
"'plugin'",
"=>",
"$",
"this",
",",
"'request'",
"=>",
"$",
"request",
")",
")",
";",
"$",
"item"... | Get a response from the front of the list and add it to a request
@param RequestInterface $request Request to mock
@return self
@throws CurlException When request.send is called and an exception is queued | [
"Get",
"a",
"response",
"from",
"the",
"front",
"of",
"the",
"list",
"and",
"add",
"it",
"to",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Mock/MockPlugin.php#L180-L205 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Mock/MockPlugin.php | MockPlugin.onRequestBeforeSend | public function onRequestBeforeSend(Event $event)
{
if (!$this->queue) {
throw new \OutOfBoundsException('Mock queue is empty');
}
$request = $event['request'];
$this->received[] = $request;
// Detach the filter from the client so it's a one-time use
if ($this->temporary && count($this->queue) == 1 && $request->getClient()) {
$request->getClient()->getEventDispatcher()->removeSubscriber($this);
}
$this->dequeue($request);
} | php | public function onRequestBeforeSend(Event $event)
{
if (!$this->queue) {
throw new \OutOfBoundsException('Mock queue is empty');
}
$request = $event['request'];
$this->received[] = $request;
// Detach the filter from the client so it's a one-time use
if ($this->temporary && count($this->queue) == 1 && $request->getClient()) {
$request->getClient()->getEventDispatcher()->removeSubscriber($this);
}
$this->dequeue($request);
} | [
"public",
"function",
"onRequestBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Mock queue is empty'",
")",
";",
"}",
"$",
"request",
"=",
"$",
... | Called when a request is about to be sent
@param Event $event
@throws \OutOfBoundsException When queue is empty | [
"Called",
"when",
"a",
"request",
"is",
"about",
"to",
"be",
"sent"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Mock/MockPlugin.php#L231-L244 | train |
guzzle/guzzle3 | src/Guzzle/Batch/BatchBuilder.php | BatchBuilder.build | public function build()
{
if (!$this->transferStrategy) {
throw new RuntimeException('No transfer strategy has been specified');
}
if (!$this->divisorStrategy) {
throw new RuntimeException('No divisor strategy has been specified');
}
$batch = new Batch($this->transferStrategy, $this->divisorStrategy);
if ($this->exceptionBuffering) {
$batch = new ExceptionBufferingBatch($batch);
}
if ($this->afterFlush) {
$batch = new NotifyingBatch($batch, $this->afterFlush);
}
if ($this->autoFlush) {
$batch = new FlushingBatch($batch, $this->autoFlush);
}
if ($this->history) {
$batch = new HistoryBatch($batch);
}
return $batch;
} | php | public function build()
{
if (!$this->transferStrategy) {
throw new RuntimeException('No transfer strategy has been specified');
}
if (!$this->divisorStrategy) {
throw new RuntimeException('No divisor strategy has been specified');
}
$batch = new Batch($this->transferStrategy, $this->divisorStrategy);
if ($this->exceptionBuffering) {
$batch = new ExceptionBufferingBatch($batch);
}
if ($this->afterFlush) {
$batch = new NotifyingBatch($batch, $this->afterFlush);
}
if ($this->autoFlush) {
$batch = new FlushingBatch($batch, $this->autoFlush);
}
if ($this->history) {
$batch = new HistoryBatch($batch);
}
return $batch;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"transferStrategy",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'No transfer strategy has been specified'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"divisorStr... | Create and return the instantiated batch
@return BatchInterface
@throws RuntimeException if no transfer strategy has been specified | [
"Create",
"and",
"return",
"the",
"instantiated",
"batch"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Batch/BatchBuilder.php#L169-L198 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/Link.php | Link.addLink | public function addLink($url, $rel, array $params = array())
{
$values = array("<{$url}>", "rel=\"{$rel}\"");
foreach ($params as $k => $v) {
$values[] = "{$k}=\"{$v}\"";
}
return $this->add(implode('; ', $values));
} | php | public function addLink($url, $rel, array $params = array())
{
$values = array("<{$url}>", "rel=\"{$rel}\"");
foreach ($params as $k => $v) {
$values[] = "{$k}=\"{$v}\"";
}
return $this->add(implode('; ', $values));
} | [
"public",
"function",
"addLink",
"(",
"$",
"url",
",",
"$",
"rel",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"values",
"=",
"array",
"(",
"\"<{$url}>\"",
",",
"\"rel=\\\"{$rel}\\\"\"",
")",
";",
"foreach",
"(",
"$",
"params",
... | Add a link to the header
@param string $url Link URL
@param string $rel Link rel
@param array $params Other link parameters
@return self | [
"Add",
"a",
"link",
"to",
"the",
"header"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/Link.php#L21-L30 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/Link.php | Link.getLink | public function getLink($rel)
{
foreach ($this->getLinks() as $link) {
if (isset($link['rel']) && $link['rel'] == $rel) {
return $link;
}
}
return null;
} | php | public function getLink($rel)
{
foreach ($this->getLinks() as $link) {
if (isset($link['rel']) && $link['rel'] == $rel) {
return $link;
}
}
return null;
} | [
"public",
"function",
"getLink",
"(",
"$",
"rel",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getLinks",
"(",
")",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"link",
"[",
"'rel'",
"]",
")",
"&&",
"$",
"link",
"[",
"'rel'",
"]"... | Get a specific link for a given rel attribute
@param string $rel Rel value
@return array|null | [
"Get",
"a",
"specific",
"link",
"for",
"a",
"given",
"rel",
"attribute"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/Link.php#L51-L60 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/Header/Link.php | Link.getLinks | public function getLinks()
{
$links = $this->parseParams();
foreach ($links as &$link) {
$key = key($link);
unset($link[$key]);
$link['url'] = trim($key, '<> ');
}
return $links;
} | php | public function getLinks()
{
$links = $this->parseParams();
foreach ($links as &$link) {
$key = key($link);
unset($link[$key]);
$link['url'] = trim($key, '<> ');
}
return $links;
} | [
"public",
"function",
"getLinks",
"(",
")",
"{",
"$",
"links",
"=",
"$",
"this",
"->",
"parseParams",
"(",
")",
";",
"foreach",
"(",
"$",
"links",
"as",
"&",
"$",
"link",
")",
"{",
"$",
"key",
"=",
"key",
"(",
"$",
"link",
")",
";",
"unset",
"(... | Get an associative array of links
For example:
Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"
<code>
var_export($response->getLinks());
array(
array(
'url' => 'http:/.../front.jpeg',
'rel' => 'back',
'type' => 'image/jpeg',
)
)
</code>
@return array | [
"Get",
"an",
"associative",
"array",
"of",
"links"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/Header/Link.php#L81-L92 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlHandle.php | CurlHandle.getErrorNo | public function getErrorNo()
{
if ($this->errorNo) {
return $this->errorNo;
}
return $this->isAvailable() ? curl_errno($this->handle) : CURLE_OK;
} | php | public function getErrorNo()
{
if ($this->errorNo) {
return $this->errorNo;
}
return $this->isAvailable() ? curl_errno($this->handle) : CURLE_OK;
} | [
"public",
"function",
"getErrorNo",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"errorNo",
")",
"{",
"return",
"$",
"this",
"->",
"errorNo",
";",
"}",
"return",
"$",
"this",
"->",
"isAvailable",
"(",
")",
"?",
"curl_errno",
"(",
"$",
"this",
"->",
... | Get the last error number that occurred on the cURL handle
@return int | [
"Get",
"the",
"last",
"error",
"number",
"that",
"occurred",
"on",
"the",
"cURL",
"handle"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlHandle.php#L293-L300 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlHandle.php | CurlHandle.getStderr | public function getStderr($asResource = false)
{
$stderr = $this->getOptions()->get(CURLOPT_STDERR);
if (!$stderr) {
return null;
}
if ($asResource) {
return $stderr;
}
fseek($stderr, 0);
$e = stream_get_contents($stderr);
fseek($stderr, 0, SEEK_END);
return $e;
} | php | public function getStderr($asResource = false)
{
$stderr = $this->getOptions()->get(CURLOPT_STDERR);
if (!$stderr) {
return null;
}
if ($asResource) {
return $stderr;
}
fseek($stderr, 0);
$e = stream_get_contents($stderr);
fseek($stderr, 0, SEEK_END);
return $e;
} | [
"public",
"function",
"getStderr",
"(",
"$",
"asResource",
"=",
"false",
")",
"{",
"$",
"stderr",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"get",
"(",
"CURLOPT_STDERR",
")",
";",
"if",
"(",
"!",
"$",
"stderr",
")",
"{",
"return",
"null",... | Get the stderr output
@param bool $asResource Set to TRUE to get an fopen resource
@return string|resource|null | [
"Get",
"the",
"stderr",
"output"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlHandle.php#L343-L359 | train |
guzzle/guzzle3 | src/Guzzle/Http/Curl/CurlHandle.php | CurlHandle.updateRequestFromTransfer | public function updateRequestFromTransfer(RequestInterface $request)
{
if (!$request->getResponse()) {
return;
}
// Update the transfer stats of the response
$request->getResponse()->setInfo($this->getInfo());
if (!$log = $this->getStderr(true)) {
return;
}
// Parse the cURL stderr output for outgoing requests
$headers = '';
fseek($log, 0);
while (($line = fgets($log)) !== false) {
if ($line && $line[0] == '>') {
$headers = substr(trim($line), 2) . "\r\n";
while (($line = fgets($log)) !== false) {
if ($line[0] == '*' || $line[0] == '<') {
break;
} else {
$headers .= trim($line) . "\r\n";
}
}
}
}
// Add request headers to the request exactly as they were sent
if ($headers) {
$parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($headers);
if (!empty($parsed['headers'])) {
$request->setHeaders(array());
foreach ($parsed['headers'] as $name => $value) {
$request->setHeader($name, $value);
}
}
if (!empty($parsed['version'])) {
$request->setProtocolVersion($parsed['version']);
}
}
} | php | public function updateRequestFromTransfer(RequestInterface $request)
{
if (!$request->getResponse()) {
return;
}
// Update the transfer stats of the response
$request->getResponse()->setInfo($this->getInfo());
if (!$log = $this->getStderr(true)) {
return;
}
// Parse the cURL stderr output for outgoing requests
$headers = '';
fseek($log, 0);
while (($line = fgets($log)) !== false) {
if ($line && $line[0] == '>') {
$headers = substr(trim($line), 2) . "\r\n";
while (($line = fgets($log)) !== false) {
if ($line[0] == '*' || $line[0] == '<') {
break;
} else {
$headers .= trim($line) . "\r\n";
}
}
}
}
// Add request headers to the request exactly as they were sent
if ($headers) {
$parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($headers);
if (!empty($parsed['headers'])) {
$request->setHeaders(array());
foreach ($parsed['headers'] as $name => $value) {
$request->setHeader($name, $value);
}
}
if (!empty($parsed['version'])) {
$request->setProtocolVersion($parsed['version']);
}
}
} | [
"public",
"function",
"updateRequestFromTransfer",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"request",
"->",
"getResponse",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Update the transfer stats of the response",
"$",
"request",
"->",... | Update a request based on the log messages of the CurlHandle
@param RequestInterface $request Request to update | [
"Update",
"a",
"request",
"based",
"on",
"the",
"log",
"messages",
"of",
"the",
"CurlHandle"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Curl/CurlHandle.php#L397-L439 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/ServiceDescription.php | ServiceDescription.addOperation | public function addOperation(OperationInterface $operation)
{
$this->operations[$operation->getName()] = $operation->setServiceDescription($this);
return $this;
} | php | public function addOperation(OperationInterface $operation)
{
$this->operations[$operation->getName()] = $operation->setServiceDescription($this);
return $this;
} | [
"public",
"function",
"addOperation",
"(",
"OperationInterface",
"$",
"operation",
")",
"{",
"$",
"this",
"->",
"operations",
"[",
"$",
"operation",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"operation",
"->",
"setServiceDescription",
"(",
"$",
"this",
")",
... | Add a operation to the service description
@param OperationInterface $operation Operation to add
@return self | [
"Add",
"a",
"operation",
"to",
"the",
"service",
"description"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/ServiceDescription.php#L150-L155 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/ServiceDescription.php | ServiceDescription.fromArray | protected function fromArray(array $config)
{
// Keep a list of default keys used in service descriptions that is later used to determine extra data keys
static $defaultKeys = array('name', 'models', 'apiVersion', 'baseUrl', 'description');
// Pull in the default configuration values
foreach ($defaultKeys as $key) {
if (isset($config[$key])) {
$this->{$key} = $config[$key];
}
}
// Account for the Swagger name for Guzzle's baseUrl
if (isset($config['basePath'])) {
$this->baseUrl = $config['basePath'];
}
// Ensure that the models and operations properties are always arrays
$this->models = (array) $this->models;
$this->operations = (array) $this->operations;
// We want to add operations differently than adding the other properties
$defaultKeys[] = 'operations';
// Create operations for each operation
if (isset($config['operations'])) {
foreach ($config['operations'] as $name => $operation) {
if (!($operation instanceof Operation) && !is_array($operation)) {
throw new InvalidArgumentException('Invalid operation in service description: '
. gettype($operation));
}
$this->operations[$name] = $operation;
}
}
// Get all of the additional properties of the service description and store them in a data array
foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
$this->extraData[$key] = $config[$key];
}
} | php | protected function fromArray(array $config)
{
// Keep a list of default keys used in service descriptions that is later used to determine extra data keys
static $defaultKeys = array('name', 'models', 'apiVersion', 'baseUrl', 'description');
// Pull in the default configuration values
foreach ($defaultKeys as $key) {
if (isset($config[$key])) {
$this->{$key} = $config[$key];
}
}
// Account for the Swagger name for Guzzle's baseUrl
if (isset($config['basePath'])) {
$this->baseUrl = $config['basePath'];
}
// Ensure that the models and operations properties are always arrays
$this->models = (array) $this->models;
$this->operations = (array) $this->operations;
// We want to add operations differently than adding the other properties
$defaultKeys[] = 'operations';
// Create operations for each operation
if (isset($config['operations'])) {
foreach ($config['operations'] as $name => $operation) {
if (!($operation instanceof Operation) && !is_array($operation)) {
throw new InvalidArgumentException('Invalid operation in service description: '
. gettype($operation));
}
$this->operations[$name] = $operation;
}
}
// Get all of the additional properties of the service description and store them in a data array
foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
$this->extraData[$key] = $config[$key];
}
} | [
"protected",
"function",
"fromArray",
"(",
"array",
"$",
"config",
")",
"{",
"// Keep a list of default keys used in service descriptions that is later used to determine extra data keys",
"static",
"$",
"defaultKeys",
"=",
"array",
"(",
"'name'",
",",
"'models'",
",",
"'apiVe... | Initialize the state from an array
@param array $config Configuration data
@throws InvalidArgumentException | [
"Initialize",
"the",
"state",
"from",
"an",
"array"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/ServiceDescription.php#L232-L270 | train |
guzzle/guzzle3 | src/Guzzle/Service/Resource/CompositeResourceIteratorFactory.php | CompositeResourceIteratorFactory.getFactory | protected function getFactory(CommandInterface $command)
{
foreach ($this->factories as $factory) {
if ($factory->canBuild($command)) {
return $factory;
}
}
return false;
} | php | protected function getFactory(CommandInterface $command)
{
foreach ($this->factories as $factory) {
if ($factory->canBuild($command)) {
return $factory;
}
}
return false;
} | [
"protected",
"function",
"getFactory",
"(",
"CommandInterface",
"$",
"command",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"factories",
"as",
"$",
"factory",
")",
"{",
"if",
"(",
"$",
"factory",
"->",
"canBuild",
"(",
"$",
"command",
")",
")",
"{",
"... | Get the factory that matches the command object
@param CommandInterface $command Command retrieving the iterator for
@return ResourceIteratorFactoryInterface|bool | [
"Get",
"the",
"factory",
"that",
"matches",
"the",
"command",
"object"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Resource/CompositeResourceIteratorFactory.php#L57-L66 | train |
guzzle/guzzle3 | src/Guzzle/Service/Resource/ResourceIterator.php | ResourceIterator.calculatePageSize | protected function calculatePageSize()
{
if ($this->limit && $this->iteratedCount + $this->pageSize > $this->limit) {
return 1 + ($this->limit - $this->iteratedCount);
}
return (int) $this->pageSize;
} | php | protected function calculatePageSize()
{
if ($this->limit && $this->iteratedCount + $this->pageSize > $this->limit) {
return 1 + ($this->limit - $this->iteratedCount);
}
return (int) $this->pageSize;
} | [
"protected",
"function",
"calculatePageSize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"limit",
"&&",
"$",
"this",
"->",
"iteratedCount",
"+",
"$",
"this",
"->",
"pageSize",
">",
"$",
"this",
"->",
"limit",
")",
"{",
"return",
"1",
"+",
"(",
"$",... | Returns the value that should be specified for the page size for a request that will maintain any hard limits,
but still honor the specified pageSize if the number of items retrieved + pageSize < hard limit
@return int Returns the page size of the next request. | [
"Returns",
"the",
"value",
"that",
"should",
"be",
"specified",
"for",
"the",
"page",
"size",
"for",
"a",
"request",
"that",
"will",
"maintain",
"any",
"hard",
"limits",
"but",
"still",
"honor",
"the",
"specified",
"pageSize",
"if",
"the",
"number",
"of",
... | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Resource/ResourceIterator.php#L227-L234 | train |
guzzle/guzzle3 | src/Guzzle/Service/Description/SchemaValidator.php | SchemaValidator.determineType | protected function determineType($type, $value)
{
foreach ((array) $type as $t) {
if ($t == 'string' && (is_string($value) || (is_object($value) && method_exists($value, '__toString')))) {
return 'string';
} elseif ($t == 'object' && (is_array($value) || is_object($value))) {
return 'object';
} elseif ($t == 'array' && is_array($value)) {
return 'array';
} elseif ($t == 'integer' && is_integer($value)) {
return 'integer';
} elseif ($t == 'boolean' && is_bool($value)) {
return 'boolean';
} elseif ($t == 'number' && is_numeric($value)) {
return 'number';
} elseif ($t == 'numeric' && is_numeric($value)) {
return 'numeric';
} elseif ($t == 'null' && !$value) {
return 'null';
} elseif ($t == 'any') {
return 'any';
}
}
return false;
} | php | protected function determineType($type, $value)
{
foreach ((array) $type as $t) {
if ($t == 'string' && (is_string($value) || (is_object($value) && method_exists($value, '__toString')))) {
return 'string';
} elseif ($t == 'object' && (is_array($value) || is_object($value))) {
return 'object';
} elseif ($t == 'array' && is_array($value)) {
return 'array';
} elseif ($t == 'integer' && is_integer($value)) {
return 'integer';
} elseif ($t == 'boolean' && is_bool($value)) {
return 'boolean';
} elseif ($t == 'number' && is_numeric($value)) {
return 'number';
} elseif ($t == 'numeric' && is_numeric($value)) {
return 'numeric';
} elseif ($t == 'null' && !$value) {
return 'null';
} elseif ($t == 'any') {
return 'any';
}
}
return false;
} | [
"protected",
"function",
"determineType",
"(",
"$",
"type",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"type",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"$",
"t",
"==",
"'string'",
"&&",
"(",
"is_string",
"(",
"$",
"value",
"... | From the allowable types, determine the type that the variable matches
@param string $type Parameter type
@param mixed $value Value to determine the type
@return string|bool Returns the matching type on | [
"From",
"the",
"allowable",
"types",
"determine",
"the",
"type",
"that",
"the",
"variable",
"matches"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Description/SchemaValidator.php#L265-L290 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.onRequestBeforeSend | public function onRequestBeforeSend(Event $event)
{
$request = $event['request'];
$request->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
if (!$this->canCache->canCacheRequest($request)) {
switch ($request->getMethod()) {
case 'PURGE':
$this->purge($request);
$request->setResponse(new Response(200, array(), 'purged'));
break;
case 'PUT':
case 'POST':
case 'DELETE':
case 'PATCH':
if ($this->autoPurge) {
$this->purge($request);
}
}
return;
}
if ($response = $this->storage->fetch($request)) {
$params = $request->getParams();
$params['cache.lookup'] = true;
$response->setHeader(
'Age',
time() - strtotime($response->getDate() ? : $response->getLastModified() ?: 'now')
);
// Validate that the response satisfies the request
if ($this->canResponseSatisfyRequest($request, $response)) {
if (!isset($params['cache.hit'])) {
$params['cache.hit'] = true;
}
$request->setResponse($response);
}
}
} | php | public function onRequestBeforeSend(Event $event)
{
$request = $event['request'];
$request->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
if (!$this->canCache->canCacheRequest($request)) {
switch ($request->getMethod()) {
case 'PURGE':
$this->purge($request);
$request->setResponse(new Response(200, array(), 'purged'));
break;
case 'PUT':
case 'POST':
case 'DELETE':
case 'PATCH':
if ($this->autoPurge) {
$this->purge($request);
}
}
return;
}
if ($response = $this->storage->fetch($request)) {
$params = $request->getParams();
$params['cache.lookup'] = true;
$response->setHeader(
'Age',
time() - strtotime($response->getDate() ? : $response->getLastModified() ?: 'now')
);
// Validate that the response satisfies the request
if ($this->canResponseSatisfyRequest($request, $response)) {
if (!isset($params['cache.hit'])) {
$params['cache.hit'] = true;
}
$request->setResponse($response);
}
}
} | [
"public",
"function",
"onRequestBeforeSend",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"$",
"request",
"->",
"addHeader",
"(",
"'Via'",
",",
"sprintf",
"(",
"'%s GuzzleCache/%s'",
",",
"$",
"reques... | Check if a response in cache will satisfy the request before sending
@param Event $event | [
"Check",
"if",
"a",
"response",
"in",
"cache",
"will",
"satisfy",
"the",
"request",
"before",
"sending"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L103-L140 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.onRequestSent | public function onRequestSent(Event $event)
{
$request = $event['request'];
$response = $event['response'];
if ($request->getParams()->get('cache.hit') === null &&
$this->canCache->canCacheRequest($request) &&
$this->canCache->canCacheResponse($response)
) {
$this->storage->cache($request, $response);
}
$this->addResponseHeaders($request, $response);
} | php | public function onRequestSent(Event $event)
{
$request = $event['request'];
$response = $event['response'];
if ($request->getParams()->get('cache.hit') === null &&
$this->canCache->canCacheRequest($request) &&
$this->canCache->canCacheResponse($response)
) {
$this->storage->cache($request, $response);
}
$this->addResponseHeaders($request, $response);
} | [
"public",
"function",
"onRequestSent",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"$",
"response",
"=",
"$",
"event",
"[",
"'response'",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"getParams",
... | If possible, store a response in cache after sending
@param Event $event | [
"If",
"possible",
"store",
"a",
"response",
"in",
"cache",
"after",
"sending"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L147-L160 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.onRequestError | public function onRequestError(Event $event)
{
$request = $event['request'];
if (!$this->canCache->canCacheRequest($request)) {
return;
}
if ($response = $this->storage->fetch($request)) {
$response->setHeader(
'Age',
time() - strtotime($response->getLastModified() ? : $response->getDate() ?: 'now')
);
if ($this->canResponseSatisfyFailedRequest($request, $response)) {
$request->getParams()->set('cache.hit', 'error');
$this->addResponseHeaders($request, $response);
$event['response'] = $response;
$event->stopPropagation();
}
}
} | php | public function onRequestError(Event $event)
{
$request = $event['request'];
if (!$this->canCache->canCacheRequest($request)) {
return;
}
if ($response = $this->storage->fetch($request)) {
$response->setHeader(
'Age',
time() - strtotime($response->getLastModified() ? : $response->getDate() ?: 'now')
);
if ($this->canResponseSatisfyFailedRequest($request, $response)) {
$request->getParams()->set('cache.hit', 'error');
$this->addResponseHeaders($request, $response);
$event['response'] = $response;
$event->stopPropagation();
}
}
} | [
"public",
"function",
"onRequestError",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canCache",
"->",
"canCacheRequest",
"(",
"$",
"request",
")",
")",
"{",
"... | If possible, return a cache response on an error
@param Event $event | [
"If",
"possible",
"return",
"a",
"cache",
"response",
"on",
"an",
"error"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L167-L188 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.onRequestException | public function onRequestException(Event $event)
{
if (!$event['exception'] instanceof CurlException) {
return;
}
$request = $event['request'];
if (!$this->canCache->canCacheRequest($request)) {
return;
}
if ($response = $this->storage->fetch($request)) {
$response->setHeader('Age', time() - strtotime($response->getDate() ? : 'now'));
if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
return;
}
$request->getParams()->set('cache.hit', 'error');
$request->setResponse($response);
$this->addResponseHeaders($request, $response);
$event->stopPropagation();
}
} | php | public function onRequestException(Event $event)
{
if (!$event['exception'] instanceof CurlException) {
return;
}
$request = $event['request'];
if (!$this->canCache->canCacheRequest($request)) {
return;
}
if ($response = $this->storage->fetch($request)) {
$response->setHeader('Age', time() - strtotime($response->getDate() ? : 'now'));
if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
return;
}
$request->getParams()->set('cache.hit', 'error');
$request->setResponse($response);
$this->addResponseHeaders($request, $response);
$event->stopPropagation();
}
} | [
"public",
"function",
"onRequestException",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"[",
"'exception'",
"]",
"instanceof",
"CurlException",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]"... | If possible, set a cache response on a cURL exception
@param Event $event
@return null | [
"If",
"possible",
"set",
"a",
"cache",
"response",
"on",
"a",
"cURL",
"exception"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L197-L218 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.canResponseSatisfyRequest | public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
{
$responseAge = $response->calculateAge();
$reqc = $request->getHeader('Cache-Control');
$resc = $response->getHeader('Cache-Control');
// Check the request's max-age header against the age of the response
if ($reqc && $reqc->hasDirective('max-age') &&
$responseAge > $reqc->getDirective('max-age')) {
return false;
}
// Check the response's max-age header
if ($response->isFresh() === false) {
$maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
if (null !== $maxStale) {
if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
return false;
}
} elseif ($resc && $resc->hasDirective('max-age')
&& $responseAge > $resc->getDirective('max-age')
) {
return false;
}
}
if ($this->revalidation->shouldRevalidate($request, $response)) {
try {
return $this->revalidation->revalidate($request, $response);
} catch (CurlException $e) {
$request->getParams()->set('cache.hit', 'error');
return $this->canResponseSatisfyFailedRequest($request, $response);
}
}
return true;
} | php | public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
{
$responseAge = $response->calculateAge();
$reqc = $request->getHeader('Cache-Control');
$resc = $response->getHeader('Cache-Control');
// Check the request's max-age header against the age of the response
if ($reqc && $reqc->hasDirective('max-age') &&
$responseAge > $reqc->getDirective('max-age')) {
return false;
}
// Check the response's max-age header
if ($response->isFresh() === false) {
$maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
if (null !== $maxStale) {
if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
return false;
}
} elseif ($resc && $resc->hasDirective('max-age')
&& $responseAge > $resc->getDirective('max-age')
) {
return false;
}
}
if ($this->revalidation->shouldRevalidate($request, $response)) {
try {
return $this->revalidation->revalidate($request, $response);
} catch (CurlException $e) {
$request->getParams()->set('cache.hit', 'error');
return $this->canResponseSatisfyFailedRequest($request, $response);
}
}
return true;
} | [
"public",
"function",
"canResponseSatisfyRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"responseAge",
"=",
"$",
"response",
"->",
"calculateAge",
"(",
")",
";",
"$",
"reqc",
"=",
"$",
"request",
"->",
"ge... | Check if a cache response satisfies a request's caching constraints
@param RequestInterface $request Request to validate
@param Response $response Response to validate
@return bool | [
"Check",
"if",
"a",
"cache",
"response",
"satisfies",
"a",
"request",
"s",
"caching",
"constraints"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L228-L264 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.canResponseSatisfyFailedRequest | public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
{
$reqc = $request->getHeader('Cache-Control');
$resc = $response->getHeader('Cache-Control');
$requestStaleIfError = $reqc ? $reqc->getDirective('stale-if-error') : null;
$responseStaleIfError = $resc ? $resc->getDirective('stale-if-error') : null;
if (!$requestStaleIfError && !$responseStaleIfError) {
return false;
}
if (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
return false;
}
if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
return false;
}
return true;
} | php | public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
{
$reqc = $request->getHeader('Cache-Control');
$resc = $response->getHeader('Cache-Control');
$requestStaleIfError = $reqc ? $reqc->getDirective('stale-if-error') : null;
$responseStaleIfError = $resc ? $resc->getDirective('stale-if-error') : null;
if (!$requestStaleIfError && !$responseStaleIfError) {
return false;
}
if (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
return false;
}
if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
return false;
}
return true;
} | [
"public",
"function",
"canResponseSatisfyFailedRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"reqc",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Cache-Control'",
")",
";",
"$",
"resc",
"=",
"$",
"respons... | Check if a cache response satisfies a failed request's caching constraints
@param RequestInterface $request Request to validate
@param Response $response Response to validate
@return bool | [
"Check",
"if",
"a",
"cache",
"response",
"satisfies",
"a",
"failed",
"request",
"s",
"caching",
"constraints"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L274-L294 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.purge | public function purge($url)
{
// BC compatibility with previous version that accepted a Request object
$url = $url instanceof RequestInterface ? $url->getUrl() : $url;
$this->storage->purge($url);
} | php | public function purge($url)
{
// BC compatibility with previous version that accepted a Request object
$url = $url instanceof RequestInterface ? $url->getUrl() : $url;
$this->storage->purge($url);
} | [
"public",
"function",
"purge",
"(",
"$",
"url",
")",
"{",
"// BC compatibility with previous version that accepted a Request object",
"$",
"url",
"=",
"$",
"url",
"instanceof",
"RequestInterface",
"?",
"$",
"url",
"->",
"getUrl",
"(",
")",
":",
"$",
"url",
";",
... | Purge all cache entries for a given URL
@param string $url URL to purge | [
"Purge",
"all",
"cache",
"entries",
"for",
"a",
"given",
"URL"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L301-L306 | train |
guzzle/guzzle3 | src/Guzzle/Plugin/Cache/CachePlugin.php | CachePlugin.addResponseHeaders | protected function addResponseHeaders(RequestInterface $request, Response $response)
{
$params = $request->getParams();
$response->setHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
$lookup = ($params['cache.lookup'] === true ? 'HIT' : 'MISS') . ' from GuzzleCache';
if ($header = $response->getHeader('X-Cache-Lookup')) {
// Don't add duplicates
$values = $header->toArray();
$values[] = $lookup;
$response->setHeader('X-Cache-Lookup', array_unique($values));
} else {
$response->setHeader('X-Cache-Lookup', $lookup);
}
if ($params['cache.hit'] === true) {
$xcache = 'HIT from GuzzleCache';
} elseif ($params['cache.hit'] == 'error') {
$xcache = 'HIT_ERROR from GuzzleCache';
} else {
$xcache = 'MISS from GuzzleCache';
}
if ($header = $response->getHeader('X-Cache')) {
// Don't add duplicates
$values = $header->toArray();
$values[] = $xcache;
$response->setHeader('X-Cache', array_unique($values));
} else {
$response->setHeader('X-Cache', $xcache);
}
if ($response->isFresh() === false) {
$response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
if ($params['cache.hit'] === 'error') {
$response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
}
}
} | php | protected function addResponseHeaders(RequestInterface $request, Response $response)
{
$params = $request->getParams();
$response->setHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
$lookup = ($params['cache.lookup'] === true ? 'HIT' : 'MISS') . ' from GuzzleCache';
if ($header = $response->getHeader('X-Cache-Lookup')) {
// Don't add duplicates
$values = $header->toArray();
$values[] = $lookup;
$response->setHeader('X-Cache-Lookup', array_unique($values));
} else {
$response->setHeader('X-Cache-Lookup', $lookup);
}
if ($params['cache.hit'] === true) {
$xcache = 'HIT from GuzzleCache';
} elseif ($params['cache.hit'] == 'error') {
$xcache = 'HIT_ERROR from GuzzleCache';
} else {
$xcache = 'MISS from GuzzleCache';
}
if ($header = $response->getHeader('X-Cache')) {
// Don't add duplicates
$values = $header->toArray();
$values[] = $xcache;
$response->setHeader('X-Cache', array_unique($values));
} else {
$response->setHeader('X-Cache', $xcache);
}
if ($response->isFresh() === false) {
$response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
if ($params['cache.hit'] === 'error') {
$response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
}
}
} | [
"protected",
"function",
"addResponseHeaders",
"(",
"RequestInterface",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"params",
"=",
"$",
"request",
"->",
"getParams",
"(",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Via'",
",",
... | Add the plugin's headers to a response
@param RequestInterface $request Request
@param Response $response Response to add headers to | [
"Add",
"the",
"plugin",
"s",
"headers",
"to",
"a",
"response"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Plugin/Cache/CachePlugin.php#L314-L352 | train |
guzzle/guzzle3 | src/Guzzle/Http/Message/EntityEnclosingRequest.php | EntityEnclosingRequest.processPostFields | protected function processPostFields()
{
if (!$this->postFiles) {
$this->removeHeader('Expect')->setHeader('Content-Type', self::URL_ENCODED);
} else {
$this->setHeader('Content-Type', self::MULTIPART);
if ($this->expectCutoff !== false) {
$this->setHeader('Expect', '100-Continue');
}
}
} | php | protected function processPostFields()
{
if (!$this->postFiles) {
$this->removeHeader('Expect')->setHeader('Content-Type', self::URL_ENCODED);
} else {
$this->setHeader('Content-Type', self::MULTIPART);
if ($this->expectCutoff !== false) {
$this->setHeader('Expect', '100-Continue');
}
}
} | [
"protected",
"function",
"processPostFields",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"postFiles",
")",
"{",
"$",
"this",
"->",
"removeHeader",
"(",
"'Expect'",
")",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"self",
"::",
"URL_ENCODED",
")",... | Determine what type of request should be sent based on post fields | [
"Determine",
"what",
"type",
"of",
"request",
"should",
"be",
"sent",
"based",
"on",
"post",
"fields"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Http/Message/EntityEnclosingRequest.php#L236-L246 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/DefaultRequestSerializer.php | DefaultRequestSerializer.addVisitor | public function addVisitor($location, RequestVisitorInterface $visitor)
{
$this->factory->addRequestVisitor($location, $visitor);
return $this;
} | php | public function addVisitor($location, RequestVisitorInterface $visitor)
{
$this->factory->addRequestVisitor($location, $visitor);
return $this;
} | [
"public",
"function",
"addVisitor",
"(",
"$",
"location",
",",
"RequestVisitorInterface",
"$",
"visitor",
")",
"{",
"$",
"this",
"->",
"factory",
"->",
"addRequestVisitor",
"(",
"$",
"location",
",",
"$",
"visitor",
")",
";",
"return",
"$",
"this",
";",
"}... | Add a location visitor to the serializer
@param string $location Location to associate with the visitor
@param RequestVisitorInterface $visitor Visitor to attach
@return self | [
"Add",
"a",
"location",
"visitor",
"to",
"the",
"serializer"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/DefaultRequestSerializer.php#L51-L56 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/DefaultRequestSerializer.php | DefaultRequestSerializer.prepareAdditionalParameters | protected function prepareAdditionalParameters(
OperationInterface $operation,
CommandInterface $command,
RequestInterface $request,
Parameter $additional
) {
if (!($location = $additional->getLocation())) {
return;
}
$visitor = $this->factory->getRequestVisitor($location);
$hidden = $command[$command::HIDDEN_PARAMS];
foreach ($command->toArray() as $key => $value) {
// Ignore values that are null or built-in command options
if ($value !== null
&& !in_array($key, $hidden)
&& !$operation->hasParam($key)
) {
$additional->setName($key);
$visitor->visit($command, $request, $additional, $value);
}
}
return $visitor;
} | php | protected function prepareAdditionalParameters(
OperationInterface $operation,
CommandInterface $command,
RequestInterface $request,
Parameter $additional
) {
if (!($location = $additional->getLocation())) {
return;
}
$visitor = $this->factory->getRequestVisitor($location);
$hidden = $command[$command::HIDDEN_PARAMS];
foreach ($command->toArray() as $key => $value) {
// Ignore values that are null or built-in command options
if ($value !== null
&& !in_array($key, $hidden)
&& !$operation->hasParam($key)
) {
$additional->setName($key);
$visitor->visit($command, $request, $additional, $value);
}
}
return $visitor;
} | [
"protected",
"function",
"prepareAdditionalParameters",
"(",
"OperationInterface",
"$",
"operation",
",",
"CommandInterface",
"$",
"command",
",",
"RequestInterface",
"$",
"request",
",",
"Parameter",
"$",
"additional",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"locatio... | Serialize additional parameters
@param OperationInterface $operation Operation that owns the command
@param CommandInterface $command Command to prepare
@param RequestInterface $request Request to serialize
@param Parameter $additional Additional parameters
@return null|RequestVisitorInterface | [
"Serialize",
"additional",
"parameters"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/DefaultRequestSerializer.php#L109-L134 | train |
guzzle/guzzle3 | src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php | BodyVisitor.addExpectHeader | protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
{
// Allow the `expect` data parameter to be set to remove the Expect header from the request
if ($expect === false) {
$request->removeHeader('Expect');
} elseif ($expect !== true) {
// Default to using a MB as the point in which to start using the expect header
$expect = $expect ?: 1048576;
// If the expect_header value is numeric then only add if the size is greater than the cutoff
if (is_numeric($expect) && $body->getSize()) {
if ($body->getSize() < $expect) {
$request->removeHeader('Expect');
} else {
$request->setHeader('Expect', '100-Continue');
}
}
}
} | php | protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
{
// Allow the `expect` data parameter to be set to remove the Expect header from the request
if ($expect === false) {
$request->removeHeader('Expect');
} elseif ($expect !== true) {
// Default to using a MB as the point in which to start using the expect header
$expect = $expect ?: 1048576;
// If the expect_header value is numeric then only add if the size is greater than the cutoff
if (is_numeric($expect) && $body->getSize()) {
if ($body->getSize() < $expect) {
$request->removeHeader('Expect');
} else {
$request->setHeader('Expect', '100-Continue');
}
}
}
} | [
"protected",
"function",
"addExpectHeader",
"(",
"EntityEnclosingRequestInterface",
"$",
"request",
",",
"EntityBodyInterface",
"$",
"body",
",",
"$",
"expect",
")",
"{",
"// Allow the `expect` data parameter to be set to remove the Expect header from the request",
"if",
"(",
"... | Add the appropriate expect header to a request
@param EntityEnclosingRequestInterface $request Request to update
@param EntityBodyInterface $body Entity body of the request
@param string|int $expect Expect header setting | [
"Add",
"the",
"appropriate",
"expect",
"header",
"to",
"a",
"request"
] | f7778ed85e3db90009d79725afd6c3a82dab32fe | https://github.com/guzzle/guzzle3/blob/f7778ed85e3db90009d79725afd6c3a82dab32fe/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php#L40-L57 | train |
thephpleague/oauth2-facebook | src/Provider/FacebookUser.php | FacebookUser.getField | private function getField($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
} | php | private function getField($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
} | [
"private",
"function",
"getField",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns a field from the Graph node data.
@param string $key
@return mixed|null | [
"Returns",
"a",
"field",
"from",
"the",
"Graph",
"node",
"data",
"."
] | bcbcd540fb66ae16b4f82671c8ae7752b6a89556 | https://github.com/thephpleague/oauth2-facebook/blob/bcbcd540fb66ae16b4f82671c8ae7752b6a89556/src/Provider/FacebookUser.php#L217-L220 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.