PHP 7.2 버전용으로 올림!
This commit is contained in:
+3
-5
@@ -36,7 +36,7 @@ class FlockStore implements StoreInterface
|
||||
*
|
||||
* @throws LockStorageException If the lock directory doesn’t exist or is not writable
|
||||
*/
|
||||
public function __construct($lockPath = null)
|
||||
public function __construct(string $lockPath = null)
|
||||
{
|
||||
if (null === $lockPath) {
|
||||
$lockPath = sys_get_temp_dir();
|
||||
@@ -78,8 +78,7 @@ class FlockStore implements StoreInterface
|
||||
);
|
||||
|
||||
// Silence error reporting
|
||||
set_error_handler(function () {
|
||||
});
|
||||
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
|
||||
if (!$handle = fopen($fileName, 'r')) {
|
||||
if ($handle = fopen($fileName, 'x')) {
|
||||
chmod($fileName, 0444);
|
||||
@@ -91,8 +90,7 @@ class FlockStore implements StoreInterface
|
||||
restore_error_handler();
|
||||
|
||||
if (!$handle) {
|
||||
$error = error_get_last();
|
||||
throw new LockStorageException($error['message'], 0, null);
|
||||
throw new LockStorageException($error, 0, null);
|
||||
}
|
||||
|
||||
// On Windows, even if PHP doc says the contrary, LOCK_NB works, see
|
||||
|
||||
+2
-6
@@ -38,7 +38,7 @@ class MemcachedStore implements StoreInterface
|
||||
* @param \Memcached $memcached
|
||||
* @param int $initialTtl the expiration delay of locks in seconds
|
||||
*/
|
||||
public function __construct(\Memcached $memcached, $initialTtl = 300)
|
||||
public function __construct(\Memcached $memcached, int $initialTtl = 300)
|
||||
{
|
||||
if (!static::isSupported()) {
|
||||
throw new InvalidArgumentException('Memcached extension is required');
|
||||
@@ -149,12 +149,8 @@ class MemcachedStore implements StoreInterface
|
||||
|
||||
/**
|
||||
* Retrieve an unique token for the given key.
|
||||
*
|
||||
* @param Key $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getToken(Key $key)
|
||||
private function getToken(Key $key): string
|
||||
{
|
||||
if (!$key->hasState(__CLASS__)) {
|
||||
$token = base64_encode(random_bytes(32));
|
||||
|
||||
+3
-11
@@ -32,7 +32,7 @@ class RedisStore implements StoreInterface
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
|
||||
* @param float $initialTtl the expiration delay of locks in seconds
|
||||
*/
|
||||
public function __construct($redisClient, $initialTtl = 300.0)
|
||||
public function __construct($redisClient, float $initialTtl = 300.0)
|
||||
{
|
||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\Client && !$redisClient instanceof RedisProxy) {
|
||||
throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, is_object($redisClient) ? get_class($redisClient) : gettype($redisClient)));
|
||||
@@ -124,13 +124,9 @@ class RedisStore implements StoreInterface
|
||||
/**
|
||||
* Evaluates a script in the corresponding redis client.
|
||||
*
|
||||
* @param string $script
|
||||
* @param string $resource
|
||||
* @param array $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function evaluate($script, $resource, array $args)
|
||||
private function evaluate(string $script, string $resource, array $args)
|
||||
{
|
||||
if ($this->redis instanceof \Redis || $this->redis instanceof \RedisCluster || $this->redis instanceof RedisProxy) {
|
||||
return $this->redis->eval($script, array_merge(array($resource), $args), 1);
|
||||
@@ -149,12 +145,8 @@ class RedisStore implements StoreInterface
|
||||
|
||||
/**
|
||||
* Retrieves an unique token for the given key.
|
||||
*
|
||||
* @param Key $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getToken(Key $key)
|
||||
private function getToken(Key $key): string
|
||||
{
|
||||
if (!$key->hasState(__CLASS__)) {
|
||||
$token = base64_encode(random_bytes(32));
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class RetryTillSaveStore implements StoreInterface, LoggerAwareInterface
|
||||
* @param int $retrySleep Duration in ms between 2 retry
|
||||
* @param int $retryCount Maximum amount of retry
|
||||
*/
|
||||
public function __construct(StoreInterface $decorated, $retrySleep = 100, $retryCount = PHP_INT_MAX)
|
||||
public function __construct(StoreInterface $decorated, int $retrySleep = 100, int $retryCount = PHP_INT_MAX)
|
||||
{
|
||||
$this->decorated = $decorated;
|
||||
$this->retrySleep = $retrySleep;
|
||||
|
||||
+3
-23
@@ -13,7 +13,6 @@ namespace Symfony\Component\Lock\Store;
|
||||
|
||||
use Symfony\Component\Lock\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Lock\Exception\LockConflictedException;
|
||||
use Symfony\Component\Lock\Exception\NotSupportedException;
|
||||
use Symfony\Component\Lock\Key;
|
||||
use Symfony\Component\Lock\StoreInterface;
|
||||
|
||||
@@ -27,23 +26,13 @@ class SemaphoreStore implements StoreInterface
|
||||
/**
|
||||
* Returns whether or not the store is supported.
|
||||
*
|
||||
* @param bool|null $blocking when not null, checked again the blocking mode
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function isSupported($blocking = null)
|
||||
public static function isSupported()
|
||||
{
|
||||
if (!extension_loaded('sysvsem')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false === $blocking && \PHP_VERSION_ID < 50601) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return extension_loaded('sysvsem');
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
@@ -76,16 +65,7 @@ class SemaphoreStore implements StoreInterface
|
||||
}
|
||||
|
||||
$resource = sem_get(crc32($key));
|
||||
|
||||
if (\PHP_VERSION_ID < 50601) {
|
||||
if (!$blocking) {
|
||||
throw new NotSupportedException(sprintf('The store "%s" does not supports non blocking locks.', get_class($this)));
|
||||
}
|
||||
|
||||
$acquired = sem_acquire($resource);
|
||||
} else {
|
||||
$acquired = sem_acquire($resource, !$blocking);
|
||||
}
|
||||
$acquired = sem_acquire($resource, !$blocking);
|
||||
|
||||
if (!$acquired) {
|
||||
throw new LockConflictedException();
|
||||
|
||||
Reference in New Issue
Block a user