MediaWiki  1.34.0
UserArray.php
Go to the documentation of this file.
1 <?php
24 
25 abstract 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  }
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  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:52
$dbr
$dbr
Definition: testCompression.php:50
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:2575
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
User\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
Definition: User.php:5252
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200