MediaWiki REL1_31
UserArray.php
Go to the documentation of this file.
1<?php
24
25abstract class UserArray implements Iterator {
30 static function newFromResult( $res ) {
31 $userArray = null;
32 if ( !Hooks::run( 'UserArrayFromResult', [ &$userArray, $res ] ) ) {
33 return null;
34 }
35 if ( $userArray === null ) {
36 $userArray = self::newFromResult_internal( $res );
37 }
38 return $userArray;
39 }
40
45 static function newFromIDs( $ids ) {
46 $ids = array_map( 'intval', (array)$ids ); // paranoia
47 if ( !$ids ) {
48 // Database::select() doesn't like empty arrays
49 return new ArrayIterator( [] );
50 }
52 $userQuery = User::getQueryInfo();
53 $res = $dbr->select(
54 $userQuery['tables'],
55 $userQuery['fields'],
56 [ 'user_id' => array_unique( $ids ) ],
57 __METHOD__,
58 [],
59 $userQuery['joins']
60 );
61 return self::newFromResult( $res );
62 }
63
69 static function newFromNames( $names ) {
70 $names = array_map( 'strval', (array)$names ); // paranoia
71 if ( !$names ) {
72 // Database::select() doesn't like empty arrays
73 return new ArrayIterator( [] );
74 }
76 $userQuery = User::getQueryInfo();
77 $res = $dbr->select(
78 $userQuery['tables'],
79 $userQuery['fields'],
80 [ 'user_name' => array_unique( $names ) ],
81 __METHOD__,
82 [],
83 $userQuery['joins']
84 );
85 return self::newFromResult( $res );
86 }
87
92 protected static function newFromResult_internal( $res ) {
93 return new UserArrayFromResult( $res );
94 }
95}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static newFromResult( $res)
Definition UserArray.php:30
static newFromIDs( $ids)
Definition UserArray.php:45
static newFromNames( $names)
Definition UserArray.php:69
static newFromResult_internal( $res)
Definition UserArray.php:92
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
Definition User.php:5672
$res
Definition database.txt:21
Result wrapper for grabbing data queried from an IDatabase object.
const DB_REPLICA
Definition defines.php:25