Exemplo n.º 1
0
 public function testConstructor()
 {
     $encode = new XmlEncoder();
     $xml = $encode->encode($this->getFarm());
     $encodeStrFirst = $xml->saveXML();
     $decode = $encode->decode(simplexml_import_dom($xml));
     $xml2 = $encode->encode($decode['farm']);
     $encodeStrSecond = $xml2->saveXML();
     $this->assertEquals($encodeStrFirst, $encodeStrSecond);
 }
Exemplo n.º 2
0
// create a corresponding node and add the variable
class HelloWorldNode extends EncoderNode
{
    function __construct()
    {
        parent::__construct('hello-worlds', 'hello-world', null);
        $this->addVariable(new EncoderNodeVariable('foo'));
    }
}
// register the node so it becomes known to the encoder
EncoderNode::addNode(new HelloWorldNode());
// create a HelloWorld object
$helloWorld = new HelloWorld();
$helloWorld->setFoo('hello world');
// make an instance of an encoder type and encode the object
$encoder = new XmlEncoder();
$encodedResultXml = $encoder->encode($helloWorld);
// will output:
/* <?xml version="1.0" encoding="UTF-8"?>
 * <encoded>
 *   <hello-world foo="hello world"/>
 * </encoded>
 */
echo htmlentities($encodedResultXml->saveXML());
// decode the XML again
$decoded = $encoder->decode($encodedResultXml->saveXML());
// will output:
/*
 * HelloWorld Object
 * (
 *   [foo:HelloWorld:private] => hello world