Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RouterList.php
Go to the documentation of this file.
1 <?php
9 namespace Magento\Framework\App;
10 
12 {
16  protected $objectManager;
17 
23  protected $routerList;
24 
30  {
31  $this->objectManager = $objectManager;
32  $this->routerList = array_filter(
34  function ($item) {
35  return (!isset($item['disable']) || !$item['disable']) && $item['class'];
36  }
37  );
38  uasort($this->routerList, [$this, 'compareRoutersSortOrder']);
39  }
40 
47  protected function getRouterInstance($routerId)
48  {
49  if (!isset($this->routerList[$routerId]['object'])) {
50  $this->routerList[$routerId]['object'] = $this->objectManager->create(
51  $this->routerList[$routerId]['class']
52  );
53  }
54  return $this->routerList[$routerId]['object'];
55  }
56 
63  public function current()
64  {
65  return $this->getRouterInstance($this->key());
66  }
67 
74  public function next()
75  {
76  next($this->routerList);
77  }
78 
85  public function key()
86  {
87  return key($this->routerList);
88  }
89 
97  public function valid()
98  {
99  return !!current($this->routerList);
100  }
101 
108  public function rewind()
109  {
110  reset($this->routerList);
111  }
112 
120  protected function compareRoutersSortOrder($routerDataFirst, $routerDataSecond)
121  {
122  return (int)$routerDataFirst['sortOrder'] <=> (int)$routerDataSecond['sortOrder'];
123  }
124 }
compareRoutersSortOrder($routerDataFirst, $routerDataSecond)
Definition: RouterList.php:120
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $routerList)
Definition: RouterList.php:29