RequestProcessorPool.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Webapi\Controller\Rest;
  8. /**
  9. * Request Processor Pool
  10. */
  11. class RequestProcessorPool
  12. {
  13. /**
  14. * @var array
  15. */
  16. private $requestProcessors;
  17. /**
  18. * Initial dependencies
  19. *
  20. * @param RequestProcessorInterface[] $requestProcessors
  21. */
  22. public function __construct($requestProcessors = [])
  23. {
  24. $this->requestProcessors = $requestProcessors;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. *
  29. * @throws \Magento\Framework\Webapi\Exception
  30. * return RequestProcessorInterface
  31. */
  32. public function getProcessor(\Magento\Framework\Webapi\Rest\Request $request)
  33. {
  34. foreach ($this->requestProcessors as $processor) {
  35. if ($processor->canProcess($request)) {
  36. return $processor;
  37. }
  38. }
  39. throw new \Magento\Framework\Webapi\Exception(
  40. __('Specified request cannot be processed.'),
  41. 0,
  42. \Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST
  43. );
  44. }
  45. }