8000 Merge tag 'v0.6.1' into develop · volldigital/laravel-json-api@6af7b63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6af7b63

Browse files
committed
Merge tag 'v0.6.1' into develop
Update factory service container bindings
2 parents f850256 + ed398ff commit 6af7b63

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## [0.6.1] - 2017-02-22
6+
7+
### Changed
8+
- Updated service provider bindings for the `neomerx/json-api` factories.
9+
510
## [0.6.0] - 2017-02-20
611

712
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"require": {
2525
"php": "^5.6|^7.0",
2626
"laravel/framework": "5.1.*|5.2.*|5.3.*|5.4.*",
27-
"cloudcreativity/json-api": "^0.7",
27+
"cloudcreativity/json-api": "^0.7.1",
2828
"symfony/psr-http-message-bridge": "^1.0",
2929
"zendframework/zend-diactoros": "^1.3"
3030
},

src/ServiceProvider.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use CloudCreativity\JsonApi\Contracts\Utils\ConfigurableInterface;
3333
use CloudCreativity\JsonApi\Contracts\Utils\ReplacerInterface;
3434
use CloudCreativity\JsonApi\Contracts\Validators\ValidatorFactoryInterface as BaseValidatorFactoryInterface;
35+
use CloudCreativity\JsonApi\Factories\Factory;
3536
use CloudCreativity\JsonApi\Http\ApiFactory;
3637
use CloudCreativity\JsonApi\Http\Requests\RequestFactory;
3738
use CloudCreativity\JsonApi\Http\Responses\ResponseFactory;
@@ -61,14 +62,19 @@
6162
use CloudCreativity\LaravelJsonApi\Services\JsonApiService;
6263
use CloudCreativity\LaravelJsonApi\Validators\ValidatorErrorFactory;
6364
use CloudCreativity\LaravelJsonApi\Validators\ValidatorFactory;
65+
use Illuminate\Contracts\Foundation\Application;
6466
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
6567
use Illuminate\Routing\Router;
6668
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
69+
use Neomerx\JsonApi\Contracts\Document\DocumentFactoryInterface;
70+
use Neomerx\JsonApi\Contracts\Encoder\Handlers\HandlerFactoryInterface;
71+
use Neomerx\JsonApi\Contracts\Encoder\Parser\ParserFactoryInterface;
72+
use Neomerx\JsonApi\Contracts\Encoder\Stack\StackFactoryInterface;
6773
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
6874
use Neomerx\JsonApi\Contracts\Http\HttpFactoryInterface;
6975
use Neomerx\JsonApi\Contracts\Http\ResponsesInterface;
7076
use Neomerx\JsonApi\Contracts\Schema\SchemaFactoryInterface;
71-
use Neomerx\JsonApi\Factories\Factory;
77+
use Psr\Log\LoggerInterface;
7278

7379
/**
7480
* Class ServiceProvider
@@ -185,12 +191,33 @@ protected function bootResponseMacro(ResponseFactoryContract $responses)
185191

186192
/**
187193
* Bind parts of the neomerx/json-api dependency into the service container.
194+
*
195+
* For this Laravel JSON API package, we use our extended JSON API factory.
196+
* This ensures that we can override any parts of the Neomerx JSON API pacakge
197+
* that we want.
198+
*
199+
* As the Neomerx package splits the factories into multiple interfaces, we
200+
* also register aliases for each of the factory interfaces.
201+
*
202+
* The Neomerx package allows a logger to be injected into the factory. This
203+
* enables the Neomerx package to log messages. When creating the factory, we
204+
* therefore set the logger as our application's logger.
188205
*/
189206
protected function bindNeomerx()
190207
{
191-
$this->app->singleton(FactoryInterface::class, Factory::class);
192-
$this->app->singleton(SchemaFactoryInterface::class, FactoryInterface::class);
193-
$this->app->singleton(HttpFactoryInterface::class, FactoryInterface::class);
208+
$this->app->singleton(Factory::class, function (Application $app) {
209+
$factory = new Factory();
210+
$factory->setLogger($app->make(LoggerInterface::class));
211+
return $factory;
212+
});
213+
214+
$this->app->alias(Factory::class, FactoryInterface::class);
215+
$this->app->alias(Factory::class, DocumentFactoryInterface::class);
216+
$this->app->alias(Factory::class, HandlerFactoryInterface::class);
217+
$this->app->alias(Factory::class, HttpFactoryInterface::class);
218+
$this->app->alias(Factory::class, ParserFactoryInterface::class);
219+
$this->app->alias(Factory::class, SchemaFactoryInterface::class);
220+
$this->app->alias(Factory::class, StackFactoryInterface::class);
194221
}
195222

196223
/**

0 commit comments

Comments
 (0)
0