22
33namespace MichaelDzjap \TwoFactorAuth ;
44
5- use InvalidArgumentException ;
5+ use Illuminate \ Support \ Manager ;
66use MessageBird \Client ;
77use MichaelDzjap \TwoFactorAuth \Providers \MessageBirdVerify ;
88use MichaelDzjap \TwoFactorAuth \Providers \NullProvider ;
99
10- class TwoFactorAuthManager
10+ class TwoFactorAuthManager extends Manager
1111{
12- /**
13- * The application instance.
14- *
15- * @var \Illuminate\Foundation\Application
16- */
17- protected $ app ;
18-
19- /**
20- * The array of resolved two-factor authentication drivers.
21- *
22- * @var array
23- */
24- protected $ drivers = [];
25-
26- /**
27- * Create a new manager instance.
28- *
29- * @param \Illuminate\Foundation\Application $app
30- * @return void
31- */
32- public function __construct ($ app )
33- {
34- $ this ->app = $ app ;
35- }
36-
3712 /**
3813 * Get a driver instance.
3914 *
@@ -45,90 +20,28 @@ public function provider($driver = null)
4520 return $ this ->driver ($ driver );
4621 }
4722
48- /**
49- * Get a driver instance.
50- *
51- * @param string $name
52- * @return mixed
53- */
54- public function driver ($ name = null )
55- {
56- $ name = $ name ?: $ this ->getDefaultDriver ();
57-
58- return $ this ->drivers [$ name ] = $ this ->get ($ name );
59- }
60-
61- /**
62- * Attempt to get the connection from the local cache.
63- *
64- * @param string $name
65- * @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
66- */
67- protected function get ($ name )
68- {
69- return $ this ->drivers [$ name ] ?? $ this ->resolve ($ name );
70- }
71-
72- /**
73- * Resolve the given store.
74- *
75- * @param string $name
76- * @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
77- *
78- * @throws \InvalidArgumentException
79- */
80- protected function resolve ($ name )
81- {
82- $ config = $ this ->getConfig ($ name );
83-
84- if (is_null ($ config )) {
85- throw new InvalidArgumentException ("TwoFactorProvider [ {$ name }] is not defined. " );
86- }
87-
88- $ driverMethod = 'create ' .ucfirst ($ config ['driver ' ]).'Driver ' ;
89-
90- if (! method_exists ($ this , $ driverMethod )) {
91- throw new InvalidArgumentException ("Driver [ {$ config ['driver ' ]}] is not supported. " );
92- }
93-
94- return $ this ->{$ driverMethod }($ config );
95- }
96-
9723 /**
9824 * Create an instance of the driver.
9925 *
100- * @param array $config
10126 * @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
10227 */
103- protected function createMessageBirdDriver (array $ config )
28+ protected function createMessageBirdDriver ()
10429 {
10530 return new MessageBirdVerify (
106- new Client ($ config[ ' key ' ])
31+ new Client ($ this -> app [ ' config ' ][ ' twofactor-auth.providers.messagebird. key ' ])
10732 );
10833 }
10934
11035 /**
11136 * Create an instance of the driver.
11237 *
113- * @param array $config
11438 * @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
11539 */
116- protected function createNullDriver (array $ config )
40+ protected function createNullDriver ()
11741 {
11842 return new NullProvider ;
11943 }
12044
121- /**
122- * Get the provider configuration.
123- *
124- * @param string $name
125- * @return array
126- */
127- protected function getConfig ($ name )
128- {
129- return $ this ->app ['config ' ]["twofactor-auth.providers. {$ name }" ];
130- }
131-
13245 /**
13346 * Get the default driver name.
13447 *
0 commit comments