Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyvdSluijs committed Jul 12, 2020
2 parents 28133b7 + de3c963 commit f960a19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.1] - 2020-07-12
### Fixed
- Make JsonMapperInterface availalbe in ServiceProvider

## [1.1.0] - 2020-07-12
### Fixed
- Optimised composer dependencies. [PR#2](https://github.com/JsonMapper/LaravelPackage/pull/2)
Expand Down
2 changes: 1 addition & 1 deletion Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
22 changes: 11 additions & 11 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use JsonMapper\JsonMapper;
use JsonMapper\JsonMapperFactory;
use JsonMapper\JsonMapperInterface;

class ServiceProvider extends BaseServiceProvider
{
Expand All @@ -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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Config\Repository;
use JsonMapper\JsonMapper;
use JsonMapper\JsonMapperInterface;
use JsonMapper\LaravelPackage\ServiceProvider;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit f960a19

Please sign in to comment.