DbMutex.php 1.15 KB
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 19
 * DbMutex is the base class for classes, which relies on database while implementing mutex "lock" mechanism.
 *
 * @see Mutex
 *
20 21 22
 * @author resurtm <resurtm@gmail.com>
 * @since 2.0
 */
resurtm committed
23
abstract class DbMutex extends Mutex
resurtm committed
24
{
25
    /**
26
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
27 28
     * After the Mutex object is created, if you want to change this property, you should only assign
     * it with a DB connection object.
29
     * Starting from version 2.0.2, this can also be a configuration array for creating the object.
30 31
     */
    public $db = 'db';
resurtm committed
32

33

34 35 36 37 38 39 40
    /**
     * Initializes generic database table based mutex implementation.
     * @throws InvalidConfigException if [[db]] is invalid.
     */
    public function init()
    {
        parent::init();
41
        $this->db = Instance::ensure($this->db, Connection::className());
42
    }
resurtm committed
43
}