X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fpassword%2FPasswordFactory.php;h=f7b283be719ca99d66dd7014161a7df779d3d97c;hb=9bd9b2f02b3001e1a90ec2861a31cb54b7c7f1ed;hp=bc37b484043d9085317afa6136d71e6a3b6a03b1;hpb=7babd362babcbf7f20adb8e12edb4f4bc1d4249f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/password/PasswordFactory.php b/includes/password/PasswordFactory.php index bc37b48404..f7b283be71 100644 --- a/includes/password/PasswordFactory.php +++ b/includes/password/PasswordFactory.php @@ -36,6 +36,7 @@ final class PasswordFactory { /** * Mapping of password types to classes + * * @var array * @see PasswordFactory::register * @see Setup.php @@ -44,11 +45,31 @@ final class PasswordFactory { '' => [ 'type' => '', 'class' => InvalidPassword::class ], ]; + /** + * Construct a new password factory. + * Most of the time you'll want to use MediaWikiServices::getPasswordFactory instead. + * @param array $config Mapping of password type => config + * @param string $default Default password type + * @see PasswordFactory::register + * @see PasswordFactory::setDefaultType + */ + public function __construct( array $config = [], $default = '' ) { + foreach ( $config as $type => $options ) { + $this->register( $type, $options ); + } + + if ( $default !== '' ) { + $this->setDefaultType( $default ); + } + } + /** * Register a new type of password hash * - * @param string $type Unique type name for the hash - * @param array $config Array of configuration options + * @param string $type Unique type name for the hash. Will be prefixed to the password hashes + * to identify what hashing method was used. + * @param array $config Array of configuration options. 'class' is required (the Password + * subclass name), everything else is passed to the constructor of that class. */ public function register( $type, array $config ) { $config['type'] = $type; @@ -58,8 +79,11 @@ final class PasswordFactory { /** * Set the default password type * - * @throws InvalidArgumentException If the type is not registered + * This type will be used for creating new passwords when the type is not specified. + * Passwords of a different type will be considered outdated and in need of update. + * * @param string $type Password hash type + * @throws InvalidArgumentException If the type is not registered */ public function setDefaultType( $type ) { if ( !isset( $this->types[$type] ) ) { @@ -78,6 +102,8 @@ final class PasswordFactory { } /** + * @deprecated since 1.32 Initialize settings using the constructor + * * Initialize the internal static variables using the global variables * * @param Config $config Configuration object to load data from