vendor/pimcore/pimcore/lib/Tool/Frontend.php line 75

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Tool;
  15. use Pimcore;
  16. use Pimcore\Bundle\CoreBundle\EventListener\Frontend\FullPageCacheListener;
  17. use Pimcore\Cache\RuntimeCache;
  18. use Pimcore\Model\Document;
  19. use Pimcore\Model\Site;
  20. final class Frontend
  21. {
  22.     /**
  23.      * @param Site|null $site
  24.      * @param Document $document
  25.      *
  26.      * @return bool
  27.      */
  28.     public static function isDocumentInSite($site$document)
  29.     {
  30.         $inSite true;
  31.         if ($site && $site->getRootDocument() instanceof Document\Page) {
  32.             if (strpos($document->getRealFullPath(), $site->getRootDocument()->getRealFullPath() . '/') !== 0) {
  33.                 $inSite false;
  34.             }
  35.         }
  36.         return $inSite;
  37.     }
  38.     /**
  39.      * @param Document $document
  40.      *
  41.      * @return bool
  42.      */
  43.     public static function isDocumentInCurrentSite($document)
  44.     {
  45.         if (Site::isSiteRequest()) {
  46.             $site Site::getCurrentSite();
  47.             if ($site instanceof Site) {
  48.                 return self::isDocumentInSite($site$document);
  49.             }
  50.         }
  51.         return true;
  52.     }
  53.     /**
  54.      * @param Document $document
  55.      *
  56.      * @return Site|null
  57.      */
  58.     public static function getSiteForDocument($document)
  59.     {
  60.         $cacheKey 'sites_full_list';
  61.         if (RuntimeCache::isRegistered($cacheKey)) {
  62.             $sites RuntimeCache::get($cacheKey);
  63.         } else {
  64.             $sites = new Site\Listing();
  65.             $sites->setOrderKey('(SELECT LENGTH(path) FROM documents WHERE documents.id = sites.rootId) DESC'false);
  66.             $sites $sites->load();
  67.             RuntimeCache::set($cacheKey$sites);
  68.         }
  69.         foreach ($sites as $site) {
  70.             if (strpos($document->getRealFullPath(), $site->getRootPath() . '/') === || $site->getRootDocument()->getId() == $document->getId()) {
  71.                 return $site;
  72.             }
  73.         }
  74.         return null;
  75.     }
  76.     /**
  77.      * @return array|bool
  78.      */
  79.     public static function isOutputCacheEnabled()
  80.     {
  81.         $cacheService Pimcore::getContainer()->get(FullPageCacheListener::class);
  82.         if ($cacheService->isEnabled()) {
  83.             return [
  84.                 'enabled' => true,
  85.                 'lifetime' => $cacheService->getLifetime(),
  86.             ];
  87.         }
  88.         return false;
  89.     }
  90. }