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); }
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); }
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; }
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')); }
public function setCache($cache) { $this->metadataFactory->setCache($cache); }
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); }
/** * 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); }