MediaWiki REL1_39
UserArray.php
Go to the documentation of this file.
1<?php
24
25abstract class UserArray implements Iterator {
35 public static function newFromResult( $res ) {
36 $userArray = null;
37 if ( !Hooks::runner()->onUserArrayFromResult( $userArray, $res ) ) {
38 return new ArrayIterator( [] );
39 }
40 return $userArray ?? new UserArrayFromResult( $res );
41 }
42
52 public static function newFromIDs( $ids ) {
53 $ids = array_map( 'intval', (array)$ids ); // paranoia
54 if ( !$ids ) {
55 // Database::select() doesn't like empty arrays
56 return new ArrayIterator( [] );
57 }
59 $userQuery = User::getQueryInfo();
60 $res = $dbr->select(
61 $userQuery['tables'],
62 $userQuery['fields'],
63 [ 'user_id' => array_unique( $ids ) ],
64 __METHOD__,
65 [],
66 $userQuery['joins']
67 );
68 return self::newFromResult( $res );
69 }
70
81 public static function newFromNames( $names ) {
82 $names = array_map( 'strval', (array)$names ); // paranoia
83 if ( !$names ) {
84 // Database::select() doesn't like empty arrays
85 return new ArrayIterator( [] );
86 }
88 $userQuery = User::getQueryInfo();
89 $res = $dbr->select(
90 $userQuery['tables'],
91 $userQuery['fields'],
92 [ 'user_name' => array_unique( $names ) ],
93 __METHOD__,
94 [],
95 $userQuery['joins']
96 );
97 return self::newFromResult( $res );
98 }
99
103 abstract public function current(): User;
104
108 abstract public function key(): int;
109}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static newFromResult( $res)
Definition UserArray.php:35
static newFromIDs( $ids)
Definition UserArray.php:52
static newFromNames( $names)
Definition UserArray.php:81
internal since 1.36
Definition User.php:70
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
Definition User.php:3370
Result wrapper for grabbing data queried from an IDatabase object.
const DB_REPLICA
Definition defines.php:26