NoRouteHandlerList.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * No route handlers retriever
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\Router;
  9. class NoRouteHandlerList
  10. {
  11. /**
  12. * No route handlers instances
  13. *
  14. * @var NoRouteHandlerInterface[]
  15. */
  16. protected $_handlers;
  17. /**
  18. * @var array
  19. */
  20. protected $_handlerList;
  21. /**
  22. * @var \Magento\Framework\ObjectManagerInterface
  23. */
  24. protected $_objectManager;
  25. /**
  26. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  27. * @param array $handlerClassesList
  28. */
  29. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $handlerClassesList)
  30. {
  31. $this->_handlerList = $handlerClassesList;
  32. $this->_objectManager = $objectManager;
  33. }
  34. /**
  35. * Get noRoute handlers
  36. *
  37. * @return NoRouteHandlerInterface[]
  38. */
  39. public function getHandlers()
  40. {
  41. if (!$this->_handlers) {
  42. //sorting handlers list
  43. $sortedHandlersList = [];
  44. foreach ($this->_handlerList as $handlerInfo) {
  45. if (isset($handlerInfo['class']) && isset($handlerInfo['sortOrder'])) {
  46. $sortedHandlersList[$handlerInfo['class']] = $handlerInfo['sortOrder'];
  47. }
  48. }
  49. asort($sortedHandlersList);
  50. //creating handlers
  51. foreach (array_keys($sortedHandlersList) as $handlerInstance) {
  52. $this->_handlers[] = $this->_objectManager->create($handlerInstance);
  53. }
  54. }
  55. return $this->_handlers;
  56. }
  57. }