mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-19 21:03:44 -07:00
v2: Updates
* Simplifies & beautifies everything * Introduces a new Class system. * Errors are defaulted to AWS's handler. * New function names & more efficient handling. * Should fix a majority of the errors. Please read the README for more!
This commit is contained in:
parent
ad0726e41e
commit
e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions
|
@ -94,15 +94,17 @@ class CookieJar implements CookieJarInterface
|
|||
*/
|
||||
public function getCookieByName($name)
|
||||
{
|
||||
// don't allow a null name
|
||||
if($name === null) {
|
||||
// don't allow a non string name
|
||||
if ($name === null || !is_scalar($name)) {
|
||||
return null;
|
||||
}
|
||||
foreach($this->cookies as $cookie) {
|
||||
if($cookie->getName() !== null && strcasecmp($cookie->getName(), $name) === 0) {
|
||||
foreach ($this->cookies as $cookie) {
|
||||
if ($cookie->getName() !== null && strcasecmp($cookie->getName(), $name) === 0) {
|
||||
return $cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
|
@ -120,7 +122,7 @@ class CookieJar implements CookieJarInterface
|
|||
} elseif (!$path) {
|
||||
$this->cookies = array_filter(
|
||||
$this->cookies,
|
||||
function (SetCookie $cookie) use ($path, $domain) {
|
||||
function (SetCookie $cookie) use ($domain) {
|
||||
return !$cookie->matchesDomain($domain);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -58,9 +58,9 @@ interface CookieJarInterface extends \Countable, \IteratorAggregate
|
|||
* arguments, then the cookie with the specified name, path and domain is
|
||||
* removed.
|
||||
*
|
||||
* @param string $domain Clears cookies matching a domain
|
||||
* @param string $path Clears cookies matching a domain and path
|
||||
* @param string $name Clears cookies matching a domain, path, and name
|
||||
* @param string|null $domain Clears cookies matching a domain
|
||||
* @param string|null $path Clears cookies matching a domain and path
|
||||
* @param string|null $name Clears cookies matching a domain, path, and name
|
||||
*
|
||||
* @return CookieJarInterface
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@ class FileCookieJar extends CookieJar
|
|||
*/
|
||||
public function __construct($cookieFile, $storeSessionCookies = false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->filename = $cookieFile;
|
||||
$this->storeSessionCookies = $storeSessionCookies;
|
||||
|
||||
|
@ -56,7 +57,7 @@ class FileCookieJar extends CookieJar
|
|||
}
|
||||
|
||||
$jsonStr = \GuzzleHttp\json_encode($json);
|
||||
if (false === file_put_contents($filename, $jsonStr)) {
|
||||
if (false === file_put_contents($filename, $jsonStr, LOCK_EX)) {
|
||||
throw new \RuntimeException("Unable to save file {$filename}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,14 @@ class SessionCookieJar extends CookieJar
|
|||
/**
|
||||
* Create a new SessionCookieJar object
|
||||
*
|
||||
* @param string $sessionKey Session key name to store the cookie
|
||||
* @param string $sessionKey Session key name to store the cookie
|
||||
* data in session
|
||||
* @param bool $storeSessionCookies Set to true to store session cookies
|
||||
* in the cookie jar.
|
||||
*/
|
||||
public function __construct($sessionKey, $storeSessionCookies = false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->sessionKey = $sessionKey;
|
||||
$this->storeSessionCookies = $storeSessionCookies;
|
||||
$this->load();
|
||||
|
|
|
@ -35,14 +35,13 @@ class SetCookie
|
|||
$data = self::$defaults;
|
||||
// Explode the cookie string using a series of semicolons
|
||||
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
|
||||
// The name of the cookie (first kvp) must include an equal sign.
|
||||
if (empty($pieces) || !strpos($pieces[0], '=')) {
|
||||
// The name of the cookie (first kvp) must exist and include an equal sign.
|
||||
if (empty($pieces[0]) || !strpos($pieces[0], '=')) {
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
// Add the cookie pieces into the parsed data array
|
||||
foreach ($pieces as $part) {
|
||||
|
||||
$cookieParts = explode('=', $part, 2);
|
||||
$key = trim($cookieParts[0]);
|
||||
$value = isset($cookieParts[1])
|
||||
|
@ -228,7 +227,7 @@ class SetCookie
|
|||
/**
|
||||
* Get whether or not this is a secure cookie
|
||||
*
|
||||
* @return null|bool
|
||||
* @return bool|null
|
||||
*/
|
||||
public function getSecure()
|
||||
{
|
||||
|
@ -248,7 +247,7 @@ class SetCookie
|
|||
/**
|
||||
* Get whether or not this is a session cookie
|
||||
*
|
||||
* @return null|bool
|
||||
* @return bool|null
|
||||
*/
|
||||
public function getDiscard()
|
||||
{
|
||||
|
@ -349,7 +348,7 @@ class SetCookie
|
|||
return false;
|
||||
}
|
||||
|
||||
return (bool) preg_match('/\.' . preg_quote($cookieDomain) . '$/', $domain);
|
||||
return (bool) preg_match('/\.' . preg_quote($cookieDomain, '/') . '$/', $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,7 +358,7 @@ class SetCookie
|
|||
*/
|
||||
public function isExpired()
|
||||
{
|
||||
return $this->getExpires() && time() > $this->getExpires();
|
||||
return $this->getExpires() !== null && time() > $this->getExpires();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,8 +377,8 @@ class SetCookie
|
|||
// Check if any of the invalid characters are present in the cookie name
|
||||
if (preg_match(
|
||||
'/[\x00-\x20\x22\x28-\x29\x2c\x2f\x3a-\x40\x5c\x7b\x7d\x7f]/',
|
||||
$name)
|
||||
) {
|
||||
$name
|
||||
)) {
|
||||
return 'Cookie name must not contain invalid characters: ASCII '
|
||||
. 'Control characters (0-31;127), space, tab and the '
|
||||
. 'following characters: ()<>@,;:\"/?={}';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue