1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | namespace OpenSearch\Connections; |
23: | |
24: | use OpenSearch\Serializers\SerializerInterface; |
25: | use Psr\Log\LoggerInterface; |
26: | |
27: | class ConnectionFactory implements ConnectionFactoryInterface |
28: | { |
29: | |
30: | |
31: | |
32: | private $connectionParams; |
33: | |
34: | |
35: | |
36: | |
37: | private $serializer; |
38: | |
39: | |
40: | |
41: | |
42: | private $logger; |
43: | |
44: | |
45: | |
46: | |
47: | private $tracer; |
48: | |
49: | |
50: | |
51: | |
52: | private $handler; |
53: | |
54: | |
55: | |
56: | |
57: | public function __construct(callable $handler, array $connectionParams, SerializerInterface $serializer, LoggerInterface $logger, LoggerInterface $tracer) |
58: | { |
59: | $this->handler = $handler; |
60: | $this->connectionParams = $connectionParams; |
61: | $this->logger = $logger; |
62: | $this->tracer = $tracer; |
63: | $this->serializer = $serializer; |
64: | } |
65: | |
66: | public function create(array $hostDetails): ConnectionInterface |
67: | { |
68: | if (isset($hostDetails['path'])) { |
69: | $hostDetails['path'] = rtrim($hostDetails['path'], '/'); |
70: | } |
71: | |
72: | return new Connection( |
73: | $this->handler, |
74: | $hostDetails, |
75: | $this->connectionParams, |
76: | $this->serializer, |
77: | $this->logger, |
78: | $this->tracer |
79: | ); |
80: | } |
81: | } |
82: | |