Dep: update
주로 PHAN
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
/Tests export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/.gitignore export-ignore
|
||||
@@ -11,9 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Lock\Exception;
|
||||
|
||||
use Symfony\Component\Lock\Lock;
|
||||
|
||||
/**
|
||||
* LockConflictedException is thrown when a lock is acquired by someone else.
|
||||
*
|
||||
* In non-blocking mode it is caught by {@see Lock::acquire()} and {@see Lock::acquireRead()}.
|
||||
*
|
||||
* @author Jérémy Derussé <jeremy@derusse.com>
|
||||
*/
|
||||
class LockConflictedException extends \RuntimeException implements ExceptionInterface
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2016-2020 Fabien Potencier
|
||||
Copyright (c) 2016-2021 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
Vendored
+14
@@ -50,6 +50,19 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
||||
$this->logger = new NullLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically releases the underlying lock when the object is destructed.
|
||||
*/
|
||||
@@ -67,6 +80,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
||||
*/
|
||||
public function acquire($blocking = false): bool
|
||||
{
|
||||
$this->key->resetLifetime();
|
||||
try {
|
||||
if ($blocking) {
|
||||
if (!$this->store instanceof StoreInterface && !$this->store instanceof BlockingStoreInterface) {
|
||||
|
||||
Vendored
+8
-5
@@ -1,11 +1,14 @@
|
||||
Lock Component
|
||||
==============
|
||||
|
||||
The Lock component creates and manages locks, a mechanism to provide exclusive
|
||||
access to a shared resource.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/master/components/lock.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
* [Documentation](https://symfony.com/doc/master/components/lock.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
|
||||
+11
-6
@@ -29,8 +29,8 @@ use Symfony\Component\Lock\Strategy\StrategyInterface;
|
||||
*/
|
||||
class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
{
|
||||
use LoggerAwareTrait;
|
||||
use ExpiringStoreTrait;
|
||||
use LoggerAwareTrait;
|
||||
|
||||
/** @var PersistingStoreInterface[] */
|
||||
private $stores;
|
||||
@@ -99,8 +99,8 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
*/
|
||||
public function waitAndSave(Key $key)
|
||||
{
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this)));
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', static::class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,9 +171,14 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
$storesCount = \count($this->stores);
|
||||
|
||||
foreach ($this->stores as $store) {
|
||||
if ($store->exists($key)) {
|
||||
++$successCount;
|
||||
} else {
|
||||
try {
|
||||
if ($store->exists($key)) {
|
||||
++$successCount;
|
||||
} else {
|
||||
++$failureCount;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
|
||||
++$failureCount;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -74,7 +74,7 @@ class FlockStore implements StoreInterface, BlockingStoreInterface
|
||||
|
||||
$fileName = sprintf('%s/sf.%s.%s.lock',
|
||||
$this->lockPath,
|
||||
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
|
||||
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
|
||||
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
|
||||
);
|
||||
|
||||
@@ -96,7 +96,7 @@ class FlockStore implements StoreInterface, BlockingStoreInterface
|
||||
|
||||
// On Windows, even if PHP doc says the contrary, LOCK_NB works, see
|
||||
// https://bugs.php.net/54129
|
||||
if (!flock($handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) {
|
||||
if (!flock($handle, \LOCK_EX | ($blocking ? 0 : \LOCK_NB))) {
|
||||
fclose($handle);
|
||||
throw new LockConflictedException();
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class FlockStore implements StoreInterface, BlockingStoreInterface
|
||||
|
||||
$handle = $key->getState(__CLASS__);
|
||||
|
||||
flock($handle, LOCK_UN | LOCK_NB);
|
||||
flock($handle, \LOCK_UN | \LOCK_NB);
|
||||
fclose($handle);
|
||||
|
||||
$key->removeState(__CLASS__);
|
||||
|
||||
+7
-7
@@ -43,11 +43,11 @@ class MemcachedStore implements StoreInterface
|
||||
public function __construct(\Memcached $memcached, int $initialTtl = 300)
|
||||
{
|
||||
if (!static::isSupported()) {
|
||||
throw new InvalidArgumentException('Memcached extension is required');
|
||||
throw new InvalidArgumentException('Memcached extension is required.');
|
||||
}
|
||||
|
||||
if ($initialTtl < 1) {
|
||||
throw new InvalidArgumentException(sprintf('%s() expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||
}
|
||||
|
||||
$this->memcached = $memcached;
|
||||
@@ -76,8 +76,8 @@ class MemcachedStore implements StoreInterface
|
||||
*/
|
||||
public function waitAndSave(Key $key)
|
||||
{
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this)));
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', static::class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ class MemcachedStore implements StoreInterface
|
||||
public function putOffExpiration(Key $key, $ttl)
|
||||
{
|
||||
if ($ttl < 1) {
|
||||
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
|
||||
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
|
||||
}
|
||||
|
||||
// Interface defines a float value but Store required an integer.
|
||||
@@ -94,7 +94,7 @@ class MemcachedStore implements StoreInterface
|
||||
|
||||
$token = $this->getUniqueToken($key);
|
||||
|
||||
list($value, $cas) = $this->getValueAndCas($key);
|
||||
[$value, $cas] = $this->getValueAndCas($key);
|
||||
|
||||
$key->reduceLifetime($ttl);
|
||||
// Could happens when we ask a putOff after a timeout but in luck nobody steal the lock
|
||||
@@ -126,7 +126,7 @@ class MemcachedStore implements StoreInterface
|
||||
{
|
||||
$token = $this->getUniqueToken($key);
|
||||
|
||||
list($value, $cas) = $this->getValueAndCas($key);
|
||||
[$value, $cas] = $this->getValueAndCas($key);
|
||||
|
||||
if ($value !== $token) {
|
||||
// we are not the owner of the lock. Nothing to do.
|
||||
|
||||
+48
-23
@@ -14,6 +14,7 @@ namespace Symfony\Component\Lock\Store;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Symfony\Component\Lock\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Lock\Exception\InvalidTtlException;
|
||||
@@ -82,12 +83,12 @@ class PdoStore implements StoreInterface
|
||||
throw new InvalidArgumentException(sprintf('"%s" requires gcProbability between 0 and 1, "%f" given.', __METHOD__, $gcProbability));
|
||||
}
|
||||
if ($initialTtl < 1) {
|
||||
throw new InvalidTtlException(sprintf('%s() expects a strictly positive TTL, "%d" given.', __METHOD__, $initialTtl));
|
||||
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL, "%d" given.', __METHOD__, $initialTtl));
|
||||
}
|
||||
|
||||
if ($connOrDsn instanceof \PDO) {
|
||||
if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
|
||||
throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __METHOD__));
|
||||
throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
|
||||
}
|
||||
|
||||
$this->conn = $connOrDsn;
|
||||
@@ -126,7 +127,7 @@ class PdoStore implements StoreInterface
|
||||
|
||||
try {
|
||||
$stmt->execute();
|
||||
} catch (DBALException $e) {
|
||||
} catch (DBALException | Exception $e) {
|
||||
// the lock is already acquired. It could be us. Let's try to put off.
|
||||
$this->putOffExpiration($key, $this->initialTtl);
|
||||
} catch (\PDOException $e) {
|
||||
@@ -134,7 +135,7 @@ class PdoStore implements StoreInterface
|
||||
$this->putOffExpiration($key, $this->initialTtl);
|
||||
}
|
||||
|
||||
if ($this->gcProbability > 0 && (1.0 === $this->gcProbability || (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) <= $this->gcProbability)) {
|
||||
if ($this->gcProbability > 0 && (1.0 === $this->gcProbability || (random_int(0, \PHP_INT_MAX) / \PHP_INT_MAX) <= $this->gcProbability)) {
|
||||
$this->prune();
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ class PdoStore implements StoreInterface
|
||||
*/
|
||||
public function waitAndSave(Key $key)
|
||||
{
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not supports blocking locks.', __METHOD__));
|
||||
}
|
||||
|
||||
@@ -156,7 +157,7 @@ class PdoStore implements StoreInterface
|
||||
public function putOffExpiration(Key $key, $ttl)
|
||||
{
|
||||
if ($ttl < 1) {
|
||||
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
|
||||
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
|
||||
}
|
||||
|
||||
$key->reduceLifetime($ttl);
|
||||
@@ -168,10 +169,10 @@ class PdoStore implements StoreInterface
|
||||
$stmt->bindValue(':id', $this->getHashedKey($key));
|
||||
$stmt->bindValue(':token1', $uniqueToken);
|
||||
$stmt->bindValue(':token2', $uniqueToken);
|
||||
$stmt->execute();
|
||||
$result = $stmt->execute();
|
||||
|
||||
// If this method is called twice in the same second, the row wouldn't be updated. We have to call exists to know if we are the owner
|
||||
if (!$stmt->rowCount() && !$this->exists($key)) {
|
||||
if (!(\is_object($result) ? $result : $stmt)->rowCount() && !$this->exists($key)) {
|
||||
throw new LockConflictedException();
|
||||
}
|
||||
|
||||
@@ -201,9 +202,9 @@ class PdoStore implements StoreInterface
|
||||
|
||||
$stmt->bindValue(':id', $this->getHashedKey($key));
|
||||
$stmt->bindValue(':token', $this->getUniqueToken($key));
|
||||
$stmt->execute();
|
||||
$result = $stmt->execute();
|
||||
|
||||
return (bool) $stmt->fetchColumn();
|
||||
return (bool) (\is_object($result) ? $result->fetchOne() : $stmt->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,6 +250,7 @@ class PdoStore implements StoreInterface
|
||||
*
|
||||
* @throws \PDOException When the table already exists
|
||||
* @throws DBALException When the table already exists
|
||||
* @throws Exception When the table already exists
|
||||
* @throws \DomainException When an unsupported PDO driver is used
|
||||
*/
|
||||
public function createTable(): void
|
||||
@@ -266,7 +268,11 @@ class PdoStore implements StoreInterface
|
||||
$table->setPrimaryKey([$this->idCol]);
|
||||
|
||||
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
|
||||
$conn->exec($sql);
|
||||
if (method_exists($conn, 'executeStatement')) {
|
||||
$conn->executeStatement($sql);
|
||||
} else {
|
||||
$conn->exec($sql);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -292,7 +298,11 @@ class PdoStore implements StoreInterface
|
||||
throw new \DomainException(sprintf('Creating the lock table is currently not implemented for PDO driver "%s".', $driver));
|
||||
}
|
||||
|
||||
$conn->exec($sql);
|
||||
if (method_exists($conn, 'executeStatement')) {
|
||||
$conn->executeStatement($sql);
|
||||
} else {
|
||||
$conn->exec($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +312,12 @@ class PdoStore implements StoreInterface
|
||||
{
|
||||
$sql = "DELETE FROM $this->table WHERE $this->expirationCol <= {$this->getCurrentTimestampStatement()}";
|
||||
|
||||
$this->getConnection()->exec($sql);
|
||||
$conn = $this->getConnection();
|
||||
if (method_exists($conn, 'executeStatement')) {
|
||||
$conn->executeStatement($sql);
|
||||
} else {
|
||||
$conn->exec($sql);
|
||||
}
|
||||
}
|
||||
|
||||
private function getDriver(): string
|
||||
@@ -315,25 +330,35 @@ class PdoStore implements StoreInterface
|
||||
if ($con instanceof \PDO) {
|
||||
$this->driver = $con->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||
} else {
|
||||
switch ($this->driver = $con->getDriver()->getName()) {
|
||||
case 'mysqli':
|
||||
case 'pdo_mysql':
|
||||
case 'drizzle_pdo_mysql':
|
||||
$driver = $con->getDriver();
|
||||
|
||||
switch (true) {
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\Mysqli\Driver:
|
||||
throw new \LogicException(sprintf('The adapter "%s" does not support the mysqli driver, use pdo_mysql instead.', static::class));
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\AbstractMySQLDriver:
|
||||
$this->driver = 'mysql';
|
||||
break;
|
||||
case 'pdo_sqlite':
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLite\Driver:
|
||||
$this->driver = 'sqlite';
|
||||
break;
|
||||
case 'pdo_pgsql':
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDO\PgSQL\Driver:
|
||||
$this->driver = 'pgsql';
|
||||
break;
|
||||
case 'oci8':
|
||||
case 'pdo_oracle':
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\OCI8\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDOOracle\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDO\OCI\Driver:
|
||||
$this->driver = 'oci';
|
||||
break;
|
||||
case 'pdo_sqlsrv':
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlsrv\Driver:
|
||||
case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver:
|
||||
$this->driver = 'sqlsrv';
|
||||
break;
|
||||
default:
|
||||
$this->driver = \get_class($driver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +366,7 @@ class PdoStore implements StoreInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a SQL function to get the current timestamp regarding the current connection's driver.
|
||||
* Provides an SQL function to get the current timestamp regarding the current connection's driver.
|
||||
*/
|
||||
private function getCurrentTimestampStatement(): string
|
||||
{
|
||||
|
||||
+10
-10
@@ -33,20 +33,20 @@ class RedisStore implements StoreInterface
|
||||
private $initialTtl;
|
||||
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
|
||||
* @param float $initialTtl the expiration delay of locks in seconds
|
||||
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redis
|
||||
* @param float $initialTtl The expiration delay of locks in seconds
|
||||
*/
|
||||
public function __construct($redisClient, float $initialTtl = 300.0)
|
||||
public function __construct($redis, float $initialTtl = 300.0)
|
||||
{
|
||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy) {
|
||||
throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)));
|
||||
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster, RedisProxy, RedisClusterProxy or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis)));
|
||||
}
|
||||
|
||||
if ($initialTtl <= 0) {
|
||||
throw new InvalidTtlException(sprintf('%s() expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||
}
|
||||
|
||||
$this->redis = $redisClient;
|
||||
$this->redis = $redis;
|
||||
$this->initialTtl = $initialTtl;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ class RedisStore implements StoreInterface
|
||||
*/
|
||||
public function waitAndSave(Key $key)
|
||||
{
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this)));
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', static::class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +153,7 @@ class RedisStore implements StoreInterface
|
||||
return $this->redis->eval(...array_merge([$script, 1, $resource], $args));
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('%s() expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
|
||||
}
|
||||
|
||||
private function getUniqueToken(Key $key): string
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class RetryTillSaveStore implements BlockingStoreInterface, StoreInterface, Logg
|
||||
* @param int $retrySleep Duration in ms between 2 retry
|
||||
* @param int $retryCount Maximum amount of retry
|
||||
*/
|
||||
public function __construct(PersistingStoreInterface $decorated, int $retrySleep = 100, int $retryCount = PHP_INT_MAX)
|
||||
public function __construct(PersistingStoreInterface $decorated, int $retrySleep = 100, int $retryCount = \PHP_INT_MAX)
|
||||
{
|
||||
$this->decorated = $decorated;
|
||||
$this->retrySleep = $retrySleep;
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ class SemaphoreStore implements StoreInterface, BlockingStoreInterface
|
||||
public function __construct()
|
||||
{
|
||||
if (!static::isSupported()) {
|
||||
throw new InvalidArgumentException('Semaphore extension (sysvsem) is required');
|
||||
throw new InvalidArgumentException('Semaphore extension (sysvsem) is required.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class SemaphoreStore implements StoreInterface, BlockingStoreInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$keyId = crc32($key);
|
||||
$keyId = unpack('i', md5($key, true))[1];
|
||||
$resource = sem_get($keyId);
|
||||
$acquired = @sem_acquire($resource, !$blocking);
|
||||
|
||||
|
||||
+21
-21
@@ -33,7 +33,7 @@ class StoreFactory
|
||||
public static function createStore($connection)
|
||||
{
|
||||
if (!\is_string($connection) && !\is_object($connection)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to %s() must be a string or a connection object, %s given.', __METHOD__, \gettype($connection)));
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, \gettype($connection)));
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
@@ -56,45 +56,45 @@ class StoreFactory
|
||||
return new ZookeeperStore($connection);
|
||||
|
||||
case !\is_string($connection):
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Connection: %s.', \get_class($connection)));
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', \get_class($connection)));
|
||||
case 'flock' === $connection:
|
||||
return new FlockStore();
|
||||
|
||||
case 0 === strpos($connection, 'flock://'):
|
||||
case str_starts_with($connection, 'flock://'):
|
||||
return new FlockStore(substr($connection, 8));
|
||||
|
||||
case 'semaphore' === $connection:
|
||||
return new SemaphoreStore();
|
||||
|
||||
case 0 === strpos($connection, 'redis://'):
|
||||
case 0 === strpos($connection, 'rediss://'):
|
||||
case 0 === strpos($connection, 'memcached://'):
|
||||
case str_starts_with($connection, 'redis:'):
|
||||
case str_starts_with($connection, 'rediss:'):
|
||||
case str_starts_with($connection, 'memcached:'):
|
||||
if (!class_exists(AbstractAdapter::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
|
||||
}
|
||||
$storeClass = 0 === strpos($connection, 'memcached://') ? MemcachedStore::class : RedisStore::class;
|
||||
$storeClass = str_starts_with($connection, 'memcached:') ? MemcachedStore::class : RedisStore::class;
|
||||
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
|
||||
|
||||
return new $storeClass($connection);
|
||||
|
||||
case 0 === strpos($connection, 'mssql://'):
|
||||
case 0 === strpos($connection, 'mysql:'):
|
||||
case 0 === strpos($connection, 'mysql2://'):
|
||||
case 0 === strpos($connection, 'oci:'):
|
||||
case 0 === strpos($connection, 'oci8://'):
|
||||
case 0 === strpos($connection, 'pdo_oci://'):
|
||||
case 0 === strpos($connection, 'pgsql:'):
|
||||
case 0 === strpos($connection, 'postgres://'):
|
||||
case 0 === strpos($connection, 'postgresql://'):
|
||||
case 0 === strpos($connection, 'sqlsrv:'):
|
||||
case 0 === strpos($connection, 'sqlite:'):
|
||||
case 0 === strpos($connection, 'sqlite3://'):
|
||||
case str_starts_with($connection, 'mssql://'):
|
||||
case str_starts_with($connection, 'mysql:'):
|
||||
case str_starts_with($connection, 'mysql2://'):
|
||||
case str_starts_with($connection, 'oci:'):
|
||||
case str_starts_with($connection, 'oci8://'):
|
||||
case str_starts_with($connection, 'pdo_oci://'):
|
||||
case str_starts_with($connection, 'pgsql:'):
|
||||
case str_starts_with($connection, 'postgres://'):
|
||||
case str_starts_with($connection, 'postgresql://'):
|
||||
case str_starts_with($connection, 'sqlsrv:'):
|
||||
case str_starts_with($connection, 'sqlite:'):
|
||||
case str_starts_with($connection, 'sqlite3://'):
|
||||
return new PdoStore($connection);
|
||||
|
||||
case 0 === strpos($connection, 'zookeeper://'):
|
||||
case str_starts_with($connection, 'zookeeper://'):
|
||||
return new ZookeeperStore(ZookeeperStore::createConnection($connection));
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Connection: %s.', $connection));
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -37,12 +37,12 @@ class ZookeeperStore implements StoreInterface
|
||||
|
||||
public static function createConnection(string $dsn): \Zookeeper
|
||||
{
|
||||
if (0 !== strpos($dsn, 'zookeeper:')) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported DSN: %s.', $dsn));
|
||||
if (!str_starts_with($dsn, 'zookeeper:')) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported DSN: "%s".', $dsn));
|
||||
}
|
||||
|
||||
if (false === $params = parse_url($dsn)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid Zookeeper DSN: %s.', $dsn));
|
||||
throw new InvalidArgumentException(sprintf('Invalid Zookeeper DSN: "%s".', $dsn));
|
||||
}
|
||||
|
||||
$host = $params['host'] ?? '';
|
||||
@@ -108,7 +108,7 @@ class ZookeeperStore implements StoreInterface
|
||||
*/
|
||||
public function waitAndSave(Key $key)
|
||||
{
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class ZookeeperStore implements StoreInterface
|
||||
// For example: foo/bar will become /foo-bar and /foo/bar will become /-foo-bar
|
||||
$resource = (string) $key;
|
||||
|
||||
if (false !== strpos($resource, '/')) {
|
||||
if (str_contains($resource, '/')) {
|
||||
$resource = strtr($resource, ['/' => '-']).'-'.sha1($resource);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+7
-12
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "symfony/lock",
|
||||
"type": "library",
|
||||
"description": "Symfony Lock Component",
|
||||
"description": "Creates and manages locks, a mechanism to provide exclusive access to a shared resource",
|
||||
"keywords": ["locking", "redlock", "mutex", "semaphore", "flock", "cas"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
@@ -16,16 +16,16 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"psr/log": "~1.0"
|
||||
"php": ">=7.1.3",
|
||||
"psr/log": "^1|^2|^3",
|
||||
"symfony/polyfill-php80": "^1.16"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/dbal": "~2.5",
|
||||
"mongodb/mongodb": "~1.1",
|
||||
"doctrine/dbal": "^2.6|^3.0",
|
||||
"predis/predis": "~1.0"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/dbal": "<2.5"
|
||||
"doctrine/dbal": "<2.6"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\Lock\\": "" },
|
||||
@@ -33,10 +33,5 @@
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.4-dev"
|
||||
}
|
||||
}
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user