/** * 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); } }
/** * Generates a display URL from the given image. * * @param MediaInterface $file * @param array $options * @param Boolean|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface) * * @return string The generated URL */ protected function displayUrl(MediaInterface $file, array $options = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { $urlSafePath = $this->mediaManager->getUrlSafePath($file); if ($this->imagineHelper && isset($options['imagine_filter']) && is_string($options['imagine_filter'])) { return $this->imagineHelper->filter($urlSafePath, $options['imagine_filter'], !empty($options['runtime_config']) ? $options['runtime_config'] : array()); } return $this->generator->generate('cmf_media_image_display', array('path' => $urlSafePath), $referenceType); }