Пример #1
0
 public function setUp()
 {
     $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy());
     $loader = new AnnotationLoader();
     $loader->setReader(new AnnotationReader());
     $this->serializer = new Serializer(new MetadataFactory($loader), new HandlerRegistry(), new UnserializeObjectConstructor(), ['array' => new GenericSerializationVisitor($namingStrategy)], ['array' => new GenericDeserializationVisitor($namingStrategy)]);
 }
Пример #2
0
 public function loadClassMetadata(ClassMetadataInterface $classMetadata)
 {
     if (!$this->getClassElement($classMetadata->getName())) {
         return true;
     }
     return parent::loadClassMetadata($classMetadata);
 }
Пример #3
0
 protected function setUp()
 {
     $connection = $this->createConnection();
     $entityManager = $this->createEntityManager($connection);
     $this->registry = $registry = new SimpleManagerRegistry(function ($id) use($connection, $entityManager) {
         switch ($id) {
             case 'default_connection':
                 return $connection;
             case 'default_manager':
                 return $entityManager;
             default:
                 throw new \RuntimeException(sprintf('Unknown service id "%s".', $id));
         }
     });
     $loader = new AnnotationLoader();
     $loader->setReader(new AnnotationReader());
     $this->serializer = SerializerBuilder::create()->setMetadataLoader(new DoctrineTypeLoader($loader, $registry))->setEventDispatcher(new EventDispatcher())->build();
     $this->prepareDatabase();
 }
Пример #4
0
 protected function setUp()
 {
     $this->dispatcher = new EventDispatcher();
     $this->handlerRegistry = new HandlerRegistry();
     $this->objectConstructor = new UnserializeObjectConstructor();
     $loader = new AnnotationLoader();
     $loader->setReader(new AnnotationReader());
     $this->metadataFactory = new MetadataFactory($loader);
     $this->navigator = new GraphNavigator($this->metadataFactory, $this->handlerRegistry, $this->objectConstructor, $this->dispatcher);
 }
Пример #5
0
 public function build()
 {
     $metadataLoader = $this->metadataLoader;
     if (null === $metadataLoader) {
         $annotationReader = $this->annotationReader ?: new AnnotationReader();
         $metadataLoader = new AnnotationLoader();
         $metadataLoader->setReader($annotationReader);
     }
     $metadataFactory = new MetadataFactory($metadataLoader, $this->eventDispatcher, $this->cache);
     if (!$this->handlersConfigured) {
         $this->addDefaultHandlers();
     }
     if (!$this->listenersConfigured) {
         $this->addDefaultListeners();
     }
     if (empty($this->serializationVisitors) && empty($this->deserializationVisitors)) {
         $this->addDefaultSerializationVisitors();
         $this->addDefaultDeserializationVisitors();
     }
     return new Serializer($metadataFactory, $this->handlerRegistry, $this->objectConstructor ?: new InitializedObjectConstructor(new UnserializeObjectConstructor()), $this->serializationVisitors, $this->deserializationVisitors, $this->eventDispatcher);
 }
Пример #6
0
 protected function setUp()
 {
     $loader = new AnnotationLoader();
     $loader->setReader(new AnnotationReader());
     $this->factory = new MetadataFactory($loader);
     $this->handlerRegistry = new HandlerRegistry();
     $this->handlerRegistry->registerSubscribingHandler(new ConstraintViolationHandler());
     $this->handlerRegistry->registerSubscribingHandler(new DateHandler());
     $this->handlerRegistry->registerSubscribingHandler(new FormErrorHandler(new IdentityTranslator(new MessageSelector())));
     $this->handlerRegistry->registerSubscribingHandler(new PhpCollectionHandler());
     $this->handlerRegistry->registerSubscribingHandler(new ArrayCollectionHandler());
     $this->handlerRegistry->registerHandler(Direction::DIRECTION_SERIALIZATION, 'AuthorList', function (VisitorInterface $visitor, $object, Type $type, Context $context) {
         return $visitor->visitArray(iterator_to_array($object), $type, $context);
     });
     $this->handlerRegistry->registerHandler(Direction::DIRECTION_DESERIALIZATION, 'AuthorList', function (VisitorInterface $visitor, $data, $type, Context $context) {
         $type = new Type('array', [Type::from('integer'), Type::from(Author::class)]);
         $elements = $context->accept($data, $type);
         $list = new AuthorList();
         foreach ($elements as $author) {
             $list->add($author);
         }
         return $list;
     });
     $this->dispatcher = new EventDispatcher();
     $this->dispatcher->addSubscriber(new DoctrineProxySubscriber());
     $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy());
     $objectConstructor = new UnserializeObjectConstructor();
     $this->serializationVisitors = ['array' => new GenericSerializationVisitor($namingStrategy), 'json' => new JsonSerializationVisitor($namingStrategy), 'xml' => new XmlSerializationVisitor($namingStrategy), 'yml' => new YamlSerializationVisitor($namingStrategy)];
     $this->deserializationVisitors = ['array' => new GenericDeserializationVisitor($namingStrategy), 'xml' => new XmlDeserializationVisitor($namingStrategy), 'yml' => new YamlDeserializationVisitor($namingStrategy), 'json' => new JsonDeserializationVisitor($namingStrategy)];
     $this->serializer = new Serializer($this->factory, $this->handlerRegistry, $objectConstructor, $this->serializationVisitors, $this->deserializationVisitors, $this->dispatcher);
 }
Пример #7
0
 protected function getLoader()
 {
     $loader = new AnnotationLoader();
     $loader->setReader(new AnnotationReader());
     return $loader;
 }