X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fpassword%2FPasswordFactory.php;h=96cc3fe0ecee91f11f1a4f3f1fb9bb77d7a54c4c;hb=4b4699479957417909238f343436dc26a76eed9f;hp=3383fe385e420d5937f8ce9a15b7b1b162f7179a;hpb=bdfe02223205923d923923dd420ba0dd863cd0fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/password/PasswordFactory.php b/includes/password/PasswordFactory.php index 3383fe385e..96cc3fe0ec 100644 --- a/includes/password/PasswordFactory.php +++ b/includes/password/PasswordFactory.php @@ -36,19 +36,41 @@ final class PasswordFactory { /** * Mapping of password types to classes + * * @var array * @see PasswordFactory::register * @see Setup.php */ private $types = [ - '' => [ 'type' => '', 'class' => 'InvalidPassword' ], + '' => [ 'type' => '', 'class' => InvalidPassword::class ], ]; + /** + * Construct a new password factory. + * Most of the time you'll want to use MediaWikiServices::getInstance()->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 +80,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 +103,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