From 5f992f42046ffb8887a19aceaf78407eb5c10269 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 25 Jul 2024 10:07:38 +0100 Subject: [PATCH 01/11] storage attribute --- .../Container/Attributes/Storage.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Illuminate/Container/Attributes/Storage.php diff --git a/src/Illuminate/Container/Attributes/Storage.php b/src/Illuminate/Container/Attributes/Storage.php new file mode 100644 index 000000000000..1a89b2e6b939 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Storage.php @@ -0,0 +1,30 @@ +make('filesystem')->disk($attribute->disk); + } +} From c94c32881f468e56af234132436917f74dcb38ce Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 25 Jul 2024 10:18:15 +0100 Subject: [PATCH 02/11] test storage attribute --- .../ContextualAttributeBindingTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index a474cbbba531..ab216ba3738c 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -4,12 +4,21 @@ use Attribute; use Illuminate\Config\Repository; +use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; use Illuminate\Contracts\Container\ContextualAttribute; +use Illuminate\Contracts\Filesystem\Filesystem; +use Illuminate\Filesystem\FilesystemManager; +use Mockery as m; use PHPUnit\Framework\TestCase; class ContextualAttributeBindingTest extends TestCase { + protected function tearDown(): void + { + m::close(); + } + public function testDependencyCanBeResolvedFromAttributeBinding() { $container = new Container; @@ -75,6 +84,20 @@ public function testDependencyWithAfterCallbackAttributeCanBeResolved() $this->assertEquals('Developer', $class->person->role); } + + public function testStorageAttribute() + { + $container = new Container; + $container->singleton('filesystem', function () { + $mockFilesystemManager = m::mock(FilesystemManager::class); + $mockFilesystemManager->shouldReceive('disk')->with('foo')->andReturn(m::mock(Filesystem::class)); + $mockFilesystemManager->shouldReceive('disk')->with('bar')->andReturn(m::mock(Filesystem::class)); + + return $mockFilesystemManager; + }); + + $container->make(StorageTest::class); + } } #[Attribute(Attribute::TARGET_PARAMETER)] @@ -179,3 +202,10 @@ public function __construct( ) { } } + +final class StorageTest +{ + public function __construct(#[Storage('foo')] Filesystem $foo, #[Storage('bar')] Filesystem $bar) + { + } +} From ac65ea245c4d72aea08ad92c67b4681126768dcc Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 25 Jul 2024 10:22:45 +0100 Subject: [PATCH 03/11] test config attribute --- .../ContextualAttributeBindingTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index ab216ba3738c..24ac0693ee64 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -4,6 +4,7 @@ use Attribute; use Illuminate\Config\Repository; +use Illuminate\Container\Attributes\Config; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; use Illuminate\Contracts\Container\ContextualAttribute; @@ -85,6 +86,20 @@ public function testDependencyWithAfterCallbackAttributeCanBeResolved() $this->assertEquals('Developer', $class->person->role); } + public function testConfigAttribute() + { + $container = new Container; + $container->singleton('config', function () { + $mockConfig = m::mock(Repository::class); + $mockConfig->shouldReceive('get')->with('foo', null)->andReturn('foo'); + $mockConfig->shouldReceive('get')->with('bar', null)->andReturn('bar'); + + return $mockConfig; + }); + + $container->make(ConfigTest::class); + } + public function testStorageAttribute() { $container = new Container; @@ -203,6 +218,13 @@ public function __construct( } } +final class ConfigTest +{ + public function __construct(#[Config('foo')] string $foo, #[Config('bar')] string $bar) + { + } +} + final class StorageTest { public function __construct(#[Storage('foo')] Filesystem $foo, #[Storage('bar')] Filesystem $bar) From d6f61fdd39c155b20fa3c83a30ef8408cf797f99 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 25 Jul 2024 10:37:43 +0100 Subject: [PATCH 04/11] correct return type --- src/Illuminate/Container/Attributes/Storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Container/Attributes/Storage.php b/src/Illuminate/Container/Attributes/Storage.php index 1a89b2e6b939..f507b26b4626 100644 --- a/src/Illuminate/Container/Attributes/Storage.php +++ b/src/Illuminate/Container/Attributes/Storage.php @@ -21,7 +21,7 @@ public function __construct(public string $disk) * * @param self $attribute * @param \Illuminate\Contracts\Container\Container $container - * @return mixed + * @return \Illuminate\Contracts\Filesystem\Filesystem */ public static function resolve(self $attribute, Container $container) { From 9531576018a90986aaf4dcb6fac21f1ef7a0d2b8 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 30 Jul 2024 08:46:41 +0100 Subject: [PATCH 05/11] cache, db, log attrs --- src/Illuminate/Container/Attributes/Cache.php | 30 +++++++ .../Container/Attributes/Database.php | 30 +++++++ src/Illuminate/Container/Attributes/Log.php | 30 +++++++ .../Container/Attributes/Storage.php | 2 +- .../ContextualAttributeBindingTest.php | 88 +++++++++++++++++-- 5 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 src/Illuminate/Container/Attributes/Cache.php create mode 100644 src/Illuminate/Container/Attributes/Database.php create mode 100644 src/Illuminate/Container/Attributes/Log.php diff --git a/src/Illuminate/Container/Attributes/Cache.php b/src/Illuminate/Container/Attributes/Cache.php new file mode 100644 index 000000000000..f851e0d68411 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Cache.php @@ -0,0 +1,30 @@ +make('cache')->driver($attribute->driver); + } +} diff --git a/src/Illuminate/Container/Attributes/Database.php b/src/Illuminate/Container/Attributes/Database.php new file mode 100644 index 000000000000..262e3061dea1 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Database.php @@ -0,0 +1,30 @@ +make('db')->connection($attribute->connection); + } +} diff --git a/src/Illuminate/Container/Attributes/Log.php b/src/Illuminate/Container/Attributes/Log.php new file mode 100644 index 000000000000..cfbf763a37a5 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Log.php @@ -0,0 +1,30 @@ +make('log')->driver($attribute->driver); + } +} diff --git a/src/Illuminate/Container/Attributes/Storage.php b/src/Illuminate/Container/Attributes/Storage.php index f507b26b4626..b9a16d19817a 100644 --- a/src/Illuminate/Container/Attributes/Storage.php +++ b/src/Illuminate/Container/Attributes/Storage.php @@ -12,7 +12,7 @@ class Storage implements ContextualAttribute /** * Create a new class instance. */ - public function __construct(public string $disk) + public function __construct(public ?string $disk = null) { } diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index 24ac0693ee64..a91c1c6853bc 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -3,15 +3,24 @@ namespace Illuminate\Tests\Container; use Attribute; +use Illuminate\Cache\CacheManager; +use Illuminate\Cache\Repository as CacheRepository; use Illuminate\Config\Repository; +use Illuminate\Container\Attributes\Cache; use Illuminate\Container\Attributes\Config; +use Illuminate\Container\Attributes\Database; +use Illuminate\Container\Attributes\Log; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; use Illuminate\Contracts\Container\ContextualAttribute; use Illuminate\Contracts\Filesystem\Filesystem; +use Illuminate\Database\Connection; +use Illuminate\Database\DatabaseManager; use Illuminate\Filesystem\FilesystemManager; +use Illuminate\Log\LogManager; use Mockery as m; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; class ContextualAttributeBindingTest extends TestCase { @@ -86,29 +95,71 @@ public function testDependencyWithAfterCallbackAttributeCanBeResolved() $this->assertEquals('Developer', $class->person->role); } + public function testCacheAttribute() + { + $container = new Container; + $container->singleton('cache', function () { + $manager = m::mock(CacheManager::class); + $manager->shouldReceive('driver')->with('foo')->andReturn(m::mock(CacheRepository::class)); + $manager->shouldReceive('driver')->with('bar')->andReturn(m::mock(CacheRepository::class)); + + return $manager; + }); + + $container->make(CacheTest::class); + } + public function testConfigAttribute() { $container = new Container; $container->singleton('config', function () { - $mockConfig = m::mock(Repository::class); - $mockConfig->shouldReceive('get')->with('foo', null)->andReturn('foo'); - $mockConfig->shouldReceive('get')->with('bar', null)->andReturn('bar'); + $repository = m::mock(Repository::class); + $repository->shouldReceive('get')->with('foo', null)->andReturn('foo'); + $repository->shouldReceive('get')->with('bar', null)->andReturn('bar'); - return $mockConfig; + return $repository; }); $container->make(ConfigTest::class); } + public function testDatabaseAttribute() + { + $container = new Container; + $container->singleton('db', function () { + $manager = m::mock(DatabaseManager::class); + $manager->shouldReceive('connection')->with('foo')->andReturn(m::mock(Connection::class)); + $manager->shouldReceive('connection')->with('bar')->andReturn(m::mock(Connection::class)); + + return $manager; + }); + + $container->make(DatabaseTest::class); + } + + public function testLogAttribute() + { + $container = new Container; + $container->singleton('log', function () { + $manager = m::mock(LogManager::class); + $manager->shouldReceive('driver')->with('foo')->andReturn(m::mock(LoggerInterface::class)); + $manager->shouldReceive('driver')->with('bar')->andReturn(m::mock(LoggerInterface::class)); + + return $manager; + }); + + $container->make(LogTest::class); + } + public function testStorageAttribute() { $container = new Container; $container->singleton('filesystem', function () { - $mockFilesystemManager = m::mock(FilesystemManager::class); - $mockFilesystemManager->shouldReceive('disk')->with('foo')->andReturn(m::mock(Filesystem::class)); - $mockFilesystemManager->shouldReceive('disk')->with('bar')->andReturn(m::mock(Filesystem::class)); + $manager = m::mock(FilesystemManager::class); + $manager->shouldReceive('disk')->with('foo')->andReturn(m::mock(Filesystem::class)); + $manager->shouldReceive('disk')->with('bar')->andReturn(m::mock(Filesystem::class)); - return $mockFilesystemManager; + return $manager; }); $container->make(StorageTest::class); @@ -218,6 +269,13 @@ public function __construct( } } +final class CacheTest +{ + public function __construct(#[Cache('foo')] CacheRepository $foo, #[Cache('bar')] CacheRepository $bar) + { + } +} + final class ConfigTest { public function __construct(#[Config('foo')] string $foo, #[Config('bar')] string $bar) @@ -225,6 +283,20 @@ public function __construct(#[Config('foo')] string $foo, #[Config('bar')] strin } } +final class DatabaseTest +{ + public function __construct(#[Database('foo')] Connection $foo, #[Database('bar')] Connection $bar) + { + } +} + +final class LogTest +{ + public function __construct(#[Log('foo')] LoggerInterface $foo, #[Log('bar')] LoggerInterface $bar) + { + } +} + final class StorageTest { public function __construct(#[Storage('foo')] Filesystem $foo, #[Storage('bar')] Filesystem $bar) From 0fb9d72298dcfa3f5a5c48f9825daf2343c4b2cc Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 30 Jul 2024 09:46:29 +0100 Subject: [PATCH 06/11] guard attr --- src/Illuminate/Container/Attributes/Guard.php | 30 +++++++++++++++++++ .../ContextualAttributeBindingTest.php | 24 +++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/Illuminate/Container/Attributes/Guard.php diff --git a/src/Illuminate/Container/Attributes/Guard.php b/src/Illuminate/Container/Attributes/Guard.php new file mode 100644 index 000000000000..aa7ef064a9a3 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Guard.php @@ -0,0 +1,30 @@ +make('auth')->guard($attribute->guard); + } +} diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index a91c1c6853bc..cf68c4f1fa48 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -3,15 +3,18 @@ namespace Illuminate\Tests\Container; use Attribute; +use Illuminate\Auth\AuthManager; use Illuminate\Cache\CacheManager; use Illuminate\Cache\Repository as CacheRepository; use Illuminate\Config\Repository; use Illuminate\Container\Attributes\Cache; use Illuminate\Container\Attributes\Config; use Illuminate\Container\Attributes\Database; +use Illuminate\Container\Attributes\Guard; use Illuminate\Container\Attributes\Log; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; +use Illuminate\Contracts\Auth\Guard as GuardContract; use Illuminate\Contracts\Container\ContextualAttribute; use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Database\Connection; @@ -137,6 +140,20 @@ public function testDatabaseAttribute() $container->make(DatabaseTest::class); } + public function testGuardAttribute() + { + $container = new Container; + $container->singleton('auth', function () { + $manager = m::mock(AuthManager::class); + $manager->shouldReceive('guard')->with('foo')->andReturn(m::mock(GuardContract::class)); + $manager->shouldReceive('guard')->with('bar')->andReturn(m::mock(GuardContract::class)); + + return $manager; + }); + + $container->make(GuardTest::class); + } + public function testLogAttribute() { $container = new Container; @@ -290,6 +307,13 @@ public function __construct(#[Database('foo')] Connection $foo, #[Database('bar' } } +final class GuardTest +{ + public function __construct(#[Guard('foo')] GuardContract $foo, #[Guard('bar')] GuardContract $bar) + { + } +} + final class LogTest { public function __construct(#[Log('foo')] LoggerInterface $foo, #[Log('bar')] LoggerInterface $bar) From 415dc123391451531e0b5d827ce83494c02e372c Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 30 Jul 2024 09:52:59 +0100 Subject: [PATCH 07/11] authed attr --- .../Container/Attributes/Authed.php | 30 ++++++++++++++++ .../ContextualAttributeBindingTest.php | 34 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/Illuminate/Container/Attributes/Authed.php diff --git a/src/Illuminate/Container/Attributes/Authed.php b/src/Illuminate/Container/Attributes/Authed.php new file mode 100644 index 000000000000..18f874e1eca4 --- /dev/null +++ b/src/Illuminate/Container/Attributes/Authed.php @@ -0,0 +1,30 @@ +make('auth')->guard($attribute->guard)->user(); + } +} diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index cf68c4f1fa48..bb67cda0c6cd 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -7,6 +7,7 @@ use Illuminate\Cache\CacheManager; use Illuminate\Cache\Repository as CacheRepository; use Illuminate\Config\Repository; +use Illuminate\Container\Attributes\Authed; use Illuminate\Container\Attributes\Cache; use Illuminate\Container\Attributes\Config; use Illuminate\Container\Attributes\Database; @@ -14,6 +15,8 @@ use Illuminate\Container\Attributes\Log; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Guard as GuardContract; use Illuminate\Contracts\Container\ContextualAttribute; use Illuminate\Contracts\Filesystem\Filesystem; @@ -98,6 +101,30 @@ public function testDependencyWithAfterCallbackAttributeCanBeResolved() $this->assertEquals('Developer', $class->person->role); } + public function testAuthedAttribute() + { + $container = new Container; + $container->singleton('auth', function () { + $manager = m::mock(AuthManager::class); + $manager->shouldReceive('guard')->with('foo')->andReturnUsing(function () { + $guard = m::mock(GuardContract::class); + $guard->shouldReceive('user')->andReturn(m:mock(AuthenticatableContract::class)); + + return $guard; + }); + $manager->shouldReceive('guard')->with('bar')->andReturnUsing(function () { + $guard = m::mock(GuardContract::class); + $guard->shouldReceive('user')->andReturn(m:mock(AuthenticatableContract::class)); + + return $guard; + }); + + return $manager; + }); + + $container->make(GuardTest::class); + } + public function testCacheAttribute() { $container = new Container; @@ -286,6 +313,13 @@ public function __construct( } } +final class AuthedTest +{ + public function __construct(#[Authed('foo')] AuthenticatableContract $foo, #[Cache('bar')] AuthenticatableContract $bar) + { + } +} + final class CacheTest { public function __construct(#[Cache('foo')] CacheRepository $foo, #[Cache('bar')] CacheRepository $bar) From c4aa77a2e304fbcb14f059eac512e6e731c29cc2 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 30 Jul 2024 09:57:46 +0100 Subject: [PATCH 08/11] fix cs --- tests/Container/ContextualAttributeBindingTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index bb67cda0c6cd..0b6508158e80 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -15,7 +15,6 @@ use Illuminate\Container\Attributes\Log; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; -use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Guard as GuardContract; use Illuminate\Contracts\Container\ContextualAttribute; From dc367495f589e67960166a0813eed297e2c1117e Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 30 Jul 2024 10:13:58 +0100 Subject: [PATCH 09/11] fix tests --- tests/Container/ContextualAttributeBindingTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index 0b6508158e80..33607a669228 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -121,7 +121,7 @@ public function testAuthedAttribute() return $manager; }); - $container->make(GuardTest::class); + $container->make(AuthedTest::class); } public function testCacheAttribute() @@ -314,7 +314,7 @@ public function __construct( final class AuthedTest { - public function __construct(#[Authed('foo')] AuthenticatableContract $foo, #[Cache('bar')] AuthenticatableContract $bar) + public function __construct(#[Authed('foo')] AuthenticatableContract $foo, #[Authed('bar')] AuthenticatableContract $bar) { } } From 39b86a0a012e9b1b1f21ed800ecc32fad3f33bac Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 5 Aug 2024 09:49:36 -0500 Subject: [PATCH 10/11] rename files --- .../Attributes/{Guard.php => Auth.php} | 4 ++-- .../{Authed.php => Authenticated.php} | 4 ++-- src/Illuminate/Container/Attributes/Cache.php | 6 +++--- .../Container/Attributes/CurrentUser.php | 11 ++++++++++ src/Illuminate/Container/Attributes/Log.php | 6 +++--- .../ContextualAttributeBindingTest.php | 21 ++++++++++--------- 6 files changed, 32 insertions(+), 20 deletions(-) rename src/Illuminate/Container/Attributes/{Guard.php => Auth.php} (89%) rename src/Illuminate/Container/Attributes/{Authed.php => Authenticated.php} (87%) create mode 100644 src/Illuminate/Container/Attributes/CurrentUser.php diff --git a/src/Illuminate/Container/Attributes/Guard.php b/src/Illuminate/Container/Attributes/Auth.php similarity index 89% rename from src/Illuminate/Container/Attributes/Guard.php rename to src/Illuminate/Container/Attributes/Auth.php index aa7ef064a9a3..4cf0c1a4cc68 100644 --- a/src/Illuminate/Container/Attributes/Guard.php +++ b/src/Illuminate/Container/Attributes/Auth.php @@ -7,7 +7,7 @@ use Illuminate\Contracts\Container\ContextualAttribute; #[Attribute(Attribute::TARGET_PARAMETER)] -class Guard implements ContextualAttribute +class Auth implements ContextualAttribute { /** * Create a new class instance. @@ -17,7 +17,7 @@ public function __construct(public ?string $guard = null) } /** - * Resolve the auth guard. + * Resolve the authentication guard. * * @param self $attribute * @param \Illuminate\Contracts\Container\Container $container diff --git a/src/Illuminate/Container/Attributes/Authed.php b/src/Illuminate/Container/Attributes/Authenticated.php similarity index 87% rename from src/Illuminate/Container/Attributes/Authed.php rename to src/Illuminate/Container/Attributes/Authenticated.php index 18f874e1eca4..67cdd53cc3cf 100644 --- a/src/Illuminate/Container/Attributes/Authed.php +++ b/src/Illuminate/Container/Attributes/Authenticated.php @@ -7,7 +7,7 @@ use Illuminate\Contracts\Container\ContextualAttribute; #[Attribute(Attribute::TARGET_PARAMETER)] -class Authed implements ContextualAttribute +class Authenticated implements ContextualAttribute { /** * Create a new class instance. @@ -17,7 +17,7 @@ public function __construct(public ?string $guard = null) } /** - * Resolve the authed user. + * Resolve the currently authenticated user. * * @param self $attribute * @param \Illuminate\Contracts\Container\Container $container diff --git a/src/Illuminate/Container/Attributes/Cache.php b/src/Illuminate/Container/Attributes/Cache.php index f851e0d68411..2b7b1f78e038 100644 --- a/src/Illuminate/Container/Attributes/Cache.php +++ b/src/Illuminate/Container/Attributes/Cache.php @@ -12,12 +12,12 @@ class Cache implements ContextualAttribute /** * Create a new class instance. */ - public function __construct(public ?string $driver = null) + public function __construct(public ?string $store = null) { } /** - * Resolve the cache driver. + * Resolve the cache store. * * @param self $attribute * @param \Illuminate\Contracts\Container\Container $container @@ -25,6 +25,6 @@ public function __construct(public ?string $driver = null) */ public static function resolve(self $attribute, Container $container) { - return $container->make('cache')->driver($attribute->driver); + return $container->make('cache')->store($attribute->store); } } diff --git a/src/Illuminate/Container/Attributes/CurrentUser.php b/src/Illuminate/Container/Attributes/CurrentUser.php new file mode 100644 index 000000000000..7c13b4efee58 --- /dev/null +++ b/src/Illuminate/Container/Attributes/CurrentUser.php @@ -0,0 +1,11 @@ +make('log')->driver($attribute->driver); + return $container->make('log')->channel($attribute->channel); } } diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index 33607a669228..b7360da204aa 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -7,11 +7,12 @@ use Illuminate\Cache\CacheManager; use Illuminate\Cache\Repository as CacheRepository; use Illuminate\Config\Repository; -use Illuminate\Container\Attributes\Authed; +use Illuminate\Container\Attributes\Auth; +use Illuminate\Container\Attributes\Authenticated; use Illuminate\Container\Attributes\Cache; use Illuminate\Container\Attributes\Config; +use Illuminate\Container\Attributes\CurrentUser; use Illuminate\Container\Attributes\Database; -use Illuminate\Container\Attributes\Guard; use Illuminate\Container\Attributes\Log; use Illuminate\Container\Attributes\Storage; use Illuminate\Container\Container; @@ -129,8 +130,8 @@ public function testCacheAttribute() $container = new Container; $container->singleton('cache', function () { $manager = m::mock(CacheManager::class); - $manager->shouldReceive('driver')->with('foo')->andReturn(m::mock(CacheRepository::class)); - $manager->shouldReceive('driver')->with('bar')->andReturn(m::mock(CacheRepository::class)); + $manager->shouldReceive('store')->with('foo')->andReturn(m::mock(CacheRepository::class)); + $manager->shouldReceive('store')->with('bar')->andReturn(m::mock(CacheRepository::class)); return $manager; }); @@ -166,9 +167,9 @@ public function testDatabaseAttribute() $container->make(DatabaseTest::class); } - public function testGuardAttribute() + public function testAuthAttribute() { - $container = new Container; + $container = new Container;# $container->singleton('auth', function () { $manager = m::mock(AuthManager::class); $manager->shouldReceive('guard')->with('foo')->andReturn(m::mock(GuardContract::class)); @@ -185,8 +186,8 @@ public function testLogAttribute() $container = new Container; $container->singleton('log', function () { $manager = m::mock(LogManager::class); - $manager->shouldReceive('driver')->with('foo')->andReturn(m::mock(LoggerInterface::class)); - $manager->shouldReceive('driver')->with('bar')->andReturn(m::mock(LoggerInterface::class)); + $manager->shouldReceive('channel')->with('foo')->andReturn(m::mock(LoggerInterface::class)); + $manager->shouldReceive('channel')->with('bar')->andReturn(m::mock(LoggerInterface::class)); return $manager; }); @@ -314,7 +315,7 @@ public function __construct( final class AuthedTest { - public function __construct(#[Authed('foo')] AuthenticatableContract $foo, #[Authed('bar')] AuthenticatableContract $bar) + public function __construct(#[Authenticated('foo')] AuthenticatableContract $foo, #[CurrentUser('bar')] AuthenticatableContract $bar) { } } @@ -342,7 +343,7 @@ public function __construct(#[Database('foo')] Connection $foo, #[Database('bar' final class GuardTest { - public function __construct(#[Guard('foo')] GuardContract $foo, #[Guard('bar')] GuardContract $bar) + public function __construct(#[Auth('foo')] GuardContract $foo, #[Auth('bar')] GuardContract $bar) { } } From 7e66b567fc9bc6e786239a740e7f04252c57fe3e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 5 Aug 2024 09:58:40 -0500 Subject: [PATCH 11/11] add db --- src/Illuminate/Container/Attributes/DB.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Illuminate/Container/Attributes/DB.php diff --git a/src/Illuminate/Container/Attributes/DB.php b/src/Illuminate/Container/Attributes/DB.php new file mode 100644 index 000000000000..b6337669be46 --- /dev/null +++ b/src/Illuminate/Container/Attributes/DB.php @@ -0,0 +1,11 @@ +