Пример #1
0
 protected function getSerializationVisitor($format)
 {
     $visitor = parent::getSerializationVisitor($format);
     if ($visitor instanceof VisitorInterface) {
         return $visitor;
     }
     return $this->container->get($visitor);
 }
 public function testMultipleEntities()
 {
     $entity = new EntityElement('bar');
     $entity2 = new EntityElement('bar');
     $property = new EntityProperty(new String('foo'), new EntityType(array($entity, $entity2)), new String('zoo'));
     $unserialized = simplexml_load_string($this->serializer->serialize($property, "xml"));
     $this->assertEquals('property', $unserialized->getName());
     $this->assertEquals('entity', $unserialized['type']);
     $this->assertEquals('foo', $unserialized['name']);
     $this->assertEquals('zoo', $unserialized['title']);
     $this->assertEquals('bar', $unserialized['entityname']);
     $this->assertEquals(2, $unserialized->children()->count());
     foreach ($unserialized->children() as $child) {
         $this->assertEquals('entity', $child->getName());
         $this->assertEquals('bar', $child['name']);
     }
 }
 public function testHasLink()
 {
     $collection = new Collection('bar');
     $collection->addLink(new Link('foo', 'bar', 'zoo'));
     $xml = simplexml_load_string($this->serializer->serialize($collection, "xml"));
     $this->assertEquals(1, count($xml->links));
     foreach ($xml->links->children() as $link) {
         $this->assertEquals('link', $link->getName());
     }
     $entity = new Entity('bar');
     $entity->addLink(new Link('foo', 'bar', 'zoo'));
     $xml = simplexml_load_string($this->serializer->serialize($entity, "xml"));
     $this->assertEquals(1, count($xml->links));
     foreach ($xml->links->children() as $link) {
         $this->assertEquals('link', $link->getName());
     }
 }
 public function testWhitelistedDocumentTypesAreAllowed()
 {
     $xmlVisitor = new XmlDeserializationVisitor(new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()), $this->getDeserializationHandlers(), new UnserializeObjectConstructor());
     $xmlVisitor->setDoctypeWhitelist(array('<!DOCTYPE authorized SYSTEM "http://authorized_url.dtd">', '<!DOCTYPE author [<!ENTITY foo SYSTEM "php://filter/read=convert.base64-encode/resource=' . basename(__FILE__) . '">]>'));
     $serializer = new Serializer(new MetadataFactory(new AnnotationDriver(new AnnotationReader())), array(), array('xml' => $xmlVisitor));
     $serializer->deserialize('<?xml version="1.0"?>
         <!DOCTYPE authorized SYSTEM "http://authorized_url.dtd">
         <foo></foo>', 'stdClass', 'xml');
     $serializer->deserialize('<?xml version="1.0"?>
         <!DOCTYPE author [
             <!ENTITY foo SYSTEM "php://filter/read=convert.base64-encode/resource=' . basename(__FILE__) . '">
         ]>
         <foo></foo>', 'stdClass', 'xml');
 }