1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* @author Anton Kartsev <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Bigperson\AmoCrmApi; |
12
|
|
|
|
13
|
|
|
use Illuminate\Support\ServiceProvider; |
|
|
|
|
14
|
|
|
use linkprofit\AmoCRM\RequestHandler; |
15
|
|
|
use linkprofit\AmoCRM\services\AccountService; |
16
|
|
|
use linkprofit\AmoCRM\services\CatalogElementService; |
|
|
|
|
17
|
|
|
use linkprofit\AmoCRM\services\CatalogService; |
18
|
|
|
use linkprofit\AmoCRM\services\CompanyService; |
19
|
|
|
use linkprofit\AmoCRM\services\ContactService; |
20
|
|
|
use linkprofit\AmoCRM\services\CustomerService; |
21
|
|
|
use linkprofit\AmoCRM\services\FieldService; |
22
|
|
|
use linkprofit\AmoCRM\services\LeadService; |
23
|
|
|
use linkprofit\AmoCRM\services\NoteService; |
24
|
|
|
use linkprofit\AmoCRM\services\PipelineService; |
25
|
|
|
use linkprofit\AmoCRM\services\TaskService; |
26
|
|
|
use linkprofit\AmoCRM\services\TaskTypeService; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class AmoCrmApiServiceProvider. |
30
|
|
|
*/ |
31
|
|
|
class AmoCrmApiServiceProvider extends ServiceProvider |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
protected $defer = true; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Local config file path. |
38
|
|
|
*/ |
39
|
|
|
private const CONFIG_PATH = __DIR__.'/../config/amocrm-api.php'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array List of services |
43
|
|
|
*/ |
44
|
|
|
protected $services = [ |
45
|
|
|
AccountService::class, |
46
|
|
|
CatalogElementService::class, |
47
|
|
|
CatalogService::class, |
48
|
|
|
CompanyService::class, |
49
|
|
|
ContactService::class, |
50
|
|
|
CustomerService::class, |
51
|
|
|
FieldService::class, |
52
|
|
|
LeadService::class, |
53
|
|
|
NoteService::class, |
54
|
|
|
PipelineService::class, |
55
|
|
|
TaskService::class, |
56
|
|
|
TaskTypeService::class, |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Bootstrap the application services. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function boot() |
65
|
|
|
{ |
66
|
|
|
$this->shareResources(); |
67
|
|
|
$this->mergeConfigFrom(self::CONFIG_PATH, 'amocrm-api'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Register the application services. |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function register() |
76
|
|
|
{ |
77
|
|
|
$this->registerRequestHandler(); |
78
|
|
|
$this->registerAuthorizationService(); |
79
|
|
|
$this->registerServices(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
private function shareResources(): void |
86
|
|
|
{ |
87
|
|
|
$publishes = [ |
88
|
|
|
self::CONFIG_PATH => \config_path('amocrm-api.php'), |
|
|
|
|
89
|
|
|
]; |
90
|
|
|
$this->publishes($publishes, 'amocrm-api'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return void Register Request Handler |
95
|
|
|
*/ |
96
|
|
|
private function registerRequestHandler() |
97
|
|
|
{ |
98
|
|
|
$this->app->singleton(RequestHandler::class, function ($app) { |
|
|
|
|
99
|
|
|
$request = new \linkprofit\AmoCRM\RequestHandler(); |
100
|
|
|
$request->setSubdomain(config('amocrm.domain')); |
|
|
|
|
101
|
|
|
|
102
|
|
|
return $request; |
103
|
|
|
}); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return void Register and authorize Authorization Service |
108
|
|
|
*/ |
109
|
|
|
private function registerAuthorizationService() |
110
|
|
|
{ |
111
|
|
|
$this->app->singleton(AuthorizationService::class, function ($app) { |
|
|
|
|
112
|
|
|
$request = $app->make(RequestHandler::class); |
113
|
|
|
$connection = new \linkprofit\AmoCRM\entities\Authorization( |
114
|
|
|
config('amocrm-api.login'), |
|
|
|
|
115
|
|
|
config('amocrm-api.hash') |
116
|
|
|
); |
117
|
|
|
$authorization = new \linkprofit\AmoCRM\services\AuthorizationService($request); |
118
|
|
|
$authorization->add($connection); |
119
|
|
|
$authorization->authorize(); |
120
|
|
|
|
121
|
|
|
return $authorization; |
122
|
|
|
}); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return void Boot all services |
127
|
|
|
*/ |
128
|
|
|
private function registerServices() |
129
|
|
|
{ |
130
|
|
|
foreach ($this->services as $service) { |
131
|
|
|
$this->app->bind($service, function ($app) use ($service) { |
132
|
|
|
$request = $app->make(\linkprofit\AmoCRM\RequestHandler::class); |
133
|
|
|
$authorization = $app->make(AuthorizationService::class); |
|
|
|
|
134
|
|
|
$service = new $service($request); |
135
|
|
|
|
136
|
|
|
return $service; |
137
|
|
|
}); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the services provided by the provider. |
143
|
|
|
* |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function provides() |
147
|
|
|
{ |
148
|
|
|
return [RequestHandler::class]; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths