Skip to content

Commit 92af784

Browse files
garret-gunterpatrickbrouwers
authored andcommitted
No longer store auth guard. (#37)
* No longer store auth guard. * Remove unused constructor. * Remove unused constructor. * Add getAuth() method. Get auth manager with getter rather than directly. * Fix phpdoc formatting. * Minor formatting fix. * Pass the current user to function Implement current master branch's behavior. * Fix code format and phpdoc return type Use the contract that 'auth' is bound to instead of the default resolved manager. * Directly return guard instead of auth
1 parent d9c8b64 commit 92af784

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

src/Blameable/BlameableExtension.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,12 @@
66
use Doctrine\Common\EventManager;
77
use Doctrine\ORM\EntityManagerInterface;
88
use Gedmo\Blameable\BlameableListener;
9-
use Illuminate\Contracts\Auth\Guard;
109
use LaravelDoctrine\Extensions\GedmoExtension;
1110
use LaravelDoctrine\Extensions\ResolveUserDecorator;
1211

1312
class BlameableExtension extends GedmoExtension
1413
{
15-
/**
16-
* @var Guard
17-
*/
18-
protected $auth;
19-
20-
/**
21-
* @param Guard $auth
22-
*/
23-
public function __construct(Guard $auth)
24-
{
25-
$this->auth = $auth;
26-
}
27-
14+
2815
/**
2916
* @param EventManager $manager
3017
* @param EntityManagerInterface $em
@@ -34,7 +21,6 @@ public function addSubscribers(EventManager $manager, EntityManagerInterface $em
3421
{
3522
$subscriber = new ResolveUserDecorator(
3623
new BlameableListener(),
37-
$this->auth,
3824
'setUserValue'
3925
);
4026

src/Loggable/LoggableExtension.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@
66
use Doctrine\Common\EventManager;
77
use Doctrine\ORM\EntityManagerInterface;
88
use Gedmo\Loggable\LoggableListener;
9-
use Illuminate\Contracts\Auth\Guard;
109
use LaravelDoctrine\Extensions\GedmoExtension;
1110
use LaravelDoctrine\Extensions\ResolveUserDecorator;
1211

1312
class LoggableExtension extends GedmoExtension
1413
{
15-
/**
16-
* @var Guard
17-
*/
18-
protected $auth;
19-
20-
/**
21-
* @param Guard $auth
22-
*/
23-
public function __construct(Guard $auth)
24-
{
25-
$this->auth = $auth;
26-
}
2714

2815
/**
2916
* @param EventManager $manager
@@ -34,7 +21,6 @@ public function addSubscribers(EventManager $manager, EntityManagerInterface $em
3421
{
3522
$subscriber = new ResolveUserDecorator(
3623
new LoggableListener,
37-
$this->auth,
3824
'setUsername'
3925
);
4026

src/ResolveUserDecorator.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace LaravelDoctrine\Extensions;
44

55
use Doctrine\Common\EventSubscriber;
6-
use Illuminate\Contracts\Auth\Guard;
76

87
class ResolveUserDecorator implements EventSubscriber
98
{
@@ -17,21 +16,14 @@ class ResolveUserDecorator implements EventSubscriber
1716
*/
1817
private $userSetterMethod;
1918

20-
/**
21-
* @var Guard
22-
*/
23-
private $auth;
24-
2519
/**
2620
* @param EventSubscriber $wrapped
27-
* @param Guard $auth
2821
* @param string $userSetterMethod
2922
*/
30-
public function __construct(EventSubscriber $wrapped, Guard $auth, $userSetterMethod)
23+
public function __construct(EventSubscriber $wrapped, $userSetterMethod)
3124
{
3225
$this->wrapped = $wrapped;
3326
$this->userSetterMethod = $userSetterMethod;
34-
$this->auth = $auth;
3527
}
3628

3729
/**
@@ -67,8 +59,8 @@ public function setAnnotationReader($reader)
6759
*/
6860
public function __call($method, $params)
6961
{
70-
if ($this->auth->check()) {
71-
call_user_func([$this->wrapped, $this->userSetterMethod], $this->auth->user());
62+
if ($this->getGuard()->check()) {
63+
call_user_func([$this->wrapped, $this->userSetterMethod], $this->getGuard()->user());
7264
}
7365

7466
return call_user_func_array([$this->wrapped, $method], $params);
@@ -96,4 +88,14 @@ public function getEventSubscriberClass()
9688
{
9789
return get_class($this->wrapped);
9890
}
91+
92+
/**
93+
* Get current Auth manager.
94+
*
95+
* @return \Illuminate\Contracts\Auth\Guard
96+
*/
97+
protected function getGuard()
98+
{
99+
return app('auth')->guard();
100+
}
99101
}

0 commit comments

Comments
 (0)