File tree Expand file tree Collapse file tree 12 files changed +90
-14
lines changed Expand file tree Collapse file tree 12 files changed +90
-14
lines changed Original file line number Diff line number Diff line change @@ -263,11 +263,14 @@ public function resolveUsersUsing(Closure $userResolver)
263
263
*
264
264
* @param string $driver
265
265
* @param \Closure $callback
266
+ *
267
+ * @param-closure-this $this $callback
268
+ *
266
269
* @return $this
267
270
*/
268
271
public function extend ($ driver , Closure $ callback )
269
272
{
270
- $ this ->customCreators [$ driver ] = $ callback ;
273
+ $ this ->customCreators [$ driver ] = $ callback-> bindTo ( $ this , $ this ) ;
271
274
272
275
return $ this ;
273
276
}
Original file line number Diff line number Diff line change @@ -476,11 +476,14 @@ public function purge($name = null)
476
476
*
477
477
* @param string $driver
478
478
* @param \Closure $callback
479
+ *
480
+ * @param-closure-this $this $callback
481
+ *
479
482
* @return $this
480
483
*/
481
484
public function extend ($ driver , Closure $ callback )
482
485
{
483
- $ this ->customCreators [$ driver ] = $ callback ;
486
+ $ this ->customCreators [$ driver ] = $ callback-> bindTo ( $ this , $ this ) ;
484
487
485
488
return $ this ;
486
489
}
Original file line number Diff line number Diff line change @@ -430,11 +430,14 @@ public function purge($name = null)
430
430
*
431
431
* @param string $driver
432
432
* @param \Closure $callback
433
+ *
434
+ * @param-closure-this $this $callback
435
+ *
433
436
* @return $this
434
437
*/
435
438
public function extend ($ driver , Closure $ callback )
436
439
{
437
- $ this ->customCreators [$ driver ] = $ callback ;
440
+ $ this ->customCreators [$ driver ] = $ callback-> bindTo ( $ this , $ this ) ;
438
441
439
442
return $ this ;
440
443
}
Original file line number Diff line number Diff line change @@ -120,11 +120,14 @@ protected function callCustomCreator($driver)
120
120
*
121
121
* @param string $driver
122
122
* @param \Closure $callback
123
+ *
124
+ * @param-closure-this $this $callback
125
+ *
123
126
* @return $this
124
127
*/
125
128
public function extend ($ driver , Closure $ callback )
126
129
{
127
- $ this ->customCreators [$ driver ] = $ callback ;
130
+ $ this ->customCreators [$ driver ] = $ callback-> bindTo ( $ this , $ this ) ;
128
131
129
132
return $ this ;
130
133
}
Original file line number Diff line number Diff line change @@ -148,6 +148,12 @@ public function testMultipleDriversAuthenticatedUpdatesDefault()
148
148
$ this ->assertSame ($ secondary , $ this ->auth ->guard ());
149
149
}
150
150
151
+ public function testCustomDriverClosureBoundObjectIsAuthManager ()
152
+ {
153
+ $ this ->auth ->extend (__CLASS__ , fn () => $ this );
154
+ $ this ->assertSame ($ this ->auth , $ this ->auth ->guard (__CLASS__ ));
155
+ }
156
+
151
157
/**
152
158
* Create a new config repository instance.
153
159
*
@@ -161,6 +167,7 @@ protected function createConfig()
161
167
'guards ' => [
162
168
'default ' => ['driver ' => 'default ' ],
163
169
'secondary ' => ['driver ' => 'secondary ' ],
170
+ __CLASS__ => ['driver ' => __CLASS__ ],
164
171
],
165
172
],
166
173
]);
Original file line number Diff line number Diff line change @@ -22,18 +22,17 @@ protected function tearDown(): void
22
22
23
23
public function testCustomDriverClosureBoundObjectIsCacheManager ()
24
24
{
25
- $ cacheManager = new CacheManager ([
26
- 'config ' => [
27
- 'cache.stores. ' .__CLASS__ => [
28
- 'driver ' => __CLASS__ ,
25
+ $ manager = new CacheManager ($ this ->getApp ([
26
+ 'cache ' => [
27
+ 'stores ' => [
28
+ __CLASS__ => [
29
+ 'driver ' => __CLASS__ ,
30
+ ],
29
31
],
30
32
],
31
- ]);
32
- $ driver = function () {
33
- return $ this ;
34
- };
35
- $ cacheManager ->extend (__CLASS__ , $ driver );
36
- $ this ->assertEquals ($ cacheManager , $ cacheManager ->store (__CLASS__ ));
33
+ ]));
34
+ $ manager ->extend (__CLASS__ , fn () => $ this );
35
+ $ this ->assertSame ($ manager , $ manager ->store (__CLASS__ ));
37
36
}
38
37
39
38
public function testCustomDriverOverridesInternalDrivers ()
Original file line number Diff line number Diff line change @@ -217,6 +217,19 @@ public function testCanBuildInlineScopedDisks()
217
217
}
218
218
}
219
219
220
+ public function testCustomDriverClosureBoundObjectIsFilesystemManager ()
221
+ {
222
+ $ manager = new FilesystemManager (tap (new Application , function ($ app ) {
223
+ $ app ['config ' ] = [
224
+ 'filesystems.disks. ' .__CLASS__ => [
225
+ 'driver ' => __CLASS__ ,
226
+ ],
227
+ ];
228
+ }));
229
+ $ manager ->extend (__CLASS__ , fn () => $ this );
230
+ $ this ->assertSame ($ manager , $ manager ->disk (__CLASS__ ));
231
+ }
232
+
220
233
// public function testKeepTrackOfAdapterDecoration()
221
234
// {
222
235
// try {
Original file line number Diff line number Diff line change @@ -100,6 +100,21 @@ public function testThrowExceptionWhenUnknownStoreIsUsed()
100
100
$ broadcastManager ->connection ('alien_connection ' );
101
101
}
102
102
103
+ public function testCustomDriverClosureBoundObjectIsBroadcastManager ()
104
+ {
105
+ $ manager = new BroadcastManager ($ this ->getApp ([
106
+ 'broadcasting ' => [
107
+ 'connections ' => [
108
+ __CLASS__ => [
109
+ 'driver ' => __CLASS__ ,
110
+ ],
111
+ ],
112
+ ],
113
+ ]));
114
+ $ manager ->extend (__CLASS__ , fn () => $ this );
115
+ $ this ->assertSame ($ manager , $ manager ->connection (__CLASS__ ));
116
+ }
117
+
103
118
protected function getApp (array $ userConfig )
104
119
{
105
120
$ app = new Container ;
Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ public function getInstanceConfig($name)
89
89
'driver ' => 'mysql_database-connection ' ,
90
90
'mysql_database-connection-option ' => 'option-value ' ,
91
91
];
92
+ case 'custom ' :
93
+ return [
94
+ 'driver ' => 'custom ' ,
95
+ ];
92
96
default :
93
97
return [];
94
98
}
Original file line number Diff line number Diff line change @@ -14,4 +14,11 @@ public function testDefaultDriverCannotBeNull()
14
14
15
15
(new NullableManager ($ this ->app ))->driver ();
16
16
}
17
+
18
+ public function testCustomDriverClosureBoundObjectIsManager ()
19
+ {
20
+ $ manager = new NullableManager ($ this ->app );
21
+ $ manager ->extend (__CLASS__ , fn () => $ this );
22
+ $ this ->assertSame ($ manager , $ manager ->driver (__CLASS__ ));
23
+ }
17
24
}
You can’t perform that action at this time.
0 commit comments