Pimcore\Model\Asset\Image\Thumbnail\Config::getByName PHP Method

getByName() public static method

public static getByName ( $name ) : null | Config
$name
return null | Config
    public static function getByName($name)
    {
        $cacheKey = "imagethumb_" . crc32($name);
        try {
            $thumbnail = \Zend_Registry::get($cacheKey);
            $thumbnail->setName($name);
            if (!$thumbnail) {
                throw new \Exception("Thumbnail in registry is null");
            }
        } catch (\Exception $e) {
            try {
                $thumbnail = new self();
                $thumbnail->setName($name);
                $thumbnail->getDao()->getByName();
                \Zend_Registry::set($cacheKey, $thumbnail);
            } catch (\Exception $e) {
                return null;
            }
        }
        // only return clones of configs, this is necessary since we cache the configs in the registry (see above)
        // sometimes, e.g. when using the cropping tools, the thumbnail configuration is modified on-the-fly, since
        // pass-by-reference this modifications would then go to the cache/registry (singleton), by cloning the config
        // we can bypass this problem in an elegant way without parsing the XML config again and again
        $clone = clone $thumbnail;
        return $clone;
    }

Usage Example

Beispiel #1
1
 /**
  * Returns the configuration for the image thumbnail with the given ID.
  */
 public function imageThumbnailAction()
 {
     $this->checkUserPermission("thumbnails");
     try {
         $id = $this->getParam("id");
         if ($id) {
             $config = Asset\Image\Thumbnail\Config::getByName($id);
             if (!$config instanceof Asset\Image\Thumbnail\Config) {
                 throw new \Exception("Thumbnail '" . $id . "' file doesn't exists");
             }
             $this->encoder->encode(["success" => true, "data" => $config->getForWebserviceExport()]);
             return;
         }
     } catch (\Exception $e) {
         \Logger::error($e);
         $this->encoder->encode(["success" => false, "msg" => (string) $e]);
     }
     $this->encoder->encode(["success" => false]);
 }
All Usage Examples Of Pimcore\Model\Asset\Image\Thumbnail\Config::getByName