Pimcore\Tool::isFrontend PHP Method

isFrontend() public static method

public static isFrontend ( ) : boolean
return boolean
    public static function isFrontend()
    {
        if (self::$isFrontend !== null) {
            return self::$isFrontend;
        }
        $isFrontend = true;
        if ($isFrontend && php_sapi_name() == "cli") {
            $isFrontend = false;
        }
        if ($isFrontend && \Pimcore::inAdmin()) {
            $isFrontend = false;
        }
        if ($isFrontend) {
            $excludePatterns = ["/^\\/admin.*/", "/^\\/install.*/", "/^\\/plugin.*/", "/^\\/webservice.*/"];
            foreach ($excludePatterns as $pattern) {
                if (preg_match($pattern, $_SERVER["REQUEST_URI"])) {
                    $isFrontend = false;
                    break;
                }
            }
        }
        self::$isFrontend = $isFrontend;
        return $isFrontend;
    }

Usage Example

示例#1
0
 /**
  * Returns the document path.
  *
  * @return string
  */
 public function getPath()
 {
     // check for site, if so rewrite the path for output
     try {
         if (\Pimcore\Tool::isFrontend() && Site::isSiteRequest()) {
             $site = Site::getCurrentSite();
             if ($site instanceof Site) {
                 if ($site->getRootDocument() instanceof Document\Page && $site->getRootDocument() !== $this) {
                     $rootPath = $site->getRootPath();
                     $rootPath = preg_quote($rootPath);
                     $link = preg_replace("@^" . $rootPath . "@", "", $this->path);
                     return $link;
                 }
             }
         }
     } catch (\Exception $e) {
         Logger::error($e);
     }
     return $this->path;
 }
All Usage Examples Of Pimcore\Tool::isFrontend