-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProvider.php
More file actions
63 lines (54 loc) · 2.14 KB
/
Copy pathProvider.php
File metadata and controls
63 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Plugins\HttpClient;
use AlfacodeTeam\PhpServicePlatform\Kernel\Contracts\ModuleContract;
use AlfacodeTeam\PhpServicePlatform\Kernel\Container\ModuleContainer;
use AlfacodeTeam\PhpServicePlatform\Kernel\Events\EventBus;
use AlfacodeTeam\PhpServicePlatform\Kernel\Pipelines\Cli\CliPipeline;
use AlfacodeTeam\PhpServicePlatform\Kernel\Pipelines\Http\HttpPipeline;
use AlfacodeTeam\PhpServicePlatform\Kernel\Pipelines\Worker\WorkerPipeline;
use AlfacodeTeam\PhpServicePlatform\Kernel\Ports\HttpClientPort;
use Plugins\HttpClient\Infrastructure\CurlHttpClient;
/**
* HttpClient plugin — cURL adapter for the kernel HttpClientPort.
*
* Always available (cURL is part of every standard PHP build), so unlike the
* Mail/Storage adapters it binds unconditionally — but still yields to a
* project that wired its own HttpClientPort in withPorts().
*
* ACTIVATION: this is an ON-DEMAND module. A Gateway that makes outbound calls
* must declare it in module.json so it joins the request graph:
* { "requires": ["http.client"] }
*/
final class Provider implements ModuleContract
{
public function solves(): string
{
return 'http.client';
}
/** @return list<class-string> */
public function requires(): array
{
return [];
}
/** @return list<class-string> */
public function exposes(): array
{
return [HttpClientPort::class];
}
public function register(ModuleContainer $container): void
{
if ($container->has(HttpClientPort::class)) {
return; // a project already provided HttpClientPort
}
$container->bind(HttpClientPort::class, static fn() => new CurlHttpClient(
defaultTimeout: (int) (env('HTTP_CLIENT_TIMEOUT',30)),
defaultConnectTimeout: (int) (env('HTTP_CLIENT_CONNECT_TIMEOUT', 10)),
defaultRetry: (int) (env('HTTP_CLIENT_RETRY', 0)),
maxResponseBytes: (int) (env('HTTP_CLIENT_MAX_RESPONSE_BYTES', 33_554_432)),
));
}
public function boot(HttpPipeline $http, CliPipeline $cli, WorkerPipeline $worker, EventBus $events): void
{
}
}