MediaWiki  master
UserArray.php
Go to the documentation of this file.
1 <?php
24 
25 abstract class UserArray implements Iterator {
35  public static function newFromResult( $res ) {
36  $userArray = null;
37  if ( !Hooks::runner()->onUserArrayFromResult( $userArray, $res ) ) {
38  return null;
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  }
58  $dbr = wfGetDB( DB_REPLICA );
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  }
87  $dbr = wfGetDB( DB_REPLICA );
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 }
$res
$res
Definition: testCompression.php:57
$dbr
$dbr
Definition: testCompression.php:54
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2306
UserArrayFromResult
Definition: UserArrayFromResult.php:25
UserArray\newFromResult
static newFromResult( $res)
Definition: UserArray.php:35
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
UserArray
Definition: UserArray.php:25
UserArray\newFromIDs
static newFromIDs( $ids)
Definition: UserArray.php:52
UserArray\newFromNames
static newFromNames( $names)
Definition: UserArray.php:81
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
User\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
Definition: User.php:4131