Skip to content

Commit

Permalink
modernize DatabaseTokenRepository and make consistent with `CacheTo…
Browse files Browse the repository at this point in the history
…kenRepository` (#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.
  • Loading branch information
browner12 authored Dec 6, 2024
1 parent d654523 commit 606fe57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 64 deletions.
68 changes: 6 additions & 62 deletions src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Auth/Passwords/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down

0 comments on commit 606fe57

Please sign in to comment.