FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpfui/src/PHPFUI/Menu.php at master · phpfui/phpfui · GitHub
phpfui
/
phpfui
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpfui
/
src
/
PHPFUI
/
Menu.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
224 lines (186 loc) · 4.25 KB
Breadcrumbs
phpfui
/
src
/
PHPFUI
/
Menu.php
Copy path
File metadata and controls
224 lines (186 loc) · 4.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
namespace
PHPFUI
;
class
Menu
extends
\
PHPFUI
\HTML5Element
{
/** @var array<string, \PHPFUI\MenuItem | \PHPFUI\Menu> */
protected
array
$
menuItems
= [];
/** @var array<string, string> */
protected
array
$
menuLabels
= [];
protected
bool
$
sorted
=
false
;
private
bool
$
started
=
false
;
private
string
$
type
=
''
;
public
function
__construct
()
{
parent
::
__construct
(
'
ul
'
);
$
this
->
addClass
(
'
menu
'
);
}
public
function
addMenuItem
(
\
PHPFUI
\
MenuItem
$
item
) :
static
{
$
name
=
$
item
->
getName
() .
'
:
'
.
\count
(
$
this
->
menuItems
);
$
this
->
menuItems
[
$
name
] =
$
item
;
$
this
->
menuLabels
[
$
name
] =
$
item
->
getName
();
return
$
this
;
}
public
function
addSubMenu
(
\
PHPFUI
\
MenuItem
$
item
,
\
PHPFUI
\
Menu
$
subMenu
) :
static
{
$
subMenu
->
addClass
(
'
nested
'
);
$
name
=
$
item
->
getName
() .
'
:
'
.
\count
(
$
this
->
menuItems
);
$
this
->
menuItems
[
$
name
] =
$
subMenu
;
$
this
->
menuLabels
[
$
name
] =
$
item
->
getName
();
return
$
this
;
}
/**
* Number of object in this object. Does not count sub objects.
*/
public
function
count
() :
int
{
return
\count
(
$
this
->
menuItems
);
}
public
function
getActive
() :
bool
{
foreach
(
$
this
->
menuItems
as
$
menuItem
)
{
if
(
$
menuItem
->
getActive
())
{
return
true
;
}
}
return
false
;
}
/** @return array<string, \PHPFUI\MenuItem> */
public
function
getMenuItems
() :
array
{
return
$
this
->
menuItems
;
}
public
function
getName
() :
string
{
return
'
Menu
'
;
}
/**
* Set the active MenuItem by link
*
* @return bool true if an active link was set
*/
public
function
setActiveLink
(
string
$
link
) :
bool
{
foreach
(
$
this
->
menuItems
as
&
$
menuItem
)
{
if
(
$
menuItem
instanceof
\
PHPFUI
\MenuItem)
{
if
(
$
menuItem
->
getLink
() ==
$
link
)
{
$
menuItem
->
setActive
();
return
true
;
}
}
elseif
(
$
menuItem
->
setActiveLink
(
$
link
))
{
return
true
;
}
}
return
false
;
}
/**
* Set the active MenuItem by name
*
* @return bool true if an active name was set
*/
public
function
setActiveName
(
string
$
name
) :
bool
{
foreach
(
$
this
->
menuItems
as
&
$
menuItem
)
{
if
(
$
menuItem
->
getName
() ==
$
name
)
{
$
menuItem
->
setActive
();
return
true
;
}
}
return
false
;
}
/**
* @param string $type must one of top, right, bottom, left
*/
public
function
setIconAlignment
(
string
$
type
) :
static
{
$
types
= [
'
top
'
,
'
right
'
,
'
bottom
'
,
'
left
'
, ];
if
(!
\in_array
(
$
type
,
$
types
))
{
throw
new
\
Exception
(
__METHOD__
.
'
Error: Icon type {$type} should be one of
'
.
\implode
(
''
,
$
types
));
}
$
this
->
addClass
(
'
icons
'
);
$
this
->
addClass
(
'
icon-
'
.
$
type
);
$
this
->
type
=
$
type
;
return
$
this
;
}
/**
* Sort the menu by name displayed to the user.
*/
public
function
sort
() :
static
{
$
this
->
sorted
=
true
;
\ksort
(
$
this
->
menuItems
);
return
$
this
;
}
public
function
walk
(
string
$
method
,
mixed
$
argument
=
null
) :
static
{
foreach
(
$
this
->
menuItems
as
$
item
)
{
if
(
\method_exists
(
$
item
,
$
method
))
{
if
(
null
!==
$
argument
)
{
\call_user_func
([
$
item
,
$
method
],
$
argument
);
}
else
{
\call_user_func
([
$
item
,
$
method
]);
}
}
if
(
$
item
instanceof
\
PHPFUI
\Menu)
{
$
item
->
walk
(
$
method
,
$
argument
);
}
}
return
$
this
;
}
protected
function
getStart
() :
string
{
if
(!
$
this
->
started
)
{
$
this
->
started
=
true
;
$
somethingActive
=
0
;
if
(
$
this
->
sorted
)
{
\ksort
(
$
this
->
menuItems
);
}
foreach
(
$
this
->
menuItems
as
$
label
=>
$
item
)
{
if
(
$
item
instanceof
\
PHPFUI
\MenuItem)
{
$
somethingActive
|= (
int
)
$
item
->
getActive
();
if
(
$
this
->
type
)
{
$
item
->
setAlignment
(
$
this
->
type
);
}
$
this
->
add
(
$
item
);
}
else
{
$
menuItem
=
new
\
PHPFUI
\
MenuItem
(
$
this
->
menuLabels
[
$
label
],
'
#
'
);
$
somethingActive
|= (
int
)
$
item
->
getActive
();
$
menuItem
->
setActive
(
$
item
->
getActive
());
$
menuItem
->
add
(
$
item
);
$
this
->
add
(
$
menuItem
);
}
}
if
(
$
somethingActive
)
{
$
this
->
addClass
(
'
is-active
'
);
}
}
return
parent
::
getStart
();
}
}
Back
|
FazBrowse Home
|
New Git URL