MediaWiki master
UserArray.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\User;
24
25use ArrayIterator;
26use Iterator;
30
31abstract class UserArray implements Iterator {
41 public static function newFromResult( $res ) {
42 $userArray = null;
43 $hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
44 if ( !$hookRunner->onUserArrayFromResult( $userArray, $res ) ) {
45 return new ArrayIterator( [] );
46 }
47 return $userArray ?? new UserArrayFromResult( $res );
48 }
49
59 public static function newFromIDs( $ids ) {
60 $ids = array_map( 'intval', (array)$ids ); // paranoia
61 if ( !$ids ) {
62 // Database::select() doesn't like empty arrays
63 return new ArrayIterator( [] );
64 }
65 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
66 $res = User::newQueryBuilder( $dbr )
67 ->where( [ 'user_id' => array_unique( $ids ) ] )
68 ->caller( __METHOD__ )
69 ->fetchResultSet();
70 return self::newFromResult( $res );
71 }
72
83 public static function newFromNames( $names ) {
84 $names = array_map( 'strval', (array)$names ); // paranoia
85 if ( !$names ) {
86 // Database::select() doesn't like empty arrays
87 return new ArrayIterator( [] );
88 }
89 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
90 $res = User::newQueryBuilder( $dbr )
91 ->where( [ 'user_name' => array_unique( $names ) ] )
92 ->caller( __METHOD__ )
93 ->fetchResultSet();
94 return self::newFromResult( $res );
95 }
96
100 abstract public function current(): User;
101
105 abstract public function key(): int;
106}
107
109class_alias( UserArray::class, 'UserArray' );
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
static newFromResult( $res)
Definition UserArray.php:41
static newFromIDs( $ids)
Definition UserArray.php:59
static newFromNames( $names)
Definition UserArray.php:83
internal since 1.36
Definition User.php:93
static newQueryBuilder(IReadableDatabase $db)
Get a SelectQueryBuilder with the tables, fields and join conditions needed to create a new User obje...
Definition User.php:3160
Result wrapper for grabbing data queried from an IDatabase object.
Utility class for bot passwords.