Pimcore\Document::getInstance PHP Method

getInstance() public static method

Singleton for Pimcore\Document
public static getInstance ( null $adapter = null ) : boolean | null | Document
$adapter null
return boolean | null | Document
    public static function getInstance($adapter = null)
    {
        try {
            if ($adapter) {
                $adapterClass = "\\Pimcore\\Document\\Adapter\\" . $adapter;
                if (Tool::classExists($adapterClass)) {
                    return new $adapterClass();
                } else {
                    throw new \Exception("document-transcode adapter `" . $adapter . "ยด does not exist.");
                }
            } else {
                if ($adapter = self::getDefaultAdapter()) {
                    return $adapter;
                }
            }
        } catch (\Exception $e) {
            Logger::crit("Unable to load document adapter: " . $e->getMessage());
            throw $e;
        }
        return null;
    }

Usage Example

Beispiel #1
0
 public function getText($page = null)
 {
     if (\Pimcore\Document::isAvailable() && \Pimcore\Document::isFileTypeSupported($this->getFilename())) {
         $cacheKey = "asset_document_text_" . $this->getId() . "_" . ($page ? $page : "all");
         if (!($text = Cache::load($cacheKey))) {
             $document = \Pimcore\Document::getInstance();
             $text = $document->getText($page, $this->getFileSystemPath());
             Cache::save($text, $cacheKey, $this->getCacheTags(), null, 99, true);
             // force cache write
         }
         return $text;
     } else {
         Logger::error("Couldn't get text out of document " . $this->getRealFullPath() . " no document adapter is available");
     }
     return null;
 }
All Usage Examples Of Pimcore\Document::getInstance