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
f96a3fc0
Commit
f96a3fc0
authored
Aug 22, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Config) add toArrayFromFile() for
https://github.com/opnsense/core/issues/1097
parent
12b8a13b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
9 deletions
+34
-9
Config.php
src/opnsense/mvc/app/library/OPNsense/Core/Config.php
+34
-9
No files found.
src/opnsense/mvc/app/library/OPNsense/Core/Config.php
View file @
f96a3fc0
...
...
@@ -155,6 +155,18 @@ class Config extends Singleton
return
$result
;
}
/**
* @param $filename
* @param null $forceList
* @return array|string
*/
public
function
toArrayFromFile
(
$filename
,
$forceList
=
null
)
{
$xml
=
$this
->
load_from_file
(
$filename
);
return
$this
->
toArray
(
$forceList
,
$xml
);
}
/**
* update (reset) config with array structure (backwards compatibility mode)
* @param $source source array structure
...
...
@@ -292,16 +304,18 @@ class Config extends Singleton
}
/**
* Load config file
* load xml config from file
* @param $filename
* @return \SimpleXMLElement
* @throws ConfigException
*/
private
function
load
(
)
private
function
load
_from_file
(
$filename
)
{
// exception handling
if
(
!
file_exists
(
$
this
->
config_fil
e
))
{
if
(
!
file_exists
(
$
filenam
e
))
{
throw
new
ConfigException
(
'file not found'
);
}
$xml
=
file_get_contents
(
$
this
->
config_fil
e
);
$xml
=
file_get_contents
(
$
filenam
e
);
if
(
trim
(
$xml
)
==
''
)
{
throw
new
ConfigException
(
'empty file'
);
}
...
...
@@ -309,18 +323,29 @@ class Config extends Singleton
set_error_handler
(
function
()
{
// reset simplexml pointer on parse error.
$
this
->
simplexml
=
null
;
$
result
=
null
;
}
);
$
this
->
simplexml
=
simplexml_load_string
(
$xml
);
$
result
=
simplexml_load_string
(
$xml
);
if
(
$this
->
simplexml
==
null
)
{
restore_error_handler
();
if
(
$result
==
null
)
{
throw
new
ConfigException
(
"invalid config xml"
);
}
else
{
return
$result
;
}
}
restore_error_handler
();
/**
* Load config file
* @throws ConfigException
*/
private
function
load
()
{
$this
->
simplexml
=
null
;
$this
->
statusIsValid
=
false
;
$this
->
simplexml
=
$this
->
load_from_file
(
$this
->
config_file
);
$this
->
statusIsValid
=
true
;
}
...
...
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