You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
<?php |
|
/** |
|
* @link http://www.yiiframework.com/ |
|
* @copyright Copyright (c) 2008 Yii Software LLC |
|
* @license http://www.yiiframework.com/license/ |
|
*/ |
|
|
|
namespace yii\mutex\db; |
|
|
|
use Yii; |
|
use yii\db\Connection; |
|
use yii\base\InvalidConfigException; |
|
|
|
/** |
|
* @author resurtm <resurtm@gmail.com> |
|
* @since 2.0 |
|
*/ |
|
abstract class Mutex extends \yii\mutex\Mutex |
|
{ |
|
/** |
|
* @var Connection|string the DB connection object or the application component ID of the DB connection. |
|
* After the Mutex object is created, if you want to change this property, you should only assign |
|
* it with a DB connection object. |
|
*/ |
|
public $db = 'db'; |
|
|
|
/** |
|
* Initializes generic database table based mutex implementation. |
|
* @throws InvalidConfigException if [[db]] is invalid. |
|
*/ |
|
public function init() |
|
{ |
|
parent::init(); |
|
if (is_string($this->db)) { |
|
$this->db = Yii::$app->getComponent($this->db); |
|
} |
|
if (!$this->db instanceof Connection) { |
|
throw new InvalidConfigException('Mutex::db must be either a DB connection instance or the application component ID of a DB connection.'); |
|
} |
|
} |
|
|
|
/** |
|
* This method should be extended by concrete mutex implementations. Returns whether current mutex |
|
* implementation can be used in a distributed environment. |
|
* @return boolean whether current mutex implementation can be used in a distributed environment. |
|
*/ |
|
public function getIsDistributed() |
|
{ |
|
return true; |
|
} |
|
}
|
|
|