1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Model;
use Zend\ServiceManager\ServiceLocatorInterface;
use Magento\Framework\App\DeploymentConfig;
class Navigation
{
/**#@+
* Types of wizards
*/
const NAV_INSTALLER = 'navInstaller';
const NAV_UPDATER = 'navUpdater';
/**#@- */
/**#@- */
private $navStates;
/**
* @var string
*/
private $navType;
/**
* @var string
*/
private $titles;
/**
* @param ServiceLocatorInterface $serviceLocator
* @param DeploymentConfig $deploymentConfig
*/
public function __construct(ServiceLocatorInterface $serviceLocator, DeploymentConfig $deploymentConfig)
{
if ($deploymentConfig->isAvailable()) {
$this->navStates = $serviceLocator->get('config')[self::NAV_UPDATER];
$this->navType = self::NAV_UPDATER;
$this->titles = $serviceLocator->get('config')[self::NAV_UPDATER . 'Titles'];
} else {
$this->navStates = $serviceLocator->get('config')[self::NAV_INSTALLER];
$this->navType = self::NAV_INSTALLER;
$this->titles = $serviceLocator->get('config')[self::NAV_INSTALLER . 'Titles'];
}
}
/**
* @return string
*/
public function getType()
{
return $this->navType;
}
/**
* @return array
*/
public function getData()
{
return $this->navStates;
}
/**
* Retrieve array of menu items
*
* Returns only items with 'nav' equal to TRUE
*
* @return array
*/
public function getMenuItems()
{
return array_values(array_filter(
$this->navStates,
function ($value) {
return isset($value['nav']) && (bool)$value['nav'];
}
));
}
/**
* Retrieve array of menu items
*
* Returns only items with 'main' equal to TRUE
*
* @return array
*/
public function getMainItems()
{
$result = array_values(array_filter(
$this->navStates,
function ($value) {
return isset($value['main']) && (bool)$value['main'];
}
));
return $result;
}
/**
* Returns titles of the navigation pages
*
* @return array
*/
public function getTitles()
{
return $this->titles;
}
}