Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / includes / dao / DBAccessObjectUtils.php
blobad7804c21b52e418457e781f2019d5dc17e5735f
1 <?php
2 /**
3 * This file contains database access object related constants.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Database
24 /**
25 * Helper class for DAO classes
27 * @since 1.26
29 class DBAccessObjectUtils {
30 /**
31 * @param integer $bitfield
32 * @param integer $flags IDBAccessObject::READ_* constant
33 * @return bool Bitfield has flag $flag set
35 public static function hasFlags( $bitfield, $flags ) {
36 return ( $bitfield & $flags ) == $flags;
39 /**
40 * Get an appropriate DB index and options for a query
42 * @param integer $bitfield
43 * @return array (DB_MASTER/DB_SLAVE, SELECT options array)
45 public static function getDBOptions( $bitfield ) {
46 $index = self::hasFlags( $bitfield, IDBAccessObject::READ_LATEST )
47 ? DB_MASTER
48 : DB_SLAVE;
50 $options = array();
51 if ( self::hasFlags( $bitfield, IDBAccessObject::READ_EXCLUSIVE ) ) {
52 $options[] = 'FOR UPDATE';
53 } elseif ( self::hasFlags( $bitfield, IDBAccessObject::READ_LOCKING ) ) {
54 $options[] = 'LOCK IN SHARE MODE';
57 return array( $index, $options );