Skip to content

Commit

Permalink
Inject key instead of app instance
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed Feb 23, 2017
1 parent 38f4a25 commit e8711af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions src/Illuminate/Auth/Passwords/PasswordBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class PasswordBroker implements PasswordBrokerContract
{
/**
* The application instance.
* The application key.
*
* @var \Illuminate\Foundation\Application
* @var string
*/
protected $app;
protected $key;

/**
* The user provider implementation.
Expand All @@ -45,13 +45,14 @@ class PasswordBroker implements PasswordBrokerContract
/**
* Create a new password broker instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Auth\UserProvider $users
* @param string $key
* @param int $expiration
* @return void
*/
public function __construct(Application $app, UserProvider $users, $expiration)
public function __construct(UserProvider $users, $key, $expiration)
{
$this->app = $app;
$this->key = $key;
$this->users = $users;
$this->expiration = $expiration;
}
Expand Down Expand Up @@ -255,13 +256,11 @@ public function validateTimestamp($expiration)
*/
public function getKey()
{
$key = $this->app['config']['app.key'];

if (Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
if (Str::startsWith($this->key, 'base64:')) {
return base64_decode(substr($this->key, 7));
}

return $key;
return $this->key;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Passwords/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ protected function resolve($name)
}

return new PasswordBroker(
$this->app,
$this->app['auth']->createUserProvider($config['provider']),
$this->app['config']['app.key'],
$config['expire']
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Auth/AuthPasswordBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ public function testRedirectReturnedByRemindWhenPasswordDoesntPassValidator()

protected function getBroker($mocks)
{
return new \Illuminate\Auth\Passwords\PasswordBroker($mocks['app'], $mocks['users'], $mocks['expiration']);
return new \Illuminate\Auth\Passwords\PasswordBroker($mocks['users'], $mocks['key'], $mocks['expiration']);
}

protected function getMocks()
{
$mocks = [
'app' => m::mock('Illuminate\Contracts\Foundation\Application'),
'users' => m::mock('Illuminate\Contracts\Auth\UserProvider'),
'key' => 'secret',
'expiration' => time(),
];

Expand Down

0 comments on commit e8711af

Please sign in to comment.