MediaWiki REL1_34
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 return $userArray ?? new UserArrayFromResult( $res );
36 }
37
42 static function newFromIDs( $ids ) {
43 $ids = array_map( 'intval', (array)$ids ); // paranoia
44 if ( !$ids ) {
45 // Database::select() doesn't like empty arrays
46 return new ArrayIterator( [] );
47 }
49 $userQuery = User::getQueryInfo();
50 $res = $dbr->select(
51 $userQuery['tables'],
52 $userQuery['fields'],
53 [ 'user_id' => array_unique( $ids ) ],
54 __METHOD__,
55 [],
56 $userQuery['joins']
57 );
58 return self::newFromResult( $res );
59 }
60
66 static function newFromNames( $names ) {
67 $names = array_map( 'strval', (array)$names ); // paranoia
68 if ( !$names ) {
69 // Database::select() doesn't like empty arrays
70 return new ArrayIterator( [] );
71 }
73 $userQuery = User::getQueryInfo();
74 $res = $dbr->select(
75 $userQuery['tables'],
76 $userQuery['fields'],
77 [ 'user_name' => array_unique( $names ) ],
78 __METHOD__,
79 [],
80 $userQuery['joins']
81 );
82 return self::newFromResult( $res );
83 }
84}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static newFromResult( $res)
Definition UserArray.php:30
static newFromIDs( $ids)
Definition UserArray.php:42
static newFromNames( $names)
Definition UserArray.php:66
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
Definition User.php:5358
Result wrapper for grabbing data queried from an IDatabase object.
const DB_REPLICA
Definition defines.php:25