blob: d52aec89993589ac17080f5bd25063461ef58b86 (
plain)
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
112
113
114
115
116
117
118
119
120
121
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\install\helper\navigation;
use phpbb\di\service_collection;
/**
* Installers navigation provider
*/
class navigation_provider
{
/**
* @var array
*/
private $menu_collection;
/**
* Constructor
*
* @param service_collection $plugins
*/
public function __construct(service_collection $plugins)
{
$this->menu_collection = array();
foreach ($plugins as $plugin => $plugin_instance)
{
$this->register($plugin_instance);
}
}
/**
* Returns navigation array
*
* @return array
*/
public function get()
{
return $this->menu_collection;
}
/**
* Registers a navigation provider's navigation items
*
* @param navigation_interface $navigation
*/
public function register(navigation_interface $navigation)
{
$nav_arry = $navigation->get();
$this->menu_collection = $this->merge($nav_arry, $this->menu_collection);
}
/**
* Set a property in the navigation array
*
* @param array $nav_element Array to the navigation elem
* @param array $property_array Array with the properties to set
*/
public function set_nav_property($nav_element, $property_array)
{
$array_pointer = array();
$array_root_pointer = &$array_pointer;
foreach ($nav_element as $array_path)
{
$array_pointer[$array_path] = array();
$array_pointer = &$array_pointer[$array_path];
}
$array_pointer = $property_array;
$this->menu_collection = $this->merge($array_root_pointer, $this->menu_collection);
}
/**
* Recursive array merge
*
* This function is necessary to be able to replace the options of
* already set navigation items.
*
* @param array $array_to_merge
* @param array $array_to_merge_into
*
* @return array Merged array
*/
private function merge($array_to_merge, $array_to_merge_into)
{
$merged_array = $array_to_merge_into;
foreach ($array_to_merge as $key => $value)
{
if (isset($array_to_merge_into[$key]))
{
if (is_array($array_to_merge_into[$key]) && is_array($value))
{
$merged_array[$key] = $this->merge($value, $array_to_merge_into[$key]);
}
else
{
$merged_array[$key] = $value;
}
}
else
{
$merged_array[$key] = $value;
}
}
return $merged_array;
}
}
|