|
32 | 32 | use CloudCreativity\JsonApi\Contracts\Utils\ConfigurableInterface;
|
33 | 33 | use CloudCreativity\JsonApi\Contracts\Utils\ReplacerInterface;
|
34 | 34 | use CloudCreativity\JsonApi\Contracts\Validators\ValidatorFactoryInterface as BaseValidatorFactoryInterface;
|
| 35 | +use CloudCreativity\JsonApi\Factories\Factory; |
35 | 36 | use CloudCreativity\JsonApi\Http\ApiFactory;
|
36 | 37 | use CloudCreativity\JsonApi\Http\Requests\RequestFactory;
|
37 | 38 | use CloudCreativity\JsonApi\Http\Responses\ResponseFactory;
|
|
61 | 62 | use CloudCreativity\LaravelJsonApi\Services\JsonApiService;
|
62 | 63 | use CloudCreativity\LaravelJsonApi\Validators\ValidatorErrorFactory;
|
63 | 64 | use CloudCreativity\LaravelJsonApi\Validators\ValidatorFactory;
|
| 65 | +use Illuminate\Contracts\Foundation\Application; |
64 | 66 | use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
|
65 | 67 | use Illuminate\Routing\Router;
|
66 | 68 | 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; |
67 | 73 | use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
|
68 | 74 | use Neomerx\JsonApi\Contracts\Http\HttpFactoryInterface;
|
69 | 75 | use Neomerx\JsonApi\Contracts\Http\ResponsesInterface;
|
70 | 76 | use Neomerx\JsonApi\Contracts\Schema\SchemaFactoryInterface;
|
71 |
| -use Neomerx\JsonApi\Factories\Factory; |
| 77 | +use Psr\Log\LoggerInterface; |
72 | 78 |
|
73 | 79 | /**
|
74 | 80 | * Class ServiceProvider
|
@@ -185,12 +191,33 @@ protected function bootResponseMacro(ResponseFactoryContract $responses)
|
185 | 191 |
|
186 | 192 | /**
|
187 | 193 | * 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. |
188 | 205 | */
|
189 | 206 | protected function bindNeomerx()
|
190 | 207 | {
|
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); |
194 | 221 | }
|
195 | 222 |
|
196 | 223 | /**
|
|
0 commit comments