NinjaMutex\Tests\Mock\MockPDO::_mock_get_lock PHP Метод

_mock_get_lock() защищенный Метод

protected _mock_get_lock ( string $key, integer $timeout ) : MockPDOStatement
$key string
$timeout integer
Результат MockPDOStatement
    protected function _mock_get_lock($key, $timeout)
    {
        // http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock
        //
        // "If you have a lock obtained with GET_LOCK(),
        // it is released when you (...) execute a new GET_LOCK()"
        //
        // SELECT IS_FREE_LOCK( 'a' ) , GET_LOCK( 'a', 0 ) , IS_FREE_LOCK( 'a' ) , GET_LOCK( 'a', 0 )
        // IS_FREE_LOCK('a') GET_LOCK('a', 0) IS_FREE_LOCK('a') GET_LOCK('a', 0)
        // 1                 1                0                 1
        if ($this->_mock_is_free_lock($key)->fetch() || isset($this->current[$key])) {
            // This part is made to reflect behaviour that second GET_LOCK() releases all current locks
            foreach ($this->current as $k => $v) {
                unset(self::$data[$k]);
                unset($this->current[$k]);
            }
            self::$data[$key] = true;
            $this->current[$key] = true;
            return $this->_mock_pdo_statement->_mock_set_fetch("1");
        }
        // We use sleep because GET_LOCK(str,timeout) accept timeout in seconds
        sleep($timeout);
        return $this->_mock_pdo_statement->_mock_set_fetch("0");
    }