MediaWiki  1.28.0
UserArray.php
Go to the documentation of this file.
1 <?php
23 abstract class UserArray implements Iterator {
28  static function newFromResult( $res ) {
29  $userArray = null;
30  if ( !Hooks::run( 'UserArrayFromResult', [ &$userArray, $res ] ) ) {
31  return null;
32  }
33  if ( $userArray === null ) {
34  $userArray = self::newFromResult_internal( $res );
35  }
36  return $userArray;
37  }
38 
43  static function newFromIDs( $ids ) {
44  $ids = array_map( 'intval', (array)$ids ); // paranoia
45  if ( !$ids ) {
46  // Database::select() doesn't like empty arrays
47  return new ArrayIterator( [] );
48  }
49  $dbr = wfGetDB( DB_REPLICA );
50  $res = $dbr->select(
51  'user',
53  [ 'user_id' => array_unique( $ids ) ],
54  __METHOD__
55  );
56  return self::newFromResult( $res );
57  }
58 
64  static function newFromNames( $names ) {
65  $names = array_map( 'strval', (array)$names ); // paranoia
66  if ( !$names ) {
67  // Database::select() doesn't like empty arrays
68  return new ArrayIterator( [] );
69  }
70  $dbr = wfGetDB( DB_REPLICA );
71  $res = $dbr->select(
72  'user',
74  [ 'user_name' => array_unique( $names ) ],
75  __METHOD__
76  );
77  return self::newFromResult( $res );
78  }
79 
84  protected static function newFromResult_internal( $res ) {
85  return new UserArrayFromResult( $res );
86  }
87 }
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
static selectFields()
Return the list of user fields that should be selected to create a new user object.
Definition: User.php:5325
static newFromResult($res)
Definition: UserArray.php:28
$res
Definition: database.txt:21
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
static newFromNames($names)
Definition: UserArray.php:64
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static newFromResult_internal($res)
Definition: UserArray.php:84
const DB_REPLICA
Definition: defines.php:22
static newFromIDs($ids)
Definition: UserArray.php:43