MediaWiki  master
UserArray.php
Go to the documentation of this file.
1 <?php
24 
25 abstract class UserArray implements Iterator {
30  public static function newFromResult( $res ) {
31  $userArray = null;
32  if ( !Hooks::runner()->onUserArrayFromResult( $userArray, $res ) ) {
33  return null;
34  }
35  return $userArray ?? new UserArrayFromResult( $res );
36  }
37 
42  public 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  }
48  $dbr = wfGetDB( DB_REPLICA );
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  public 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  }
72  $dbr = wfGetDB( DB_REPLICA );
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 }
$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:2467
UserArrayFromResult
Definition: UserArrayFromResult.php:25
UserArray\newFromResult
static newFromResult( $res)
Definition: UserArray.php:30
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
UserArray
Definition: UserArray.php:25
UserArray\newFromIDs
static newFromIDs( $ids)
Definition: UserArray.php:42
UserArray\newFromNames
static newFromNames( $names)
Definition: UserArray.php:66
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:4442