ConnectionFactory.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Elasticsearch\Connections;
  3. use Elasticsearch\Serializers\SerializerInterface;
  4. use Psr\Log\LoggerInterface;
  5. /**
  6. * Class AbstractConnection
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Connections
  10. * @author Zachary Tong <zach@elastic.co>
  11. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  12. * @link http://elastic.co
  13. */
  14. class ConnectionFactory implements ConnectionFactoryInterface
  15. {
  16. /** @var array */
  17. private $connectionParams;
  18. /** @var SerializerInterface */
  19. private $serializer;
  20. /** @var LoggerInterface */
  21. private $logger;
  22. /** @var LoggerInterface */
  23. private $tracer;
  24. /** @var callable */
  25. private $handler;
  26. /**
  27. * Constructor
  28. *
  29. * @param callable $handler
  30. * @param array $connectionParams
  31. * @param SerializerInterface $serializer
  32. * @param LoggerInterface $logger
  33. * @param LoggerInterface $tracer
  34. */
  35. public function __construct(callable $handler, array $connectionParams, SerializerInterface $serializer, LoggerInterface $logger, LoggerInterface $tracer)
  36. {
  37. $this->handler = $handler;
  38. $this->connectionParams = $connectionParams;
  39. $this->logger = $logger;
  40. $this->tracer = $tracer;
  41. $this->serializer = $serializer;
  42. }
  43. /**
  44. * @param $hostDetails
  45. *
  46. * @return ConnectionInterface
  47. */
  48. public function create($hostDetails)
  49. {
  50. return new Connection(
  51. $this->handler,
  52. $hostDetails,
  53. $this->connectionParams,
  54. $this->serializer,
  55. $this->logger,
  56. $this->tracer
  57. );
  58. }
  59. }