public function testGetMetadataWithCache()
 {
     $driver = $this->getMock('Metadata\\Driver\\DriverInterface');
     $driver->expects($this->once())->method('loadMetadataForClass')->will($this->returnValue($metadata = new ClassMetadata('Metadata\\Tests\\Fixtures\\TestObject')));
     $factory = new MetadataFactory($driver);
     $cache = $this->getMock('Metadata\\Cache\\CacheInterface');
     $cache->expects($this->once())->method('loadClassMetadataFromCache')->with($this->equalTo(new \ReflectionClass('Metadata\\Tests\\Fixtures\\TestObject')))->will($this->returnValue(null));
     $cache->expects($this->once())->method('putClassMetadataInCache')->with($this->equalTo($metadata));
     $factory->setCache($cache);
     $this->assertSame($metadata, reset($factory->getMetadataForClass('Metadata\\Tests\\Fixtures\\TestObject')->classMetadata));
 }
 /**
  * Create open graph object
  */
 public function build()
 {
     $annotationReader = $this->annotationReader;
     if (null === $annotationReader) {
         $annotationReader = new AnnotationReader();
         if (null !== $this->cacheDirectory) {
             $cacheDirectory = sprintf('%s/annotations', $this->cacheDirectory);
             $this->createDirectory($cacheDirectory);
             $annotationReader = new CachedReader($annotationReader, new FilesystemCache($cacheDirectory));
         }
     }
     $metadataDriver = $this->driverFactory->createDriver($this->metadataDirectories, $annotationReader);
     $metadataFactory = new MetadataFactory($metadataDriver, null, $this->debug);
     $metadataFactory->setIncludeInterfaces($this->includeInterfaceMetadata);
     if (null !== $this->cacheDirectory) {
         $directory = sprintf('%s/metadata', $this->cacheDirectory);
         $this->createDirectory($directory);
         $metadataFactory->setCache(new FileCache($directory));
     }
     return new OpenGraphGenerator($metadataFactory);
 }
예제 #3
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();
     }
     return new Serializer($metadataFactory, $this->handlerRegistry, $this->objectConstructor ?: new UnserializeObjectConstructor(), $this->serializationVisitors, $this->deserializationVisitors, $this->eventDispatcher);
 }
예제 #4
0
 private function buildMetadataFactory()
 {
     $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);
         }
     }
     if (!empty($this->metadataDirs)) {
         $fileLocator = new FileLocator($this->metadataDirs);
         $metadataDriver = new DriverChain(array(new YamlDriver($fileLocator), new XmlDriver($fileLocator), new AnnotationDriver($annotationReader)));
     } else {
         $metadataDriver = new AnnotationDriver($annotationReader);
     }
     $metadataDriver = new ExtensionDriver($metadataDriver, $this->configurationExtensions);
     $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'));
     }
     return $metadataFactory;
 }
예제 #5
0
 public function testNotFoundMetadataIsNotCachedInDebug()
 {
     $driver = $this->getMock('Metadata\\Driver\\DriverInterface');
     $driver->expects($this->exactly(2))->method('loadMetadataForClass')->will($this->returnValue(null));
     $cachedMetadata = null;
     $cache = $this->getMock('Metadata\\Cache\\CacheInterface');
     $cache->expects($this->any())->method('loadClassMetadataFromCache')->with($this->equalTo(new \ReflectionClass('Metadata\\Tests\\Fixtures\\TestObject')))->will($this->returnValue(null));
     $cache->expects($this->never())->method('putClassMetadataInCache');
     $factory = new MetadataFactory($driver, 'Metadata\\ClassHierarchyMetadata', true);
     $factory->setCache($cache);
     $factory->getMetadataForClass('Metadata\\Tests\\Fixtures\\TestObject');
     $this->assertNull($factory->getMetadataForClass('Metadata\\Tests\\Fixtures\\TestObject'));
     // We use another factory with the same cache, to simulate another request and skip the in memory
     $factory = new MetadataFactory($driver, 'Metadata\\ClassHierarchyMetadata', true);
     $factory->setCache($cache);
     $factory->getMetadataForClass('Metadata\\Tests\\Fixtures\\TestObject');
     $this->assertNull($factory->getMetadataForClass('Metadata\\Tests\\Fixtures\\TestObject'));
 }
예제 #6
0
 public function setCache($cache)
 {
     $this->metadataFactory->setCache($cache);
 }
예제 #7
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);
         }
     }
     if (!empty($this->metadataDirs)) {
         $fileLocator = new FileLocator($this->metadataDirs);
         $metadataDriver = new DriverChain(array(new YamlDriver($fileLocator), new XmlDriver($fileLocator), new AnnotationDriver($annotationReader)));
     } else {
         $metadataDriver = new AnnotationDriver($annotationReader);
     }
     $metadataFactory = new MetadataFactory($metadataDriver, null, $this->debug);
     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();
     }
     return new Serializer($metadataFactory, $this->handlerRegistry, $this->objectConstructor ?: new UnserializeObjectConstructor(), $this->serializationVisitors, $this->deserializationVisitors, $this->eventDispatcher);
 }
예제 #8
0
 /**
  * Builds and return a Manager instance.
  *
  * @return Manager
  */
 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);
     $metadataFactory->setIncludeInterfaces($this->includeInterfaceMetadata);
     if (null !== $this->cacheDir) {
         $this->createDir($this->cacheDir . '/metadata');
         $metadataFactory->setCache(new FileCache($this->cacheDir . '/metadata'));
     }
     $schemaRegistry = new SchemaRegistry($this->schemaDirs);
     // TODO registry caching
     return new Manager($metadataFactory, $schemaRegistry);
 }