Doctrine\OXM\Marshaller\XmlMarshaller::marshalToString PHP Method

marshalToString() public method

public marshalToString ( object $mappedObject ) : string
$mappedObject object
return string
    function marshalToString($mappedObject)
    {
        $writer = new WriterHelper($this);
        // clear the internal visited list
        $this->visited = array();
        // Begin marshalling
        $this->doMarshal($mappedObject, $writer);
        return $writer->flush();
    }

Usage Example

Example #1
0
 /**
  * @test
  */
 public function itShouldDoDeepInheritedFieldsCorrectly()
 {
     $request = new Request();
     $request->id = 1;
     $bo = new ConcreteBO3();
     $bo->inherit = 1;
     $bo->overridden = 'yes';
     $bo->description = 'Scooby Doo';
     $request->bo = $bo;
     $xml = $this->marshaller->marshalToString($request);
     $this->assertXmlStringEqualsXmlString('<?xml version="1.0" encoding="UTF-8"?>
         <request id="1">
             <concrete-bo3 inherit="1" description="Scooby Doo">
                 <overridden>yes</overridden>
             </concrete-bo3>
         </request>', $xml);
     $otherRequest = $this->marshaller->unmarshalFromString($xml);
     $this->assertEquals(1, $otherRequest->id);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\ConcreteBO3', $otherRequest->bo);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\BusinessObject', $otherRequest->bo);
     $this->assertInstanceOf('Doctrine\\Tests\\OXM\\Entities\\MappedSuperclass\\AbstractBusinessObject', $otherRequest->bo);
     $this->assertEquals(1, $otherRequest->bo->inherit);
     $this->assertEquals('yes', $otherRequest->bo->overridden);
     $this->assertEquals('Scooby Doo', $otherRequest->bo->description);
 }
All Usage Examples Of Doctrine\OXM\Marshaller\XmlMarshaller::marshalToString