Gregwar\ImageBundle\Services\ImageHandling::createInstance PHP Method

createInstance() private method

Creates an instance defining the cache directory.
private createInstance ( string $file, string | null $w = null, string | null $h = null ) : Gregwar\ImageBundle\ImageHandler
$file string
$w string | null
$h string | null
return Gregwar\ImageBundle\ImageHandler
    private function createInstance($file, $w = null, $h = null)
    {
        $container = $this->container;
        $webDir = $container->getParameter('gregwar_image.web_dir');
        $handlerClass = $this->handlerClass;
        /** @var ImageHandler $image */
        $image = new $handlerClass($file, $w, $h, $this->throwException, $this->fallbackImage);
        $image->setCacheDir($this->cacheDirectory);
        $image->setCacheDirMode($this->cacheDirMode);
        $image->setActualCacheDir($webDir . '/' . $this->cacheDirectory);
        if ($container->has('templating.helper.assets')) {
            $image->setFileCallback(function ($file) use($container) {
                return $container->get('templating.helper.assets')->getUrl($file);
            });
        } else {
            $image->setFileCallback(function ($file) use($container) {
                return $container->get('assets.packages')->getUrl($file);
            });
        }
        return $image;
    }