Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
OpsPortal
lavoisiercli
Commits
982d58a0
Commit
982d58a0
authored
Oct 15, 2014
by
Olivier Lequeux
Browse files
add namespace registration to SimpleXMLHydrator
parent
95537313
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
16 deletions
+59
-16
src/Lavoisier/Entries/Entries.php
src/Lavoisier/Entries/Entries.php
+6
-9
src/Lavoisier/Entries/IEntries.php
src/Lavoisier/Entries/IEntries.php
+6
-0
src/Lavoisier/Hydrators/SimpleXMLHydrator.php
src/Lavoisier/Hydrators/SimpleXMLHydrator.php
+29
-2
tests/EntriesTest.php
tests/EntriesTest.php
+5
-3
tests/SimpleXMLHydratorTest.php
tests/SimpleXMLHydratorTest.php
+13
-2
No files found.
src/Lavoisier/Entries/Entries.php
View file @
982d58a0
...
...
@@ -11,12 +11,12 @@ namespace Lavoisier\Entries;
class
Entries
extends
\
ArrayObject
implements
IEntries
{
// original simple entries/entry Lavoisier xsd (it's a subset of the following one)
const
XMLNS_entries
=
"http://software.in2p3.fr/lavoisier/entries.xsd"
;
// extended recursive entries/entries/.../entries/entry lavoisiercli xsd
const
XMLNS_ex_entries
=
"https://gitlab.in2p3.fr/opsportal/lavoisiercli/raw/master/resources/ex_entries.xsd"
;
public
function
init
()
{
}
/*
* @param bool set true to ask original Lavoisier XMLNS
* @return string XMLNS
...
...
@@ -24,15 +24,12 @@ class Entries extends \ArrayObject implements IEntries
static
public
function
getXMLNS
(
$useLavoisierXMLNS
=
true
)
{
if
(
true
===
$useLavoisierXMLNS
)
{
return
self
::
XMLNS_entries
;
return
IEntries
::
XMLNS_entries
;
}
else
{
return
self
::
XMLNS_ex_entries
;
return
IEntries
::
XMLNS_ex_entries
;
}
}
public
function
init
()
{
}
public
function
pop
()
{
...
...
src/Lavoisier/Entries/IEntries.php
View file @
982d58a0
...
...
@@ -6,6 +6,12 @@ namespace Lavoisier\Entries;
*/
interface
IEntries
{
// original simple entries/entry Lavoisier xsd (it's a subset of the following one)
const
XMLNS_entries
=
"http://software.in2p3.fr/lavoisier/entries.xsd"
;
// extended recursive entries/entries/.../entries/entry lavoisiercli xsd
const
XMLNS_ex_entries
=
"https://gitlab.in2p3.fr/opsportal/lavoisiercli/raw/master/resources/ex_entries.xsd"
;
function
init
();
}
src/Lavoisier/Hydrators/SimpleXMLHydrator.php
View file @
982d58a0
...
...
@@ -2,16 +2,43 @@
namespace
Lavoisier\Hydrators
;
use
\
Lavoisier\Entries\Entries
;
class
SimpleXMLHydrator
implements
IHydrator
{
private
$prefix
;
private
$ns
;
function
__construct
()
{
$this
->
prefix
=
''
;
$this
->
ns
=
''
;
}
public
function
hydrate
(
$str
)
{
$sxObject
=
simplexml_load_string
(
$str
,
'\SimpleXMLElement'
);
$sxObject
=
simplexml_load_string
(
$str
,
'\SimpleXMLElement'
,
0
,
$this
->
prefix
,
((
empty
(
$this
->
prefix
))
?
false
:
true
)
);
if
(
$sxObject
===
false
)
{
throw
new
\
Exception
(
'Unable to parse XML'
);
}
return
$sxObject
;
}
}
\ No newline at end of file
public
function
registerNamespace
(
$prefix
,
$ns
)
{
$this
->
prefix
=
$prefix
;
$this
->
ns
=
$ns
;
}
public
function
registerEntriesNamespace
(
$useLavoisierXMLNS
=
true
)
{
$this
->
registerNamespace
(
'e'
,
Entries
::
getXMLNS
(
$useLavoisierXMLNS
));
}
}
tests/EntriesTest.php
View file @
982d58a0
...
...
@@ -38,8 +38,7 @@ class EntriesTest extends \PHPUnit_Framework_TestCase
$input
=
file_get_contents
(
dirname
(
__FILE__
)
.
'/Resources/tickets.xml'
);
$hydrator
=
new
\
Lavoisier\Hydrators\EntriesHydrator
(
"\TicketingSystem\Ticket\GgusFields"
);
$coll
=
$hydrator
->
hydrate
(
$input
);
// print_r($coll);
//print_r($coll);
}
...
...
@@ -47,7 +46,10 @@ class EntriesTest extends \PHPUnit_Framework_TestCase
{
$this
->
assertEquals
(
"http://software.in2p3.fr/lavoisier/entries.xsd"
,
Entries
::
getXMLNS
());
$this
->
assertEquals
(
"https://gitlab.in2p3.fr/opsportal/lavoisiercli/raw/master/resources/ex_entries.xsd"
,
Entries
::
getXMLNS
(
true
));
$this
->
assertEquals
(
"https://gitlab.in2p3.fr/opsportal/lavoisiercli/raw/master/resources/ex_entries.xsd"
,
Entries
::
getXMLNS
(
true
)
);
}
}
\ No newline at end of file
tests/SimpleXMLHydratorTest.php
View file @
982d58a0
...
...
@@ -10,7 +10,7 @@
class
SimpleXMLHydratorTest
extends
PHPUnit_Framework_TestCase
{
public
function
test
Global
()
public
function
test
XMLnoNS
()
{
$input
=
<<<EOF
...
...
@@ -22,7 +22,18 @@ EOF;
$lh
=
new
\
Lavoisier\Hydrators\SimpleXMLHydrator
();
$simpleXMLObj
=
$lh
->
hydrate
(
$input
);
$this
->
assertEquals
(
$simpleXMLObj
->
child1
,
'1st child text node'
);
$this
->
assertEquals
(
'1st child text node'
,
strval
(
$simpleXMLObj
->
child1
));
}
public
function
testXMLwithNS
()
{
$input
=
file_get_contents
(
dirname
(
__FILE__
)
.
'/Resources/tickets.xml'
);
$hydrator
=
new
\
Lavoisier\Hydrators\SimpleXMLHydrator
();
$hydrator
->
registerEntriesNamespace
(
false
);
$simpleXMLObj
=
$hydrator
->
hydrate
(
$input
);
$this
->
assertEquals
(
50455
,
strval
(
$simpleXMLObj
->
entries
[
0
]
->
entry
[
0
]));
}
}
\ No newline at end of file
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