DbMutex.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\mutex;
  8. use yii\base\InvalidConfigException;
  9. use yii\db\Connection;
  10. use yii\di\Instance;
  11. /**
  12. * DbMutex is the base class for classes, which relies on database while implementing mutex "lock" mechanism.
  13. *
  14. * @see Mutex
  15. *
  16. * @author resurtm <resurtm@gmail.com>
  17. * @since 2.0
  18. */
  19. abstract class DbMutex extends Mutex
  20. {
  21. /**
  22. * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
  23. * After the Mutex object is created, if you want to change this property, you should only assign
  24. * it with a DB connection object.
  25. * Starting from version 2.0.2, this can also be a configuration array for creating the object.
  26. */
  27. public $db = 'db';
  28. /**
  29. * Initializes generic database table based mutex implementation.
  30. * @throws InvalidConfigException if [[db]] is invalid.
  31. */
  32. public function init()
  33. {
  34. parent::init();
  35. $this->db = Instance::ensure($this->db, Connection::className());
  36. }
  37. }