ResponseFactory.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Search\Adapter\Mysql;
  7. /**
  8. * Response Factory
  9. *
  10. * @deprecated 102.0.0
  11. * @see \Magento\ElasticSearch
  12. */
  13. class ResponseFactory
  14. {
  15. /**
  16. * Object Manager instance
  17. *
  18. * @var \Magento\Framework\ObjectManagerInterface
  19. */
  20. protected $objectManager;
  21. /**
  22. * Document Factory
  23. *
  24. * @var DocumentFactory
  25. */
  26. protected $documentFactory;
  27. /**
  28. * Aggregation Factory
  29. *
  30. * @var AggregationFactory
  31. */
  32. protected $aggregationFactory;
  33. /**
  34. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  35. * @param DocumentFactory $documentFactory
  36. * @param AggregationFactory $aggregationFactory
  37. */
  38. public function __construct(
  39. \Magento\Framework\ObjectManagerInterface $objectManager,
  40. DocumentFactory $documentFactory,
  41. AggregationFactory $aggregationFactory
  42. ) {
  43. $this->objectManager = $objectManager;
  44. $this->documentFactory = $documentFactory;
  45. $this->aggregationFactory = $aggregationFactory;
  46. }
  47. /**
  48. * Create Query Response instance
  49. *
  50. * @param mixed $rawResponse
  51. * @return \Magento\Framework\Search\Response\QueryResponse
  52. */
  53. public function create($rawResponse)
  54. {
  55. $documents = [];
  56. foreach ($rawResponse['documents'] as $rawDocument) {
  57. /** @var \Magento\Framework\Api\Search\Document[] $documents */
  58. $documents[] = $this->documentFactory->create($rawDocument);
  59. }
  60. /** @var \Magento\Framework\Search\Response\Aggregation $aggregations */
  61. $aggregations = $this->aggregationFactory->create($rawResponse['aggregations']);
  62. return $this->objectManager->create(
  63. \Magento\Framework\Search\Response\QueryResponse::class,
  64. [
  65. 'documents' => $documents,
  66. 'aggregations' => $aggregations
  67. ]
  68. );
  69. }
  70. }