ConnectionFactory.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\ReportXml;
  7. use Magento\Framework\App\ResourceConnection;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Framework\DB\Adapter\AdapterInterface;
  10. /**
  11. * Creates connection instance for export according to existing one
  12. * This connection does not use buffered statement, also this connection is not persistent
  13. */
  14. class ConnectionFactory
  15. {
  16. /**
  17. * @var ResourceConnection
  18. */
  19. private $resourceConnection;
  20. /**
  21. * @var ObjectManagerInterface
  22. */
  23. private $objectManager;
  24. /**
  25. * @param ResourceConnection $resourceConnection
  26. * @param ObjectManagerInterface $objectManager
  27. */
  28. public function __construct(
  29. ResourceConnection $resourceConnection,
  30. ObjectManagerInterface $objectManager
  31. ) {
  32. $this->resourceConnection = $resourceConnection;
  33. $this->objectManager = $objectManager;
  34. }
  35. /**
  36. * Creates one-time connection for export
  37. *
  38. * @param string $connectionName
  39. * @return AdapterInterface
  40. */
  41. public function getConnection($connectionName)
  42. {
  43. $connection = $this->resourceConnection->getConnection($connectionName);
  44. $connectionClassName = get_class($connection);
  45. $configData = $connection->getConfig();
  46. $configData['use_buffered_query'] = false;
  47. unset($configData['persistent']);
  48. return $this->objectManager->create(
  49. $connectionClassName,
  50. [
  51. 'config' => $configData
  52. ]
  53. );
  54. }
  55. }