Files
yii2/tests/framework/mutex/mocks/DumbMutex.php
2022-08-03 12:32:18 +03:00

56 lines
1.0 KiB
PHP

<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yiiunit\framework\mutex\mocks;
use yii\mutex\Mutex;
use yii\mutex\RetryAcquireTrait;
/**
* Class DumbMutex.
*
* @author Robert Korulczyk <robert@korulczyk.pl>
*/
class DumbMutex extends Mutex
{
use RetryAcquireTrait;
public $attemptsTime = [];
public static $locked = false;
/**
* {@inheritdoc}
*/
protected function acquireLock($name, $timeout = 0)
{
return $this->retryAcquire($timeout, function () {
$this->attemptsTime[] = \microtime(true);
if (!static::$locked) {
static::$locked = true;
return true;
}
return false;
});
}
/**
* {@inheritdoc}
*/
protected function releaseLock($name)
{
if (static::$locked) {
static::$locked = false;
return true;
}
return false;
}
}