Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
38aded21
Commit
38aded21
authored
Dec 05, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(menu) improve menu parsing performance
parent
5069d99c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
18 deletions
+47
-18
MenuItem.php
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
+47
-18
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
View file @
38aded21
...
@@ -96,6 +96,24 @@ class MenuItem
...
@@ -96,6 +96,24 @@ class MenuItem
*/
*/
private
$selected
=
false
;
private
$selected
=
false
;
/**
* class method getters
* @var array
*/
private
static
$internalClassGetterNames
=
null
;
/**
* class method setters
* @var array
*/
private
static
$internalClassSetterNames
=
null
;
/**
* map internal methods to support faster case-insensitive matching
* @var array|null
*/
private
static
$internalClassMethodAliases
=
null
;
/**
/**
* Find setter for property, ignore case
* Find setter for property, ignore case
* @param string $name property name
* @param string $name property name
...
@@ -103,14 +121,16 @@ class MenuItem
...
@@ -103,14 +121,16 @@ class MenuItem
*/
*/
private
function
getXmlPropertySetterName
(
$name
)
private
function
getXmlPropertySetterName
(
$name
)
{
{
$class_methods
=
get_class_methods
(
$this
);
if
(
!
isset
(
self
::
$internalClassMethodAliases
[
$name
]))
{
foreach
(
$class_methods
as
$method_name
)
{
self
::
$internalClassMethodAliases
[
$name
]
=
null
;
if
(
"set"
.
strtolower
(
$name
)
==
strtolower
(
$method_name
))
{
$propKey
=
strtolower
(
$name
);
return
$method_name
;
foreach
(
self
::
$internalClassSetterNames
as
$methodName
=>
$propValue
)
{
if
(
$propKey
==
strtolower
(
$propValue
))
{
self
::
$internalClassMethodAliases
[
$name
]
=
$methodName
;
}
}
}
}
}
return
self
::
$internalClassMethodAliases
[
$name
];
return
null
;
}
}
/**
/**
...
@@ -123,6 +143,23 @@ class MenuItem
...
@@ -123,6 +143,23 @@ class MenuItem
$this
->
id
=
$id
;
$this
->
id
=
$id
;
$this
->
visibleName
=
$id
;
$this
->
visibleName
=
$id
;
$this
->
parent
=
$parent
;
$this
->
parent
=
$parent
;
$prop_exclude_list
=
array
(
"getXmlPropertySetterName"
=>
true
);
if
(
self
::
$internalClassMethodAliases
===
null
)
{
self
::
$internalClassMethodAliases
=
array
();
self
::
$internalClassSetterNames
=
array
();
self
::
$internalClassGetterNames
=
array
();
// cache method names, get_class_methods() should always return the initial methods.
// Caching the methods delivers quite some performance at minimal memory cost.
foreach
(
get_class_methods
(
$this
)
as
$methodName
)
{
if
(
!
isset
(
$prop_exclude_list
[
$methodName
]))
{
if
(
substr
(
$methodName
,
0
,
3
)
==
"get"
)
{
self
::
$internalClassGetterNames
[
$methodName
]
=
substr
(
$methodName
,
3
);
}
elseif
(
substr
(
$methodName
,
0
,
3
)
==
"set"
)
{
self
::
$internalClassSetterNames
[
$methodName
]
=
substr
(
$methodName
,
3
);
}
}
}
}
}
}
/**
/**
...
@@ -277,7 +314,9 @@ class MenuItem
...
@@ -277,7 +314,9 @@ class MenuItem
// set attributes
// set attributes
foreach
(
$properties
as
$propname
=>
$propvalue
)
{
foreach
(
$properties
as
$propname
=>
$propvalue
)
{
$methodName
=
$newMenuItem
->
getXmlPropertySetterName
(
$propname
);
$methodName
=
$newMenuItem
->
getXmlPropertySetterName
(
$propname
);
$newMenuItem
->
$methodName
((
string
)
$propvalue
);
if
(
$methodName
!==
null
)
{
$newMenuItem
->
$methodName
((
string
)
$propvalue
);
}
}
}
$orderNum
=
sprintf
(
"%05d"
,
$newMenuItem
->
getOrder
());
$orderNum
=
sprintf
(
"%05d"
,
$newMenuItem
->
getOrder
());
...
@@ -377,20 +416,10 @@ class MenuItem
...
@@ -377,20 +416,10 @@ class MenuItem
public
function
getChildren
()
public
function
getChildren
()
{
{
$result
=
array
();
$result
=
array
();
$properties
=
array
();
// probe this object for available setters, so we know what to publish to the outside world.
$prop_exclude_list
=
array
(
"getXmlPropertySetterName"
);
$class_methods
=
get_class_methods
(
$this
);
foreach
(
$class_methods
as
$method_name
)
{
if
(
substr
(
$method_name
,
0
,
3
)
==
"get"
&&
in_array
(
$method_name
,
$prop_exclude_list
)
==
false
)
{
$properties
[
$method_name
]
=
substr
(
$method_name
,
3
);
}
}
// sort by order/id and map getters to array items
// sort by order/id and map getters to array items
foreach
(
$this
->
getFilteredChildren
()
as
$key
=>
$node
)
{
foreach
(
$this
->
getFilteredChildren
()
as
$key
=>
$node
)
{
$result
[
$node
->
id
]
=
new
\stdClass
();
$result
[
$node
->
id
]
=
new
\stdClass
();
foreach
(
$properti
es
as
$methodName
=>
$propName
)
{
foreach
(
self
::
$internalClassGetterNam
es
as
$methodName
=>
$propName
)
{
$result
[
$node
->
id
]
->
{
$propName
}
=
$node
->
$methodName
();
$result
[
$node
->
id
]
->
{
$propName
}
=
$node
->
$methodName
();
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment