MediaWiki master
UserArray.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\User;
22
23use Countable;
24use Iterator;
29
33abstract class UserArray implements Iterator, Countable {
43 public static function newFromResult( $res ): self {
44 $userArray = null;
45 $hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
46 if ( !$hookRunner->onUserArrayFromResult( $userArray, $res ) ) {
47 return new UserArrayFromResult( new FakeResultWrapper( [] ) );
48 }
49 return $userArray ?? new UserArrayFromResult( $res );
50 }
51
61 public static function newFromIDs( array $ids ): self {
62 $ids = array_map( 'intval', $ids ); // paranoia
63 if ( !$ids ) {
64 // Database::select() doesn't like empty arrays
65 return new UserArrayFromResult( new FakeResultWrapper( [] ) );
66 }
67 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
68 $res = User::newQueryBuilder( $dbr )
69 ->where( [ 'user_id' => array_unique( $ids ) ] )
70 ->caller( __METHOD__ )
71 ->fetchResultSet();
72 return self::newFromResult( $res );
73 }
74
85 public static function newFromNames( array $names ): self {
86 $names = array_map( 'strval', $names ); // paranoia
87 if ( !$names ) {
88 // Database::select() doesn't like empty arrays
89 return new UserArrayFromResult( new FakeResultWrapper( [] ) );
90 }
91 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
92 $res = User::newQueryBuilder( $dbr )
93 ->where( [ 'user_name' => array_unique( $names ) ] )
94 ->caller( __METHOD__ )
95 ->fetchResultSet();
96 return self::newFromResult( $res );
97 }
98
99 abstract public function count(): int;
100
101 abstract public function current(): User;
102
103 abstract public function key(): int;
104}
105
107class_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.
Class to walk into a list of User objects.
Definition UserArray.php:33
static newFromResult( $res)
Definition UserArray.php:43
static newFromIDs(array $ids)
Definition UserArray.php:61
static newFromNames(array $names)
Definition UserArray.php:85
User class for the MediaWiki software.
Definition User.php:120
static newQueryBuilder(IReadableDatabase $db)
Get a SelectQueryBuilder with the tables, fields and join conditions needed to create a new User obje...
Definition User.php:3200
Overloads the relevant methods of the real ResultWrapper so it doesn't go anywhere near an actual dat...
Result wrapper for grabbing data queried from an IDatabase object.