1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Swis\JsonApi\Client\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
6
|
|
|
use Swis\JsonApi\Client\Client; |
7
|
|
|
use Swis\JsonApi\Client\DocumentClient; |
8
|
|
|
use Swis\JsonApi\Client\Interfaces\ClientInterface; |
9
|
|
|
use Swis\JsonApi\Client\Interfaces\DocumentClientInterface; |
10
|
|
|
use Swis\JsonApi\Client\Interfaces\DocumentParserInterface; |
11
|
|
|
use Swis\JsonApi\Client\Interfaces\ResponseParserInterface; |
12
|
|
|
use Swis\JsonApi\Client\Interfaces\TypeMapperInterface; |
13
|
|
|
use Swis\JsonApi\Client\Parsers\DocumentParser; |
14
|
|
|
use Swis\JsonApi\Client\Parsers\ResponseParser; |
15
|
|
|
use Swis\JsonApi\Client\TypeMapper; |
16
|
|
|
|
17
|
|
|
class ServiceProvider extends BaseServiceProvider |
18
|
|
|
{ |
19
|
|
|
public function register() |
20
|
|
|
{ |
21
|
|
|
$this->mergeConfigFrom( |
22
|
|
|
dirname(__DIR__, 2).'/config/jsonapi.php', |
23
|
|
|
'jsonapi' |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
$this->registerSharedTypeMapper(); |
27
|
|
|
$this->registerParsers(); |
28
|
|
|
$this->registerClients(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function boot() |
32
|
|
|
{ |
33
|
|
|
$this->publishes([ |
34
|
|
|
dirname(__DIR__, 2).'/config/' => config_path(), |
35
|
|
|
], 'config'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function registerSharedTypeMapper() |
39
|
|
|
{ |
40
|
|
|
$this->app->singleton(TypeMapperInterface::class, TypeMapper::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function registerParsers() |
44
|
|
|
{ |
45
|
|
|
$this->app->bind(DocumentParserInterface::class, DocumentParser::class); |
46
|
|
|
$this->app->bind(ResponseParserInterface::class, ResponseParser::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function registerClients() |
50
|
|
|
{ |
51
|
|
|
$this->app->extend( |
52
|
|
|
ClientInterface::class, |
53
|
|
|
static function (ClientInterface $client) { |
54
|
|
|
$client->setBaseUri(config('jsonapi.base_uri')); |
55
|
|
|
|
56
|
|
|
return $client; |
57
|
|
|
} |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->app->bind(ClientInterface::class, Client::class); |
61
|
|
|
$this->app->bind(DocumentClientInterface::class, DocumentClient::class); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|