Skip to content

Commit f960a19

Browse files
committed
Merge branch 'release/1.1.1'
2 parents 28133b7 + de3c963 commit f960a19

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.1.1] - 2020-07-12
10+
### Fixed
11+
- Make JsonMapperInterface availalbe in ServiceProvider
12+
913
## [1.1.0] - 2020-07-12
1014
### Fixed
1115
- Optimised composer dependencies. [PR#2](https://github.com/JsonMapper/LaravelPackage/pull/2)

Version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.1.1

src/ServiceProvider.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
88
use JsonMapper\JsonMapper;
99
use JsonMapper\JsonMapperFactory;
10+
use JsonMapper\JsonMapperInterface;
1011

1112
class ServiceProvider extends BaseServiceProvider
1213
{
@@ -19,19 +20,18 @@ public function register()
1920
{
2021
$this->mergeConfigFrom(self::CONFIG_FILE, 'json-mapper');
2122

22-
switch (config('json-mapper.type')) {
23-
case 'best-fit':
24-
$this->app->singleton(JsonMapper::class, function () {
23+
$config = config('json-mapper.type');
24+
$this->app->singleton(JsonMapperInterface::class, static function () use ($config) {
25+
switch ($config) {
26+
case 'best-fit':
2527
return (new JsonMapperFactory())->bestFit();
26-
});
27-
break;
28-
case 'default':
29-
default:
30-
$this->app->singleton(JsonMapper::class, function () {
28+
case 'default':
29+
default:
3130
return (new JsonMapperFactory())->default();
32-
});
33-
break;
34-
}
31+
}
32+
});
33+
34+
$this->app->alias(JsonMapperInterface::class, JsonMapper::class);
3535
}
3636

3737
/**

tests/Unit/ServiceProviderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Config\Repository;
88
use JsonMapper\JsonMapper;
9+
use JsonMapper\JsonMapperInterface;
910
use JsonMapper\LaravelPackage\ServiceProvider;
1011
use PHPUnit\Framework\TestCase;
1112

@@ -38,6 +39,9 @@ public function testRegisterMakesJsonMapperAvailableInApp(): void
3839

3940
$serviceProvider->register();
4041

42+
self::assertTrue($app->has(JsonMapperInterface::class));
43+
self::assertInstanceOf(JsonMapperInterface::class, $app->make(JsonMapperInterface::class));
44+
4145
self::assertTrue($app->has(JsonMapper::class));
4246
self::assertInstanceOf(JsonMapper::class, $app->make(JsonMapper::class));
4347
}

0 commit comments

Comments
 (0)