diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-11-17 20:45:02 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-11-17 20:45:02 +0100 |
commit | 8df3db566a3a937b45ebf11adb90d265e6f5e2d4 (patch) | |
tree | 4d541098d751d5a9acf8c12f6fb9f308ace066ac /vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header | |
download | flyspray-8df3db566a3a937b45ebf11adb90d265e6f5e2d4.tar.xz |
initial checking of customized version 1.0rc9
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header')
6 files changed, 450 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/CacheControl.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/CacheControl.php new file mode 100644 index 0000000..77789e5 --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/CacheControl.php @@ -0,0 +1,121 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +use Guzzle\Http\Message\Header; + +/** + * Provides helpful functionality for Cache-Control headers + */ +class CacheControl extends Header +{ + /** @var array */ + protected $directives; + + public function add($value) + { + parent::add($value); + $this->directives = null; + } + + public function removeValue($searchValue) + { + parent::removeValue($searchValue); + $this->directives = null; + } + + /** + * Check if a specific cache control directive exists + * + * @param string $param Directive to retrieve + * + * @return bool + */ + public function hasDirective($param) + { + $directives = $this->getDirectives(); + + return isset($directives[$param]); + } + + /** + * Get a specific cache control directive + * + * @param string $param Directive to retrieve + * + * @return string|bool|null + */ + public function getDirective($param) + { + $directives = $this->getDirectives(); + + return isset($directives[$param]) ? $directives[$param] : null; + } + + /** + * Add a cache control directive + * + * @param string $param Directive to add + * @param string $value Value to set + * + * @return self + */ + public function addDirective($param, $value) + { + $directives = $this->getDirectives(); + $directives[$param] = $value; + $this->updateFromDirectives($directives); + + return $this; + } + + /** + * Remove a cache control directive by name + * + * @param string $param Directive to remove + * + * @return self + */ + public function removeDirective($param) + { + $directives = $this->getDirectives(); + unset($directives[$param]); + $this->updateFromDirectives($directives); + + return $this; + } + + /** + * Get an associative array of cache control directives + * + * @return array + */ + public function getDirectives() + { + if ($this->directives === null) { + $this->directives = array(); + foreach ($this->parseParams() as $collection) { + foreach ($collection as $key => $value) { + $this->directives[$key] = $value === '' ? true : $value; + } + } + } + + return $this->directives; + } + + /** + * Updates the header value based on the parsed directives + * + * @param array $directives Array of cache control directives + */ + protected function updateFromDirectives(array $directives) + { + $this->directives = $directives; + $this->values = array(); + + foreach ($directives as $key => $value) { + $this->values[] = $value === true ? $key : "{$key}={$value}"; + } + } +} diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderCollection.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderCollection.php new file mode 100644 index 0000000..8c7f6ae --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderCollection.php @@ -0,0 +1,108 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +use Guzzle\Common\ToArrayInterface; + +/** + * Provides a case-insensitive collection of headers + */ +class HeaderCollection implements \IteratorAggregate, \Countable, \ArrayAccess, ToArrayInterface +{ + /** @var array */ + protected $headers; + + public function __construct($headers = array()) + { + $this->headers = $headers; + } + + public function __clone() + { + foreach ($this->headers as &$header) { + $header = clone $header; + } + } + + /** + * Clears the header collection + */ + public function clear() + { + $this->headers = array(); + } + + /** + * Set a header on the collection + * + * @param HeaderInterface $header Header to add + * + * @return self + */ + public function add(HeaderInterface $header) + { + $this->headers[strtolower($header->getName())] = $header; + + return $this; + } + + /** + * Get an array of header objects + * + * @return array + */ + public function getAll() + { + return $this->headers; + } + + /** + * Alias of offsetGet + */ + public function get($key) + { + return $this->offsetGet($key); + } + + public function count() + { + return count($this->headers); + } + + public function offsetExists($offset) + { + return isset($this->headers[strtolower($offset)]); + } + + public function offsetGet($offset) + { + $l = strtolower($offset); + + return isset($this->headers[$l]) ? $this->headers[$l] : null; + } + + public function offsetSet($offset, $value) + { + $this->add($value); + } + + public function offsetUnset($offset) + { + unset($this->headers[strtolower($offset)]); + } + + public function getIterator() + { + return new \ArrayIterator($this->headers); + } + + public function toArray() + { + $result = array(); + foreach ($this->headers as $header) { + $result[$header->getName()] = $header->toArray(); + } + + return $result; + } +} diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactory.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactory.php new file mode 100644 index 0000000..0273be5 --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactory.php @@ -0,0 +1,26 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +use Guzzle\Http\Message\Header; + +/** + * Default header factory implementation + */ +class HeaderFactory implements HeaderFactoryInterface +{ + /** @var array */ + protected $mapping = array( + 'cache-control' => 'Guzzle\Http\Message\Header\CacheControl', + 'link' => 'Guzzle\Http\Message\Header\Link', + ); + + public function createHeader($header, $value = null) + { + $lowercase = strtolower($header); + + return isset($this->mapping[$lowercase]) + ? new $this->mapping[$lowercase]($header, $value) + : new Header($header, $value); + } +} diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactoryInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactoryInterface.php new file mode 100644 index 0000000..9457cf6 --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactoryInterface.php @@ -0,0 +1,19 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +/** + * Interface for creating headers + */ +interface HeaderFactoryInterface +{ + /** + * Create a header from a header name and a single value + * + * @param string $header Name of the header to create + * @param string $value Value to set on the header + * + * @return HeaderInterface + */ + public function createHeader($header, $value = null); +} diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderInterface.php new file mode 100644 index 0000000..adcc78e --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderInterface.php @@ -0,0 +1,83 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +use Guzzle\Common\ToArrayInterface; + +interface HeaderInterface extends ToArrayInterface, \Countable, \IteratorAggregate +{ + /** + * Convert the header to a string + * + * @return string + */ + public function __toString(); + + /** + * Add a value to the list of header values + * + * @param string $value Value to add to the header + * + * @return self + */ + public function add($value); + + /** + * Get the name of the header + * + * @return string + */ + public function getName(); + + /** + * Change the name of the header + * + * @param string $name Name to change to + * + * @return self + */ + public function setName($name); + + /** + * Change the glue used to implode the values + * + * @param string $glue Glue used to implode multiple values + * + * @return self + */ + public function setGlue($glue); + + /** + * Get the glue used to implode multiple values into a string + * + * @return string + */ + public function getGlue(); + + /** + * Check if the collection of headers has a particular value + * + * @param string $searchValue Value to search for + * + * @return bool + */ + public function hasValue($searchValue); + + /** + * Remove a specific value from the header + * + * @param string $searchValue Value to remove + * + * @return self + */ + public function removeValue($searchValue); + + /** + * Parse a header containing ";" separated data into an array of associative arrays representing the header + * key value pair data of the header. When a parameter does not contain a value, but just contains a key, this + * function will inject a key with a '' string value. + * + * @return array + */ + public function parseParams(); +} diff --git a/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/Link.php b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/Link.php new file mode 100644 index 0000000..a9fb961 --- /dev/null +++ b/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/Link.php @@ -0,0 +1,93 @@ +<?php + +namespace Guzzle\Http\Message\Header; + +use Guzzle\Http\Message\Header; + +/** + * Provides helpful functionality for link headers + */ +class Link extends Header +{ + /** + * Add a link to the header + * + * @param string $url Link URL + * @param string $rel Link rel + * @param array $params Other link parameters + * + * @return self + */ + 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)); + } + + /** + * Check if a specific link exists for a given rel attribute + * + * @param string $rel rel value + * + * @return bool + */ + public function hasLink($rel) + { + return $this->getLink($rel) !== null; + } + + /** + * Get a specific link for a given rel attribute + * + * @param string $rel Rel value + * + * @return array|null + */ + public function getLink($rel) + { + foreach ($this->getLinks() as $link) { + if (isset($link['rel']) && $link['rel'] == $rel) { + return $link; + } + } + + return null; + } + + /** + * 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 + */ + public function getLinks() + { + $links = $this->parseParams(); + + foreach ($links as &$link) { + $key = key($link); + unset($link[$key]); + $link['url'] = trim($key, '<> '); + } + + return $links; + } +} |