summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie')
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Cookie.php538
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php237
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/CookieJarInterface.php85
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php65
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookiePlugin.php70
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Exception/InvalidCookieException.php7
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/composer.json27
7 files changed, 1029 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Cookie.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Cookie.php
new file mode 100644
index 0000000..5218e5f
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Cookie.php
@@ -0,0 +1,538 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie;
+
+use Guzzle\Common\ToArrayInterface;
+
+/**
+ * Set-Cookie object
+ */
+class Cookie implements ToArrayInterface
+{
+ /** @var array Cookie data */
+ protected $data;
+
+ /**
+ * @var string ASCII codes not valid for for use in a cookie name
+ *
+ * Cookie names are defined as 'token', according to RFC 2616, Section 2.2
+ * A valid token may contain any CHAR except CTLs (ASCII 0 - 31 or 127)
+ * or any of the following separators
+ */
+ protected static $invalidCharString;
+
+ /**
+ * Gets an array of invalid cookie characters
+ *
+ * @return array
+ */
+ protected static function getInvalidCharacters()
+ {
+ if (!self::$invalidCharString) {
+ self::$invalidCharString = implode('', array_map('chr', array_merge(
+ range(0, 32),
+ array(34, 40, 41, 44, 47),
+ array(58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 123, 125, 127)
+ )));
+ }
+
+ return self::$invalidCharString;
+ }
+
+ /**
+ * @param array $data Array of cookie data provided by a Cookie parser
+ */
+ public function __construct(array $data = array())
+ {
+ static $defaults = array(
+ 'name' => '',
+ 'value' => '',
+ 'domain' => '',
+ 'path' => '/',
+ 'expires' => null,
+ 'max_age' => 0,
+ 'comment' => null,
+ 'comment_url' => null,
+ 'port' => array(),
+ 'version' => null,
+ 'secure' => false,
+ 'discard' => false,
+ 'http_only' => false
+ );
+
+ $this->data = array_merge($defaults, $data);
+ // Extract the expires value and turn it into a UNIX timestamp if needed
+ if (!$this->getExpires() && $this->getMaxAge()) {
+ // Calculate the expires date
+ $this->setExpires(time() + (int) $this->getMaxAge());
+ } elseif ($this->getExpires() && !is_numeric($this->getExpires())) {
+ $this->setExpires(strtotime($this->getExpires()));
+ }
+ }
+
+ /**
+ * Get the cookie as an array
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Get the cookie name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->data['name'];
+ }
+
+ /**
+ * Set the cookie name
+ *
+ * @param string $name Cookie name
+ *
+ * @return Cookie
+ */
+ public function setName($name)
+ {
+ return $this->setData('name', $name);
+ }
+
+ /**
+ * Get the cookie value
+ *
+ * @return string
+ */
+ public function getValue()
+ {
+ return $this->data['value'];
+ }
+
+ /**
+ * Set the cookie value
+ *
+ * @param string $value Cookie value
+ *
+ * @return Cookie
+ */
+ public function setValue($value)
+ {
+ return $this->setData('value', $value);
+ }
+
+ /**
+ * Get the domain
+ *
+ * @return string|null
+ */
+ public function getDomain()
+ {
+ return $this->data['domain'];
+ }
+
+ /**
+ * Set the domain of the cookie
+ *
+ * @param string $domain
+ *
+ * @return Cookie
+ */
+ public function setDomain($domain)
+ {
+ return $this->setData('domain', $domain);
+ }
+
+ /**
+ * Get the path
+ *
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->data['path'];
+ }
+
+ /**
+ * Set the path of the cookie
+ *
+ * @param string $path Path of the cookie
+ *
+ * @return Cookie
+ */
+ public function setPath($path)
+ {
+ return $this->setData('path', $path);
+ }
+
+ /**
+ * Maximum lifetime of the cookie in seconds
+ *
+ * @return int|null
+ */
+ public function getMaxAge()
+ {
+ return $this->data['max_age'];
+ }
+
+ /**
+ * Set the max-age of the cookie
+ *
+ * @param int $maxAge Max age of the cookie in seconds
+ *
+ * @return Cookie
+ */
+ public function setMaxAge($maxAge)
+ {
+ return $this->setData('max_age', $maxAge);
+ }
+
+ /**
+ * The UNIX timestamp when the cookie expires
+ *
+ * @return mixed
+ */
+ public function getExpires()
+ {
+ return $this->data['expires'];
+ }
+
+ /**
+ * Set the unix timestamp for which the cookie will expire
+ *
+ * @param int $timestamp Unix timestamp
+ *
+ * @return Cookie
+ */
+ public function setExpires($timestamp)
+ {
+ return $this->setData('expires', $timestamp);
+ }
+
+ /**
+ * Version of the cookie specification. RFC 2965 is 1
+ *
+ * @return mixed
+ */
+ public function getVersion()
+ {
+ return $this->data['version'];
+ }
+
+ /**
+ * Set the cookie version
+ *
+ * @param string|int $version Version to set
+ *
+ * @return Cookie
+ */
+ public function setVersion($version)
+ {
+ return $this->setData('version', $version);
+ }
+
+ /**
+ * Get whether or not this is a secure cookie
+ *
+ * @return null|bool
+ */
+ public function getSecure()
+ {
+ return $this->data['secure'];
+ }
+
+ /**
+ * Set whether or not the cookie is secure
+ *
+ * @param bool $secure Set to true or false if secure
+ *
+ * @return Cookie
+ */
+ public function setSecure($secure)
+ {
+ return $this->setData('secure', (bool) $secure);
+ }
+
+ /**
+ * Get whether or not this is a session cookie
+ *
+ * @return null|bool
+ */
+ public function getDiscard()
+ {
+ return $this->data['discard'];
+ }
+
+ /**
+ * Set whether or not this is a session cookie
+ *
+ * @param bool $discard Set to true or false if this is a session cookie
+ *
+ * @return Cookie
+ */
+ public function setDiscard($discard)
+ {
+ return $this->setData('discard', $discard);
+ }
+
+ /**
+ * Get the comment
+ *
+ * @return string|null
+ */
+ public function getComment()
+ {
+ return $this->data['comment'];
+ }
+
+ /**
+ * Set the comment of the cookie
+ *
+ * @param string $comment Cookie comment
+ *
+ * @return Cookie
+ */
+ public function setComment($comment)
+ {
+ return $this->setData('comment', $comment);
+ }
+
+ /**
+ * Get the comment URL of the cookie
+ *
+ * @return string|null
+ */
+ public function getCommentUrl()
+ {
+ return $this->data['comment_url'];
+ }
+
+ /**
+ * Set the comment URL of the cookie
+ *
+ * @param string $commentUrl Cookie comment URL for more information
+ *
+ * @return Cookie
+ */
+ public function setCommentUrl($commentUrl)
+ {
+ return $this->setData('comment_url', $commentUrl);
+ }
+
+ /**
+ * Get an array of acceptable ports this cookie can be used with
+ *
+ * @return array
+ */
+ public function getPorts()
+ {
+ return $this->data['port'];
+ }
+
+ /**
+ * Set a list of acceptable ports this cookie can be used with
+ *
+ * @param array $ports Array of acceptable ports
+ *
+ * @return Cookie
+ */
+ public function setPorts(array $ports)
+ {
+ return $this->setData('port', $ports);
+ }
+
+ /**
+ * Get whether or not this is an HTTP only cookie
+ *
+ * @return bool
+ */
+ public function getHttpOnly()
+ {
+ return $this->data['http_only'];
+ }
+
+ /**
+ * Set whether or not this is an HTTP only cookie
+ *
+ * @param bool $httpOnly Set to true or false if this is HTTP only
+ *
+ * @return Cookie
+ */
+ public function setHttpOnly($httpOnly)
+ {
+ return $this->setData('http_only', $httpOnly);
+ }
+
+ /**
+ * Get an array of extra cookie data
+ *
+ * @return array
+ */
+ public function getAttributes()
+ {
+ return $this->data['data'];
+ }
+
+ /**
+ * Get a specific data point from the extra cookie data
+ *
+ * @param string $name Name of the data point to retrieve
+ *
+ * @return null|string
+ */
+ public function getAttribute($name)
+ {
+ return array_key_exists($name, $this->data['data']) ? $this->data['data'][$name] : null;
+ }
+
+ /**
+ * Set a cookie data attribute
+ *
+ * @param string $name Name of the attribute to set
+ * @param string $value Value to set
+ *
+ * @return Cookie
+ */
+ public function setAttribute($name, $value)
+ {
+ $this->data['data'][$name] = $value;
+
+ return $this;
+ }
+
+ /**
+ * Check if the cookie matches a path value
+ *
+ * @param string $path Path to check against
+ *
+ * @return bool
+ */
+ public function matchesPath($path)
+ {
+ // RFC6265 http://tools.ietf.org/search/rfc6265#section-5.1.4
+ // A request-path path-matches a given cookie-path if at least one of
+ // the following conditions holds:
+
+ // o The cookie-path and the request-path are identical.
+ if ($path == $this->getPath()) {
+ return true;
+ }
+
+ $pos = stripos($path, $this->getPath());
+ if ($pos === 0) {
+ // o The cookie-path is a prefix of the request-path, and the last
+ // character of the cookie-path is %x2F ("/").
+ if (substr($this->getPath(), -1, 1) === "/") {
+ return true;
+ }
+
+ // o The cookie-path is a prefix of the request-path, and the first
+ // character of the request-path that is not included in the cookie-
+ // path is a %x2F ("/") character.
+ if (substr($path, strlen($this->getPath()), 1) === "/") {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Check if the cookie matches a domain value
+ *
+ * @param string $domain Domain to check against
+ *
+ * @return bool
+ */
+ public function matchesDomain($domain)
+ {
+ // Remove the leading '.' as per spec in RFC 6265: http://tools.ietf.org/html/rfc6265#section-5.2.3
+ $cookieDomain = ltrim($this->getDomain(), '.');
+
+ // Domain not set or exact match.
+ if (!$cookieDomain || !strcasecmp($domain, $cookieDomain)) {
+ return true;
+ }
+
+ // Matching the subdomain according to RFC 6265: http://tools.ietf.org/html/rfc6265#section-5.1.3
+ if (filter_var($domain, FILTER_VALIDATE_IP)) {
+ return false;
+ }
+
+ return (bool) preg_match('/\.' . preg_quote($cookieDomain, '/') . '$/i', $domain);
+ }
+
+ /**
+ * Check if the cookie is compatible with a specific port
+ *
+ * @param int $port Port to check
+ *
+ * @return bool
+ */
+ public function matchesPort($port)
+ {
+ return count($this->getPorts()) == 0 || in_array($port, $this->getPorts());
+ }
+
+ /**
+ * Check if the cookie is expired
+ *
+ * @return bool
+ */
+ public function isExpired()
+ {
+ return $this->getExpires() && time() > $this->getExpires();
+ }
+
+ /**
+ * Check if the cookie is valid according to RFC 6265
+ *
+ * @return bool|string Returns true if valid or an error message if invalid
+ */
+ public function validate()
+ {
+ // Names must not be empty, but can be 0
+ $name = $this->getName();
+ if (empty($name) && !is_numeric($name)) {
+ return 'The cookie name must not be empty';
+ }
+
+ // Check if any of the invalid characters are present in the cookie name
+ if (strpbrk($name, self::getInvalidCharacters()) !== false) {
+ return 'The cookie name must not contain invalid characters: ' . $name;
+ }
+
+ // Value must not be empty, but can be 0
+ $value = $this->getValue();
+ if (empty($value) && !is_numeric($value)) {
+ return 'The cookie value must not be empty';
+ }
+
+ // Domains must not be empty, but can be 0
+ // A "0" is not a valid internet domain, but may be used as server name in a private network
+ $domain = $this->getDomain();
+ if (empty($domain) && !is_numeric($domain)) {
+ return 'The cookie domain must not be empty';
+ }
+
+ return true;
+ }
+
+ /**
+ * Set a value and return the cookie object
+ *
+ * @param string $key Key to set
+ * @param string $value Value to set
+ *
+ * @return Cookie
+ */
+ private function setData($key, $value)
+ {
+ $this->data[$key] = $value;
+
+ return $this;
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php
new file mode 100644
index 0000000..6b67503
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php
@@ -0,0 +1,237 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie\CookieJar;
+
+use Guzzle\Plugin\Cookie\Cookie;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Message\Response;
+use Guzzle\Parser\ParserRegistry;
+use Guzzle\Plugin\Cookie\Exception\InvalidCookieException;
+
+/**
+ * Cookie cookieJar that stores cookies an an array
+ */
+class ArrayCookieJar implements CookieJarInterface, \Serializable
+{
+ /** @var array Loaded cookie data */
+ protected $cookies = array();
+
+ /** @var bool Whether or not strict mode is enabled. When enabled, exceptions will be thrown for invalid cookies */
+ protected $strictMode;
+
+ /**
+ * @param bool $strictMode Set to true to throw exceptions when invalid cookies are added to the cookie jar
+ */
+ public function __construct($strictMode = false)
+ {
+ $this->strictMode = $strictMode;
+ }
+
+ /**
+ * Enable or disable strict mode on the cookie jar
+ *
+ * @param bool $strictMode Set to true to throw exceptions when invalid cookies are added. False to ignore them.
+ *
+ * @return self
+ */
+ public function setStrictMode($strictMode)
+ {
+ $this->strictMode = $strictMode;
+ }
+
+ public function remove($domain = null, $path = null, $name = null)
+ {
+ $cookies = $this->all($domain, $path, $name, false, false);
+ $this->cookies = array_filter($this->cookies, function (Cookie $cookie) use ($cookies) {
+ return !in_array($cookie, $cookies, true);
+ });
+
+ return $this;
+ }
+
+ public function removeTemporary()
+ {
+ $this->cookies = array_filter($this->cookies, function (Cookie $cookie) {
+ return !$cookie->getDiscard() && $cookie->getExpires();
+ });
+
+ return $this;
+ }
+
+ public function removeExpired()
+ {
+ $currentTime = time();
+ $this->cookies = array_filter($this->cookies, function (Cookie $cookie) use ($currentTime) {
+ return !$cookie->getExpires() || $currentTime < $cookie->getExpires();
+ });
+
+ return $this;
+ }
+
+ public function all($domain = null, $path = null, $name = null, $skipDiscardable = false, $skipExpired = true)
+ {
+ return array_values(array_filter($this->cookies, function (Cookie $cookie) use (
+ $domain,
+ $path,
+ $name,
+ $skipDiscardable,
+ $skipExpired
+ ) {
+ return false === (($name && $cookie->getName() != $name) ||
+ ($skipExpired && $cookie->isExpired()) ||
+ ($skipDiscardable && ($cookie->getDiscard() || !$cookie->getExpires())) ||
+ ($path && !$cookie->matchesPath($path)) ||
+ ($domain && !$cookie->matchesDomain($domain)));
+ }));
+ }
+
+ public function add(Cookie $cookie)
+ {
+ // Only allow cookies with set and valid domain, name, value
+ $result = $cookie->validate();
+ if ($result !== true) {
+ if ($this->strictMode) {
+ throw new InvalidCookieException($result);
+ } else {
+ $this->removeCookieIfEmpty($cookie);
+ return false;
+ }
+ }
+
+ // Resolve conflicts with previously set cookies
+ foreach ($this->cookies as $i => $c) {
+
+ // Two cookies are identical, when their path, domain, port and name are identical
+ if ($c->getPath() != $cookie->getPath() ||
+ $c->getDomain() != $cookie->getDomain() ||
+ $c->getPorts() != $cookie->getPorts() ||
+ $c->getName() != $cookie->getName()
+ ) {
+ continue;
+ }
+
+ // The previously set cookie is a discard cookie and this one is not so allow the new cookie to be set
+ if (!$cookie->getDiscard() && $c->getDiscard()) {
+ unset($this->cookies[$i]);
+ continue;
+ }
+
+ // If the new cookie's expiration is further into the future, then replace the old cookie
+ if ($cookie->getExpires() > $c->getExpires()) {
+ unset($this->cookies[$i]);
+ continue;
+ }
+
+ // If the value has changed, we better change it
+ if ($cookie->getValue() !== $c->getValue()) {
+ unset($this->cookies[$i]);
+ continue;
+ }
+
+ // The cookie exists, so no need to continue
+ return false;
+ }
+
+ $this->cookies[] = $cookie;
+
+ return true;
+ }
+
+ /**
+ * Serializes the cookie cookieJar
+ *
+ * @return string
+ */
+ public function serialize()
+ {
+ // Only serialize long term cookies and unexpired cookies
+ return json_encode(array_map(function (Cookie $cookie) {
+ return $cookie->toArray();
+ }, $this->all(null, null, null, true, true)));
+ }
+
+ /**
+ * Unserializes the cookie cookieJar
+ */
+ public function unserialize($data)
+ {
+ $data = json_decode($data, true);
+ if (empty($data)) {
+ $this->cookies = array();
+ } else {
+ $this->cookies = array_map(function (array $cookie) {
+ return new Cookie($cookie);
+ }, $data);
+ }
+ }
+
+ /**
+ * Returns the total number of stored cookies
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->cookies);
+ }
+
+ /**
+ * Returns an iterator
+ *
+ * @return \ArrayIterator
+ */
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->cookies);
+ }
+
+ public function addCookiesFromResponse(Response $response, RequestInterface $request = null)
+ {
+ if ($cookieHeader = $response->getHeader('Set-Cookie')) {
+ $parser = ParserRegistry::getInstance()->getParser('cookie');
+ foreach ($cookieHeader as $cookie) {
+ if ($parsed = $request
+ ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath())
+ : $parser->parseCookie($cookie)
+ ) {
+ // Break up cookie v2 into multiple cookies
+ foreach ($parsed['cookies'] as $key => $value) {
+ $row = $parsed;
+ $row['name'] = $key;
+ $row['value'] = $value;
+ unset($row['cookies']);
+ $this->add(new Cookie($row));
+ }
+ }
+ }
+ }
+ }
+
+ public function getMatchingCookies(RequestInterface $request)
+ {
+ // Find cookies that match this request
+ $cookies = $this->all($request->getHost(), $request->getPath());
+ // Remove ineligible cookies
+ foreach ($cookies as $index => $cookie) {
+ if (!$cookie->matchesPort($request->getPort()) || ($cookie->getSecure() && $request->getScheme() != 'https')) {
+ unset($cookies[$index]);
+ }
+ };
+
+ return $cookies;
+ }
+
+ /**
+ * If a cookie already exists and the server asks to set it again with a null value, the
+ * cookie must be deleted.
+ *
+ * @param \Guzzle\Plugin\Cookie\Cookie $cookie
+ */
+ private function removeCookieIfEmpty(Cookie $cookie)
+ {
+ $cookieValue = $cookie->getValue();
+ if ($cookieValue === null || $cookieValue === '') {
+ $this->remove($cookie->getDomain(), $cookie->getPath(), $cookie->getName());
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/CookieJarInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/CookieJarInterface.php
new file mode 100644
index 0000000..7faa7d2
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/CookieJarInterface.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie\CookieJar;
+
+use Guzzle\Plugin\Cookie\Cookie;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Message\Response;
+
+/**
+ * Interface for persisting cookies
+ */
+interface CookieJarInterface extends \Countable, \IteratorAggregate
+{
+ /**
+ * Remove cookies currently held in the Cookie cookieJar.
+ *
+ * Invoking this method without arguments will empty the whole Cookie cookieJar. If given a $domain argument only
+ * cookies belonging to that domain will be removed. If given a $domain and $path argument, cookies belonging to
+ * the specified path within that domain are removed. If given all three arguments, then the cookie with the
+ * specified name, path and domain is removed.
+ *
+ * @param string $domain Set to clear only cookies matching a domain
+ * @param string $path Set to clear only cookies matching a domain and path
+ * @param string $name Set to clear only cookies matching a domain, path, and name
+ *
+ * @return CookieJarInterface
+ */
+ public function remove($domain = null, $path = null, $name = null);
+
+ /**
+ * Discard all temporary cookies.
+ *
+ * Scans for all cookies in the cookieJar with either no expire field or a true discard flag. To be called when the
+ * user agent shuts down according to RFC 2965.
+ *
+ * @return CookieJarInterface
+ */
+ public function removeTemporary();
+
+ /**
+ * Delete any expired cookies
+ *
+ * @return CookieJarInterface
+ */
+ public function removeExpired();
+
+ /**
+ * Add a cookie to the cookie cookieJar
+ *
+ * @param Cookie $cookie Cookie to add
+ *
+ * @return bool Returns true on success or false on failure
+ */
+ public function add(Cookie $cookie);
+
+ /**
+ * Add cookies from a {@see Guzzle\Http\Message\Response} object
+ *
+ * @param Response $response Response object
+ * @param RequestInterface $request Request that received the response
+ */
+ public function addCookiesFromResponse(Response $response, RequestInterface $request = null);
+
+ /**
+ * Get cookies matching a request object
+ *
+ * @param RequestInterface $request Request object to match
+ *
+ * @return array
+ */
+ public function getMatchingCookies(RequestInterface $request);
+
+ /**
+ * Get all of the matching cookies
+ *
+ * @param string $domain Domain of the cookie
+ * @param string $path Path of the cookie
+ * @param string $name Name of the cookie
+ * @param bool $skipDiscardable Set to TRUE to skip cookies with the Discard attribute.
+ * @param bool $skipExpired Set to FALSE to include expired
+ *
+ * @return array Returns an array of Cookie objects
+ */
+ public function all($domain = null, $path = null, $name = null, $skipDiscardable = false, $skipExpired = true);
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php
new file mode 100644
index 0000000..99344cd
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie\CookieJar;
+
+use Guzzle\Common\Exception\RuntimeException;
+
+/**
+ * Persists non-session cookies using a JSON formatted file
+ */
+class FileCookieJar extends ArrayCookieJar
+{
+ /** @var string filename */
+ protected $filename;
+
+ /**
+ * Create a new FileCookieJar object
+ *
+ * @param string $cookieFile File to store the cookie data
+ *
+ * @throws RuntimeException if the file cannot be found or created
+ */
+ public function __construct($cookieFile)
+ {
+ $this->filename = $cookieFile;
+ $this->load();
+ }
+
+ /**
+ * Saves the file when shutting down
+ */
+ public function __destruct()
+ {
+ $this->persist();
+ }
+
+ /**
+ * Save the contents of the data array to the file
+ *
+ * @throws RuntimeException if the file cannot be found or created
+ */
+ protected function persist()
+ {
+ if (false === file_put_contents($this->filename, $this->serialize())) {
+ // @codeCoverageIgnoreStart
+ throw new RuntimeException('Unable to open file ' . $this->filename);
+ // @codeCoverageIgnoreEnd
+ }
+ }
+
+ /**
+ * Load the contents of the json formatted file into the data array and discard any unsaved state
+ */
+ protected function load()
+ {
+ $json = file_get_contents($this->filename);
+ if (false === $json) {
+ // @codeCoverageIgnoreStart
+ throw new RuntimeException('Unable to open file ' . $this->filename);
+ // @codeCoverageIgnoreEnd
+ }
+
+ $this->unserialize($json);
+ $this->cookies = $this->cookies ?: array();
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookiePlugin.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookiePlugin.php
new file mode 100644
index 0000000..df3210e
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookiePlugin.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie;
+
+use Guzzle\Common\Event;
+use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
+use Guzzle\Plugin\Cookie\CookieJar\CookieJarInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Adds, extracts, and persists cookies between HTTP requests
+ */
+class CookiePlugin implements EventSubscriberInterface
+{
+ /** @var CookieJarInterface Cookie cookieJar used to hold cookies */
+ protected $cookieJar;
+
+ /**
+ * @param CookieJarInterface $cookieJar Cookie jar used to hold cookies. Creates an ArrayCookieJar by default.
+ */
+ public function __construct(CookieJarInterface $cookieJar = null)
+ {
+ $this->cookieJar = $cookieJar ?: new ArrayCookieJar();
+ }
+
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'request.before_send' => array('onRequestBeforeSend', 125),
+ 'request.sent' => array('onRequestSent', 125)
+ );
+ }
+
+ /**
+ * Get the cookie cookieJar
+ *
+ * @return CookieJarInterface
+ */
+ public function getCookieJar()
+ {
+ return $this->cookieJar;
+ }
+
+ /**
+ * Add cookies before a request is sent
+ *
+ * @param Event $event
+ */
+ public function onRequestBeforeSend(Event $event)
+ {
+ $request = $event['request'];
+ if (!$request->getParams()->get('cookies.disable')) {
+ $request->removeHeader('Cookie');
+ // Find cookies that match this request
+ foreach ($this->cookieJar->getMatchingCookies($request) as $cookie) {
+ $request->addCookie($cookie->getName(), $cookie->getValue());
+ }
+ }
+ }
+
+ /**
+ * Extract cookies from a sent request
+ *
+ * @param Event $event
+ */
+ public function onRequestSent(Event $event)
+ {
+ $this->cookieJar->addCookiesFromResponse($event['response'], $event['request']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Exception/InvalidCookieException.php b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Exception/InvalidCookieException.php
new file mode 100644
index 0000000..b1fa6fd
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Exception/InvalidCookieException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Guzzle\Plugin\Cookie\Exception;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+
+class InvalidCookieException extends InvalidArgumentException {}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/composer.json b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/composer.json
new file mode 100644
index 0000000..f0b5230
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/composer.json
@@ -0,0 +1,27 @@
+{
+ "name": "guzzle/plugin-cookie",
+ "description": "Guzzle cookie plugin",
+ "homepage": "http://guzzlephp.org/",
+ "keywords": ["plugin", "guzzle"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.2",
+ "guzzle/http": "self.version"
+ },
+ "autoload": {
+ "psr-0": { "Guzzle\\Plugin\\Cookie": "" }
+ },
+ "target-dir": "Guzzle/Plugin/Cookie",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.7-dev"
+ }
+ }
+}