Example #1
0
 public function build()
 {
     $annotationReader = $this->annotationReader;
     if (null === $annotationReader) {
         $annotationReader = new AnnotationReader();
         if (null !== $this->cacheDir) {
             $this->createDir($this->cacheDir . '/annotations');
             $annotationReader = new FileCacheReader($annotationReader, $this->cacheDir . '/annotations', $this->debug);
         }
     }
     $metadataDriver = $this->driverFactory->createDriver($this->metadataDirs, $annotationReader);
     $metadataFactory = new MetadataFactory($metadataDriver, null, $this->debug);
     $metadataFactory->setIncludeInterfaces($this->includeInterfaceMetadata);
     if (null !== $this->cacheDir) {
         $this->createDir($this->cacheDir . '/metadata');
         $metadataFactory->setCache(new FileCache($this->cacheDir . '/metadata'));
     }
     if (!$this->handlersConfigured) {
         $this->addDefaultHandlers();
     }
     if (!$this->listenersConfigured) {
         $this->addDefaultListeners();
     }
     if (!$this->visitorsAdded) {
         $this->addDefaultSerializationVisitors();
         $this->addDefaultDeserializationVisitors();
     }
     $serializer = new Serializer($metadataFactory, $this->handlerRegistry, $this->objectConstructor ?: new UnserializeObjectConstructor(), $this->serializationVisitors, $this->deserializationVisitors, $this->eventDispatcher);
     if (null !== $this->defaultSerializationContextFactory) {
         $serializer->setDefaultSerializationContextFactory($this->defaultSerializationContextFactory);
     }
     if (null !== $this->defaultDeserializationContextFactory) {
         $serializer->setDefaultDeserializationContextFactory($this->defaultDeserializationContextFactory);
     }
     return $serializer;
 }