Dep: update

주로 PHAN
This commit is contained in:
2021-08-06 22:39:09 +09:00
parent 5310c2e7f6
commit b306601c72
1098 changed files with 92137 additions and 33228 deletions
+11 -6
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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);
}