DbMutex.php 940 Bytes
Newer Older
resurtm committed
1
<?php
2 3 4 5 6
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */
resurtm committed
7

resurtm committed
8
namespace yii\mutex;
resurtm committed
9 10 11 12

use Yii;
use yii\db\Connection;
use yii\base\InvalidConfigException;
13
use yii\di\Instance;
resurtm committed
14

15 16 17 18
/**
 * @author resurtm <resurtm@gmail.com>
 * @since 2.0
 */
resurtm committed
19
abstract class DbMutex extends Mutex
resurtm committed
20
{
21 22 23 24 25 26
    /**
     * @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';
resurtm committed
27

28 29 30 31 32 33 34
    /**
     * Initializes generic database table based mutex implementation.
     * @throws InvalidConfigException if [[db]] is invalid.
     */
    public function init()
    {
        parent::init();
35
        $this->db = Instance::ensure($this->db, Connection::className());
36
    }
resurtm committed
37
}