/** * delete the given file * * @param string $file */ public function deleteFile($file) { if (!$this->filesystem->has($file)) { return; } $this->filesystem->delete($file); $this->cacheManager->remove($file); }
/** * Check if this could mean an image document was modified (check resource, * file and image). * * @param LifecycleEventArgs $args */ private function invalidateCache(LifecycleEventArgs $args) { $object = $args->getObject(); // If we hear about the Resource which is nested in a File, we get the // parent. instanceof can handle the case where Resource is not a known // class - the condition will just be false in that case. if ($object instanceof Resource) { $object = $object->getParent(); } if (!$object instanceof ImageInterface) { return; } if (null === $this->request) { // do not fail on CLI return; } foreach ($this->filters as $filter) { $path = $this->manager->resolve($this->mediaManager->getUrlSafePath($object), $filter); if ($path instanceof RedirectResponse) { $path = $path->getTargetUrl(); } // TODO: this might not be needed https://github.com/liip/LiipImagineBundle/issues/162 if (false !== strpos($path, $filter)) { $path = substr($path, strpos($path, $filter) + strlen($filter)); } $this->manager->remove($path, $filter); } }
public function testFallbackToDefaultResolver() { $response = new Response('', 200); $request = new Request(); $resolver = $this->getMockResolver(); $resolver->expects($this->once())->method('resolve')->with($request, 'cats.jpeg', 'thumbnail')->will($this->returnValue('/thumbs/cats.jpeg')); $resolver->expects($this->once())->method('store')->with($response, '/thumbs/cats.jpeg', 'thumbnail')->will($this->returnValue($response)); $resolver->expects($this->once())->method('remove')->with('/thumbs/cats.jpeg', 'thumbnail')->will($this->returnValue(true)); $config = $this->getMockFilterConfiguration(); $config->expects($this->exactly(3))->method('get')->with('thumbnail')->will($this->returnValue(array('size' => array(180, 180), 'mode' => 'outbound', 'cache' => null))); $cacheManager = new CacheManager($config, $this->getMockRouter(), $this->fixturesDir . '/assets', 'default'); $cacheManager->addResolver('default', $resolver); // Resolve fallback to default resolver $this->assertEquals('/thumbs/cats.jpeg', $cacheManager->resolve($request, 'cats.jpeg', 'thumbnail')); // Store fallback to default resolver $this->assertEquals($response, $cacheManager->store($response, '/thumbs/cats.jpeg', 'thumbnail')); // Remove fallback to default resolver $this->assertTrue($cacheManager->remove('/thumbs/cats.jpeg', 'thumbnail')); }
public function testAggregateFiltersByResolverOnRemove() { $expectedFilterOne = 'theFilterOne'; $expectedFilterTwo = 'theFilterTwo'; $resolver = $this->createResolverMock(); $resolver ->expects($this->once()) ->method('remove') ->with(array(), array($expectedFilterOne, $expectedFilterTwo)) ; $config = $this->createFilterConfigurationMock(); $config ->expects($this->atLeastOnce()) ->method('get') ->will($this->returnCallback(function($filter) { return array( 'cache' => $filter, ); })) ; $cacheManager = new CacheManager($config, $this->createRouterMock(), new Signer('secret'), $this->createEventDispatcherMock()); $cacheManager->addResolver($expectedFilterOne, $resolver); $cacheManager->addResolver($expectedFilterTwo, $resolver); $cacheManager->remove(null, array($expectedFilterOne, $expectedFilterTwo)); }