Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Illuminate/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ public function resolveUsersUsing(Closure $userResolver)
*
* @param string $driver
* @param \Closure $callback
*
* @param-closure-this $this $callback
*
* @return $this
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;
$this->customCreators[$driver] = $callback->bindTo($this, $this);

return $this;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,14 @@ public function purge($name = null)
*
* @param string $driver
* @param \Closure $callback
*
* @param-closure-this $this $callback
*
* @return $this
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;
$this->customCreators[$driver] = $callback->bindTo($this, $this);

return $this;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,14 @@ public function purge($name = null)
*
* @param string $driver
* @param \Closure $callback
*
* @param-closure-this $this $callback
*
* @return $this
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;
$this->customCreators[$driver] = $callback->bindTo($this, $this);

return $this;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Support/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@ protected function callCustomCreator($driver)
*
* @param string $driver
* @param \Closure $callback
*
* @param-closure-this $this $callback
*
* @return $this
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;
$this->customCreators[$driver] = $callback->bindTo($this, $this);

return $this;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Auth/AuthenticateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public function testMultipleDriversAuthenticatedUpdatesDefault()
$this->assertSame($secondary, $this->auth->guard());
}

public function testCustomDriverClosureBoundObjectIsAuthManager()
{
$this->auth->extend(__CLASS__, fn () => $this);
$this->assertSame($this->auth, $this->auth->guard(__CLASS__));
}

/**
* Create a new config repository instance.
*
Expand All @@ -161,6 +167,7 @@ protected function createConfig()
'guards' => [
'default' => ['driver' => 'default'],
'secondary' => ['driver' => 'secondary'],
__CLASS__ => ['driver' => __CLASS__],
],
],
]);
Expand Down
19 changes: 9 additions & 10 deletions tests/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ protected function tearDown(): void

public function testCustomDriverClosureBoundObjectIsCacheManager()
{
$cacheManager = new CacheManager([
'config' => [
'cache.stores.'.__CLASS__ => [
'driver' => __CLASS__,
$manager = new CacheManager($this->getApp([
'cache' => [
'stores' => [
__CLASS__ => [
'driver' => __CLASS__,
],
],
],
]);
$driver = function () {
return $this;
};
$cacheManager->extend(__CLASS__, $driver);
$this->assertEquals($cacheManager, $cacheManager->store(__CLASS__));
]));
$manager->extend(__CLASS__, fn () => $this);
$this->assertSame($manager, $manager->store(__CLASS__));
}

public function testCustomDriverOverridesInternalDrivers()
Expand Down
13 changes: 13 additions & 0 deletions tests/Filesystem/FilesystemManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,17 @@ public function testCanBuildInlineScopedDisks()
rmdir(__DIR__.'/../../to-be-scoped');
}
}

public function testCustomDriverClosureBoundObjectIsFilesystemManager()
{
$manager = new FilesystemManager(tap(new Application, function ($app) {
$app['config'] = [
'filesystems.disks.'.__CLASS__ => [
'driver' => __CLASS__,
],
];
}));
$manager->extend(__CLASS__, fn () => $this);
$this->assertSame($manager, $manager->disk(__CLASS__));
}
}
15 changes: 15 additions & 0 deletions tests/Integration/Broadcasting/BroadcastManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public function testThrowExceptionWhenUnknownStoreIsUsed()
$broadcastManager->connection('alien_connection');
}

public function testCustomDriverClosureBoundObjectIsBroadcastManager()
{
$manager = new BroadcastManager($this->getApp([
'broadcasting' => [
'connections' => [
__CLASS__ => [
'driver' => __CLASS__,
],
],
],
]));
$manager->extend(__CLASS__, fn () => $this);
$this->assertSame($manager, $manager->connection(__CLASS__));
}

protected function getApp(array $userConfig)
{
$app = new Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public function getInstanceConfig($name)
'driver' => 'mysql_database-connection',
'mysql_database-connection-option' => 'option-value',
];
case 'custom':
return [
'driver' => 'custom',
];
default:
return [];
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Integration/Support/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ public function testDefaultDriverCannotBeNull()

(new NullableManager($this->app))->driver();
}

public function testCustomDriverClosureBoundObjectIsManager()
{
$manager = new NullableManager($this->app);
$manager->extend(__CLASS__, fn () => $this);
$this->assertSame($manager, $manager->driver(__CLASS__));
}
}
7 changes: 7 additions & 0 deletions tests/Integration/Support/MultipleInstanceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public function test_unresolvable_instances_throw_errors()

$instance = $manager->instance('missing');
}

public function test_custom_driver_closure_bound_object_is_multiple_instance_manager()
{
$manager = new MultipleInstanceManager($this->app);
$manager->extend('custom', fn () => $this);
$this->assertSame($manager, $manager->instance('custom'));
}
}
12 changes: 12 additions & 0 deletions tests/Log/LogManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ public function testDriverUsersPsrLoggerManagerReturnsLogger()
$this->assertCount(1, $loggerSpy->logs);
$this->assertEquals('some alert', $loggerSpy->logs[0]['message']);
}

public function testCustomDriverClosureBoundObjectIsLogManager()
{
$config = $this->app['config'];
$config->set('logging.channels.'.__CLASS__, [
'driver' => __CLASS__,
]);

$manager = new LogManager($this->app);
$manager->extend(__CLASS__, fn () => $this);
$this->assertSame($manager, $manager->channel(__CLASS__)->getLogger());
}
}

class CustomizeFormatter
Expand Down