From 81aa315264edb35a6d563aab29c2db35412860d8 Mon Sep 17 00:00:00 2001 From: Micheal Mand Date: Mon, 3 Sep 2018 16:06:47 -0600 Subject: [PATCH 1/4] Allow class resolution on short name and abstract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows developers to do: `app(‘modules’)->someMethod();` and `app(Repository::class)->someMethod();` Signed-off-by: Micheal Mand --- src/LaravelModulesServiceProvider.php | 3 ++- src/LumenModulesServiceProvider.php | 3 ++- src/ModulesServiceProvider.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/LaravelModulesServiceProvider.php b/src/LaravelModulesServiceProvider.php index 9cd75f321..57740262e 100644 --- a/src/LaravelModulesServiceProvider.php +++ b/src/LaravelModulesServiceProvider.php @@ -44,10 +44,11 @@ public function setupStubPath() */ protected function registerServices() { - $this->app->singleton('modules', function ($app) { + $this->app->singleton(Repository::class, function ($app) { $path = $app['config']->get('modules.paths.modules'); return new \Nwidart\Modules\Laravel\Repository($app, $path); }); + $this->app->alias(Repository::class, 'modules'); } } diff --git a/src/LumenModulesServiceProvider.php b/src/LumenModulesServiceProvider.php index ee7669c32..31928a163 100644 --- a/src/LumenModulesServiceProvider.php +++ b/src/LumenModulesServiceProvider.php @@ -42,10 +42,11 @@ public function setupStubPath() */ protected function registerServices() { - $this->app->singleton('modules', function ($app) { + $this->app->singleton(Repository::class, function ($app) { $path = $app['config']->get('modules.paths.modules'); return new \Nwidart\Modules\Lumen\Repository($app, $path); }); + $this->app->alias(Repository::class, 'modules'); } } diff --git a/src/ModulesServiceProvider.php b/src/ModulesServiceProvider.php index 6fac2c713..73d62b304 100644 --- a/src/ModulesServiceProvider.php +++ b/src/ModulesServiceProvider.php @@ -63,7 +63,7 @@ abstract protected function registerServices(); */ public function provides() { - return ['modules']; + return [Repository::class, 'modules']; } /** From bd3ae374b0b6a24dab0f13e871aba5998ccfb157 Mon Sep 17 00:00:00 2001 From: Micheal Mand Date: Mon, 10 Sep 2018 13:22:04 -0600 Subject: [PATCH 2/4] Bind to repository interface instead of abstract Signed-off-by: Micheal Mand --- src/LaravelModulesServiceProvider.php | 4 ++-- src/LumenModulesServiceProvider.php | 4 ++-- src/ModulesServiceProvider.php | 2 +- tests/LaravelModulesServiceProviderTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/LaravelModulesServiceProvider.php b/src/LaravelModulesServiceProvider.php index 57740262e..3989e023e 100644 --- a/src/LaravelModulesServiceProvider.php +++ b/src/LaravelModulesServiceProvider.php @@ -44,11 +44,11 @@ public function setupStubPath() */ protected function registerServices() { - $this->app->singleton(Repository::class, function ($app) { + $this->app->singleton(Contracts\RepositoryInterface::class, function ($app) { $path = $app['config']->get('modules.paths.modules'); return new \Nwidart\Modules\Laravel\Repository($app, $path); }); - $this->app->alias(Repository::class, 'modules'); + $this->app->alias(Contracts\RepositoryInterface::class, 'modules'); } } diff --git a/src/LumenModulesServiceProvider.php b/src/LumenModulesServiceProvider.php index 31928a163..20eb7b0f7 100644 --- a/src/LumenModulesServiceProvider.php +++ b/src/LumenModulesServiceProvider.php @@ -42,11 +42,11 @@ public function setupStubPath() */ protected function registerServices() { - $this->app->singleton(Repository::class, function ($app) { + $this->app->singleton(Contracts\RepositoryInterface::class, function ($app) { $path = $app['config']->get('modules.paths.modules'); return new \Nwidart\Modules\Lumen\Repository($app, $path); }); - $this->app->alias(Repository::class, 'modules'); + $this->app->alias(Contracts\RepositoryInterface::class, 'modules'); } } diff --git a/src/ModulesServiceProvider.php b/src/ModulesServiceProvider.php index 73d62b304..53899000d 100644 --- a/src/ModulesServiceProvider.php +++ b/src/ModulesServiceProvider.php @@ -63,7 +63,7 @@ abstract protected function registerServices(); */ public function provides() { - return [Repository::class, 'modules']; + return [Contracts\RepositoryInterface::class, 'modules']; } /** diff --git a/tests/LaravelModulesServiceProviderTest.php b/tests/LaravelModulesServiceProviderTest.php index 58a334058..77fe7291b 100644 --- a/tests/LaravelModulesServiceProviderTest.php +++ b/tests/LaravelModulesServiceProviderTest.php @@ -9,6 +9,6 @@ class LaravelModulesServiceProviderTest extends BaseTestCase /** @test */ public function it_binds_modules_key_to_repository_class() { - $this->assertInstanceOf(Repository::class, app('modules')); + $this->assertInstanceOf(Contracts\RepositoryInterface::class, app('modules')); } } From 1e8a1ab781d0ea623ad9c43758fb9d8ea849a0b8 Mon Sep 17 00:00:00 2001 From: Micheal Mand Date: Mon, 10 Sep 2018 13:24:28 -0600 Subject: [PATCH 3/4] Fix test Signed-off-by: Micheal Mand --- tests/LaravelModulesServiceProviderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/LaravelModulesServiceProviderTest.php b/tests/LaravelModulesServiceProviderTest.php index 77fe7291b..1c75676f4 100644 --- a/tests/LaravelModulesServiceProviderTest.php +++ b/tests/LaravelModulesServiceProviderTest.php @@ -2,13 +2,13 @@ namespace Nwidart\Modules\Tests; -use Nwidart\Modules\Laravel\Repository; +use Nwidart\Modules\Laravel\Contracts\RepositoryInterface; class LaravelModulesServiceProviderTest extends BaseTestCase { /** @test */ public function it_binds_modules_key_to_repository_class() { - $this->assertInstanceOf(Contracts\RepositoryInterface::class, app('modules')); + $this->assertInstanceOf(RepositoryInterface::class, app('modules')); } } From f9ef126a039ed65bb958410ad8cc25a93313f4ed Mon Sep 17 00:00:00 2001 From: Micheal Mand Date: Mon, 10 Sep 2018 13:27:57 -0600 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20test,=20take=20two=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Micheal Mand --- tests/LaravelModulesServiceProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/LaravelModulesServiceProviderTest.php b/tests/LaravelModulesServiceProviderTest.php index 1c75676f4..e7275a63b 100644 --- a/tests/LaravelModulesServiceProviderTest.php +++ b/tests/LaravelModulesServiceProviderTest.php @@ -2,7 +2,7 @@ namespace Nwidart\Modules\Tests; -use Nwidart\Modules\Laravel\Contracts\RepositoryInterface; +use Nwidart\Modules\Contracts\RepositoryInterface; class LaravelModulesServiceProviderTest extends BaseTestCase {