回滚事务
支持设置回滚事务层数，如果不设置则为全部回滚
@param int $levels
@return boolean
323831
public function rollBack($levels = null): bool
    {
        if(null === $levels)
        {
            $this->transactionLevels = 0;
        }
        else
        {
            $this->transactionLevels -= $levels;
        }
        return true;
    }
122663
public function level($level)
    {
        if (empty($level)) {
            $level = [];
        } elseif (is_string($level)) {
            $level = explode(',', str_replace(' ', '', $level));
        } else {
            $level = is_array($level) ? $level : func_get_args();
        }

        $this->setLevel($level);

        return $this;
    }
681600
public function migrateDown( $levels = NULL )
    {
        if ( NULL !== $levels )
        {
            $this->levels = $levels;
        }
        
        $migrations = $this->getAppliedMigrations( );
        
        $i = 0;
        
        if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $migrations ) )
        {
            $this->levels = count( $migrations );
        }
        
        while ( $i < $this->levels )
        {
            $class = $migrations[ $i ];
            
            $migration = new $class( );
            
            $method = new \ReflectionMethod( $class, 'migrateDown' );
            
            // run migrateDown
            if ( $class === $method->getDeclaringClass( )->name )
            {
                $migration->migrateDown( $this->db );
                
                // delete migration from table
                if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                {
                    throw new MigrationException( 'Failed to delete migration record: ' . $class );
                }
            }
            else // run safeMigrateDown
            {
                $method = new \ReflectionMethod( $class, 'safeMigrateDown' );
            
                if ( $class === $method->getDeclaringClass( )->name )
                {
                    try
                    {
                        // start transaction
                        $this->db->startTransaction( );

                        // turn off auto commit
                        $this->db->setTransactionAutocommit( FALSE );

                        // run safeMigrateDown
                        $migration->safeMigrateDown( $this->db );

                        // delete migration record
                        if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                        {
                            throw new MigrationException( 
                                    'Failed to delete migration record: ' . $class );
                            
                            $this->db->rollbackTransaction();
                        }

                        // commit transaction
                        $this->db->commitTransaction( );
                    }
                    catch ( \Exception $e )
                    {
                        // rollback transaction
                        $this->db->rollbackTransaction( );

                        throw $e;
                    }
                }
            }
            
            $i++;
            
            if ( $this->levels === $i )
            {
                $this->doAction( self::ON_MIGRATE_DOWN_ACTION );
                
                return;
            }
        }
    }
1205915
public function getMediaFolderByLevels($levels)
    {
        $qb = $this->createQueryBuilder('mf')
                   ->andWhere('mf._level IN (:levels)')
                   ->setParameter('levels', $levels)
                   ->orderBy('mf._leftnode', 'asc');

        return $qb->getQuery()->getResult();
    }
1102695
public function levelToString($level)
    {
        $mapping = [
            self::LOG_LEVEL_DEBUG => 'debug',
            self::LOG_LEVEL_INFO => 'info',
            self::LOG_LEVEL_WARN => 'warn',
            self::LOG_LEVEL_ERROR => 'error',
            self::LOG_LEVEL_FATAL => 'fatal',
        ];
        return isset($mapping[$level]) ? $mapping[$level] : 'unknown';
    }
1010832
public function setTransactionIsolationLevel($level = null)
    {
        $this->_connect();
        $sql = null;

        // Default transaction level in sql server
        if ($level === null)
        {
            $level = SQLSRV_TXN_READ_COMMITTED;
        }

        switch ($level) {
            case SQLSRV_TXN_READ_UNCOMMITTED:
                $sql = "READ UNCOMMITTED";
                break;
            case SQLSRV_TXN_READ_COMMITTED:
                $sql = "READ COMMITTED";
                break;
            case SQLSRV_TXN_REPEATABLE_READ:
                $sql = "REPEATABLE READ";
                break;
            case SQLSRV_TXN_SNAPSHOT:
                $sql = "SNAPSHOT";
                break;
            case SQLSRV_TXN_SERIALIZABLE:
                $sql = "SERIALIZABLE";
                break;
            default:
                // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
                throw new Zend_Db_Adapter_Sqlsrv_Exception("Invalid transaction isolation level mode '$level' specified");
        }

        if (!sqlsrv_query($this->_connection, "SET TRANSACTION ISOLATION LEVEL $sql;")) {
            // require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
            throw new Zend_Db_Adapter_Sqlsrv_Exception("Transaction cannot be changed to '$level'");
        }

        return true;
    }
922814
public function setEnabledLevels(array $levels)
    {
        $enabledLevels = array();

        foreach ($levels as $value) {
            if ($this->validLevel($value)) {
                array_push($enabledLevels, $value);
            }
        }

        $this->_enabledLevels = $enabledLevels;
    }
241140
public function lock(string $level = 'write'): self
    {
        //读/写模式
        $level = strtolower($level);
        if (!in_array($level, ['read', 'write'])) {
            trigger_error('锁表类型只能是READ/WRITE:' . $level, E_USER_ERROR);
        }

        $this->db->lock($this->tableName, $level);
        return $this;
    }
225992
public function addLevels(PhpCsFixerLevels $levels)
    {
        return new self(
            $this->undefined,
            $this->enabled,
            $levels,
            $this->options
        );
    }
1371749
public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
344150
public function setIndentLevel($level)
    {
        $level = intval($level);
        if (0 <= $level) {
            $this->_indentLevel = $level;
        }
        return $this;
    }
355
private function checkLevel(int $level)
    {
        if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) {
            throw new OutOfBounds(
                sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level)
            );
        }
    }
1159203
protected function isPropertyAccessibilityLevelValid(int $level) : bool
    {
        if ($level == AccessibilityLevels::PUBLIC_LEVEL ||
            $level ==  AccessibilityLevels::PROTECTED_LEVEL ||
            $level == AccessibilityLevels::PRIVATE_LEVEL
        ) {
            return true;
        }

        return false;
    }
876455
public function setDebug($level)
	{
		$previous    = $this->debug;
		$this->debug = (bool) $level;

		return $previous;
	}
345107
public static function setHandler($level = null, $handler = null)
    {
        if (empty($level)) {
            $level = static::DEFAULT_LEVEL;
        }

        if (!empty($handler)) {
            static::$handler = $handler;
            return;
        }

        static::$handler = new \Monolog\Handler\StdoutHandler(constant("\Monolog\Logger::$level"));
        static::$handler->setFormatter(static::getFormatter());
    }
301202
public function log($level, $message, array $context = array())
    {
        if (self::isSetLogger()) {
            return self::$logger->log($level, $message, $context);
        }

        return false;
    }
169655
public function isSuccess($level = HealthCheckTestResultInterface::WARNING)
    {
        /** @var HealthCheckTestResultInterface $result */
        foreach ($this->results as $result) {
            if (true === $result->isError() && $result->getLevel() >= $level){
                return false;
            }
        }

        return true;
    }