Ejemplo n.º 1
0
 public function testVariableMethods()
 {
     $node = EncoderNode::addNode($this->node());
     $nodeVariable = new EncoderNodeVariable('nodeVariable');
     $node->addVariable($nodeVariable);
     $collection = $node->getVariableCollection();
     $this->assertTrue($collection->variableExists('nodeVariable'));
     $this->assertFalse($collection->variableExists('unknown'));
     $this->assertEquals($nodeVariable, $node->getVariable('nodeVariable'));
     $this->assertNull($node->getVariable('unknown'));
     $this->assertEquals($nodeVariable, $collection->getVariableById('nodeVariable'));
     $this->assertNull($collection->getVariableById('unknown'));
 }
Ejemplo n.º 2
0
    public function getFoo()
    {
        return $this->foo;
    }
}
// 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());
Ejemplo n.º 3
0
 public function addAddAfterDecodeNodes($addAfterAttributes = true)
 {
     EncoderNode::addNode(new AddAfterDecodeParentNode($addAfterAttributes));
     EncoderNode::addNode(new AddAfterDecodeChildNode());
     EncoderNode::addNode(new AddAfterDecodeChildRequiresNode());
 }