/** * Apply the filter. * * @param string $aliasName */ public function apply($aliasName = null) { $reset = false; if ($aliasName === null) { $aliasName = $this->mediaManager->getOriginalDir(); $reset = true; } $this->updateFile($this->image); $this->updateFocus($this->media); $fs = $this->mediaManager->getFilesystemManipulator(); $fs->saveContent($aliasName . '/' . $this->media->getReference(), $this->image->get($this->media->getExtension())); $this->mediaManager->setSizeWidthAndHeight($this->media)->save($this->media); if ($reset === true) { $this->mediaManager->reset($this->media); } }
/** * Remove empty directory * Remove cache of media. * * @param MediaInterface|null $media If is defined, only cache of this file is removed * @param bool $onlyFocus Remove media only for focus cache */ public function reset(MediaInterface $media = null, $onlyFocus = false) { if ($onlyFocus === true) { $regex = '#^\\d*x\\d*_focus/'; } else { $regex = '#^\\d*x\\d*(_focus)?/'; } $regex .= $media !== null ? $media->getReference() : '.*'; $regex .= '$#'; foreach ($this->filesystemManipulator->keys() as $file) { if (preg_match($regex, $file)) { $this->filesystemManipulator->delete($file); } } }