LayerService::getUserDataService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Aosmak\Laravel\Layer\Sdk\Services;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Container\Container;
7
use Aosmak\Laravel\Layer\Sdk\Routers\Router;
8
use Aosmak\Laravel\Layer\Sdk\Routers\RouterInterface;
9
use Aosmak\Laravel\Layer\Sdk\Traits\ConfigTrait;
10
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\AnnouncementServiceInterface;
11
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\ConversationServiceInterface;
12
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\UserServiceInterface;
13
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\IdentityServiceInterface;
14
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\UserDataServiceInterface;
15
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\RichContentServiceInterface;
16
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\MessageServiceInterface;
17
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\NotificationServiceInterface;
18
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\DataServiceInterface;
19
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\AnnouncementService;
20
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\ConversationService;
21
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\UserService;
22
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\IdentityService;
23
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\UserDataService;
24
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\RichContentService;
25
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\MessageService;
26
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\NotificationService;
27
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\DataService;
28
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\RequestService;
29
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\BaseServiceInterface;
30
31
/**
32
 * Class LayerService
33
 * @package namespace Aosmak\Laravel\Layer\Sdk\Services
34
 */
35
class LayerService implements LayerServiceInterface
36
{
37
    use ConfigTrait;
38
39
    /**
40
     * Client
41
     *
42
     * @var \GuzzleHttp\Client
43
     */
44
    private $client;
45
46
    /**
47
     * Router
48
     *
49
     * @var \Aosmak\Laravel\Layer\Sdk\Routers\Router
50
     */
51
    private $router;
52
53
    /**
54
     * Container
55
     *
56
     * @var \Illuminate\Container\Container
57
     */
58
    private $container;
59
60
    /**
61
     * RequestService
62
     *
63
     * @var \Aosmak\Laravel\Layer\Sdk\Services\Subservices\RequestService
64
     */
65
    private $requestService;
66
67
    /**
68 43
     * Constructor
69
     *
70 43
     * @param \Illuminate\Container\Container $container
71 43
     * @param \GuzzleHttp\Client $client
72 43
     * @param \Aosmak\Laravel\Layer\Sdk\Routers\Router $router
73 43
     * @param \Aosmak\Laravel\Layer\Sdk\Services\Subservices\RequestService $requestService
74 43
     *
75 43
     * @return void
76
     */
77
    public function __construct(Container $container, Client $client, Router $router, RequestService $requestService)
78
    {
79
        $this->container = $container;
80
        $this->client    = $client;
81
        $this->router    = $router;
82 13
        $requestService->setContainer($container);
83
        $this->requestService = $requestService;
84 13
    }
85
86
    /**
87
     * Get a conversation service
88
     *
89
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\ConversationServiceInterface
90
     */
91
    public function getConversationService(): ConversationServiceInterface
92 10
    {
93
        return $this->getService(ConversationService::class);
94 10
    }
95
96
    /**
97
     * Get a message service
98
     *
99
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\MessageServiceInterface
100
     */
101
    public function getMessageService(): MessageServiceInterface
102 30
    {
103
        return $this->getService(MessageService::class);
104 30
    }
105
106
    /**
107
     * Get a user service
108
     *
109
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\UserServiceInterface
110
     */
111
    public function getUserService(): UserServiceInterface
112 11
    {
113
        return $this->getService(UserService::class);
114 11
    }
115
116
    /**
117
     * Get an identity service
118
     *
119
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\IdentityServiceInterface
120
     */
121
    public function getIdentityService(): IdentityServiceInterface
122 8
    {
123
        return $this->getService(IdentityService::class);
124 8
    }
125
126
    /**
127
     * Get a user data service
128
     *
129
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\UserDataServiceInterface
130
     */
131
    public function getUserDataService(): UserDataServiceInterface
132 2
    {
133
        return $this->getService(UserDataService::class);
134 2
    }
135
136
    /**
137
     * Get an announcement service
138
     *
139
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\AnnouncementServiceInterface
140
     */
141
    public function getAnnouncementService(): AnnouncementServiceInterface
142 2
    {
143
        return $this->getService(AnnouncementService::class);
144 2
    }
145
146
    /**
147
     * Get a notification service
148
     *
149
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\NotificationServiceInterface
150
     */
151
    public function getNotificationService(): NotificationServiceInterface
152 16
    {
153
        return $this->getService(NotificationService::class);
154 16
    }
155
156
    /**
157
     * Get a data service
158
     *
159
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\DataServiceInterface
160
     */
161
    public function getDataService(): DataServiceInterface
162 8
    {
163
        return $this->getService(DataService::class);
164 8
    }
165
166
    /**
167
     * Get a rich content service
168
     *
169
     * @return \Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\RichContentServiceInterface
170
     */
171
    public function getRichContentService(): RichContentServiceInterface
172
    {
173
        return $this->getService(RichContentService::class);
174 87
    }
175
176 87
    /**
177 87
     * Get a service
178 53
     *
179 53
     * @param string $serviceName service name
180 53
     *
181 53
     * @return AnnouncementService|ConversationService|UserService|IdentityService|UserDataService|RichContentService|MessageService|NotificationService|DataService
182 53
     */
183 53
    private function getService(string $serviceName): object
184
    {
185 71
        $propName = lcfirst($serviceName);
186
        if (empty($this->$propName)) {
187
            $service = $this->container->make($serviceName);
188 87
            $service->setRequestService($this->requestService);
189
            $service->setConfig($this->config);
190
            $service->setClient($this->client);
191
            $service->setRouter($this->getRouter());
192
            $this->$propName = $service;
193
        }
194
195
        return $this->$propName;
196 53
    }
197
198 53
    /**
199 53
     * Get a router
200 53
     *
201 53
     * @return \Aosmak\Laravel\Layer\Sdk\Routers\RouterInterface $router
202
     */
203
    private function getRouter(): RouterInterface
204
    {
205
        $router = $this->router;
206
        $router->setContainer($this->container);
207
        $router->setAppId($this->config['LAYER_SDK_APP_ID']);
208
        return $router;
209
    }
210
}
211