From 73a1c6b1f984f3219a25194f43e518458f07fdd2 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 12 Jul 2020 14:27:11 +0200 Subject: [PATCH 1/2] Feature/fix json mapper interface not available for di (#4) * Fix JsonMapperInterface to be availalbe in ServiceProvider * Add changelog entry --- CHANGELOG.md | 2 ++ src/ServiceProvider.php | 22 +++++++++++----------- tests/Unit/ServiceProviderTest.php | 4 ++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc4e1a..1516566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Make JsonMapperInterface availalbe in ServiceProvider ## [1.1.0] - 2020-07-12 ### Fixed diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 61b7be5..315f746 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Support\ServiceProvider as BaseServiceProvider; use JsonMapper\JsonMapper; use JsonMapper\JsonMapperFactory; +use JsonMapper\JsonMapperInterface; class ServiceProvider extends BaseServiceProvider { @@ -19,19 +20,18 @@ public function register() { $this->mergeConfigFrom(self::CONFIG_FILE, 'json-mapper'); - switch (config('json-mapper.type')) { - case 'best-fit': - $this->app->singleton(JsonMapper::class, function () { + $config = config('json-mapper.type'); + $this->app->singleton(JsonMapperInterface::class, static function () use ($config) { + switch ($config) { + case 'best-fit': return (new JsonMapperFactory())->bestFit(); - }); - break; - case 'default': - default: - $this->app->singleton(JsonMapper::class, function () { + case 'default': + default: return (new JsonMapperFactory())->default(); - }); - break; - } + } + }); + + $this->app->alias(JsonMapperInterface::class, JsonMapper::class); } /** diff --git a/tests/Unit/ServiceProviderTest.php b/tests/Unit/ServiceProviderTest.php index d3fc31c..a6fb4c5 100644 --- a/tests/Unit/ServiceProviderTest.php +++ b/tests/Unit/ServiceProviderTest.php @@ -6,6 +6,7 @@ use Illuminate\Config\Repository; use JsonMapper\JsonMapper; +use JsonMapper\JsonMapperInterface; use JsonMapper\LaravelPackage\ServiceProvider; use PHPUnit\Framework\TestCase; @@ -38,6 +39,9 @@ public function testRegisterMakesJsonMapperAvailableInApp(): void $serviceProvider->register(); + self::assertTrue($app->has(JsonMapperInterface::class)); + self::assertInstanceOf(JsonMapperInterface::class, $app->make(JsonMapperInterface::class)); + self::assertTrue($app->has(JsonMapper::class)); self::assertInstanceOf(JsonMapper::class, $app->make(JsonMapper::class)); } From de3c96356afd5f08c5715cbb7d18b1c41ca2f4e1 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 12 Jul 2020 14:27:57 +0200 Subject: [PATCH 2/2] Prepare release 1.1.1 --- CHANGELOG.md | 2 ++ Version | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1516566..93a458b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [1.1.1] - 2020-07-12 ### Fixed - Make JsonMapperInterface availalbe in ServiceProvider diff --git a/Version b/Version index 9084fa2..524cb55 100644 --- a/Version +++ b/Version @@ -1 +1 @@ -1.1.0 +1.1.1