ClientFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\HTTP;
  7. /**
  8. * Factory for HTTP client classes
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class ClientFactory
  13. {
  14. /**
  15. * Object Manager instance
  16. *
  17. * @var \Magento\Framework\ObjectManagerInterface
  18. */
  19. protected $_objectManager = null;
  20. /**
  21. * Instance name to create
  22. *
  23. * @var string
  24. */
  25. protected $_instanceName = null;
  26. /**
  27. * Factory constructor (default creates Curl client)
  28. *
  29. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  30. * @param string $instanceName
  31. */
  32. public function __construct(
  33. \Magento\Framework\ObjectManagerInterface $objectManager,
  34. $instanceName = \Magento\Framework\HTTP\Client\Curl::class
  35. ) {
  36. $this->_objectManager = $objectManager;
  37. $this->_instanceName = $instanceName;
  38. }
  39. /**
  40. * Create class instance with specified parameters
  41. *
  42. * @param array $data
  43. * @return ClientInterface
  44. */
  45. public function create(array $data = [])
  46. {
  47. return $this->_objectManager->create($this->_instanceName, $data);
  48. }
  49. }