From 606fe57ffd64a13727f71d4b4e9f28ffe5c9c858 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 6 Dec 2024 13:16:42 -0600 Subject: [PATCH] modernize `DatabaseTokenRepository` and make consistent with `CacheTokenRepository` (#53746) - use promoted properties - require the `expires` property to be passed in as seconds, rather than taking it as minutes and converting it. shift responsibility to calling code. --- .../Passwords/DatabaseTokenRepository.php | 68 ++----------------- .../Auth/Passwords/PasswordBrokerManager.php | 4 +- 2 files changed, 8 insertions(+), 64 deletions(-) diff --git a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php index aae28652fc58..ba0b81a62fae 100755 --- a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php +++ b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php @@ -10,73 +10,17 @@ class DatabaseTokenRepository implements TokenRepositoryInterface { - /** - * The database connection instance. - * - * @var \Illuminate\Database\ConnectionInterface - */ - protected $connection; - - /** - * The Hasher implementation. - * - * @var \Illuminate\Contracts\Hashing\Hasher - */ - protected $hasher; - - /** - * The token database table. - * - * @var string - */ - protected $table; - - /** - * The hashing key. - * - * @var string - */ - protected $hashKey; - - /** - * The number of seconds a token should last. - * - * @var int - */ - protected $expires; - - /** - * Minimum number of seconds before re-redefining the token. - * - * @var int - */ - protected $throttle; - /** * Create a new token repository instance. - * - * @param \Illuminate\Database\ConnectionInterface $connection - * @param \Illuminate\Contracts\Hashing\Hasher $hasher - * @param string $table - * @param string $hashKey - * @param int $expires - * @param int $throttle - * @return void */ public function __construct( - ConnectionInterface $connection, - HasherContract $hasher, - $table, - $hashKey, - $expires = 60, - $throttle = 60, + protected ConnectionInterface $connection, + protected HasherContract $hasher, + protected string $table, + protected string $hashKey, + protected int $expires = 3600, + protected int $throttle = 60, ) { - $this->table = $table; - $this->hasher = $hasher; - $this->hashKey = $hashKey; - $this->expires = $expires * 60; - $this->connection = $connection; - $this->throttle = $throttle; } /** diff --git a/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php b/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php index c388c693df79..ea2020022971 100644 --- a/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php +++ b/src/Illuminate/Auth/Passwords/PasswordBrokerManager.php @@ -104,8 +104,8 @@ protected function createTokenRepository(array $config) $this->app['hash'], $config['table'], $key, - $config['expire'], - $config['throttle'] ?? 0 + ($config['expire'] ?? 60) * 60, + $config['throttle'] ?? 0, ); }