public function getUrlPageName() { if (static::$urlPageName !== null) { return static::$urlPageName; } /* * Cache */ $key = 'urlMaker' . $this->urlComponentName . crc32(get_class($this)); $cached = Cache::get($key, false); if ($cached !== false && ($cached = @unserialize($cached)) !== false) { $filePath = array_get($cached, 'path'); $mtime = array_get($cached, 'mtime'); if (!File::isFile($filePath) || $mtime != File::lastModified($filePath)) { $cached = false; } } if ($cached !== false) { return static::$urlPageName = array_get($cached, 'fileName'); } $page = Page::useCache()->whereComponent($this->urlComponentName, 'isPrimary', '1')->first(); if (!$page) { throw new ApplicationException(sprintf('Unable to a find a primary component "%s" for generating a URL in %s.', $this->urlComponentName, get_class($this))); } $baseFileName = $page->getBaseFileName(); $filePath = $page->getFullPath(); $cached = ['path' => $filePath, 'fileName' => $baseFileName, 'mtime' => @File::lastModified($filePath)]; Cache::put($key, serialize($cached), Config::get('cms.parsedPageCacheTTL', 1440)); return static::$urlPageName = $baseFileName; }