/** * Searches in the specified mapping cache for $LibraryName. If a mapping is * found, it returns it. If not, it searches through the application * directories $Depth levels deep looking for $LibraryName. Returns FALSE * if not found. * * @param string $MappingsFileName The name of the mappings file to look in for library mappings. These * files are contained in the application's /cache folder. * @param string $SourceFolders The path to the folders that should be considered the "root" of this search. * @param mixed $FolderWhiteList A white-list array of sub-folders within $SourceFolder in which the * search can be performed. If FALSE is specified instead, the search will * only be performed in $SourceFolders. * @param string $LibraryName The name of the library to search for. This is a valid file name. * ie. "class.database.php" */ public static function findByMapping($MappingCacheName, $SourceFolders, $FolderWhiteList, $LibraryName) { // If the application folder was provided, it will be the only entry in the whitelist, so prepend it. if (is_array($FolderWhiteList) && count($FolderWhiteList) == 1) { $LibraryName = combinePaths(array($FolderWhiteList[0], $LibraryName)); } $LibraryKey = str_replace('.', '__', $LibraryName); Gdn_LibraryMap::prepareCache($MappingCacheName); $LibraryPath = Gdn_LibraryMap::getCache($MappingCacheName, $LibraryKey); if ($LibraryPath === null) { // $LibraryName wasn't contained in the mappings array. // I need to look through the folders in this application for the requested file. // Once I find it, I need to save the mapping so we don't have to search for it again. // Attempt to find the file directly off the root (if the app folder was provided in the querystring) /*if ($FolderWhiteList !== FALSE && count($FolderWhiteList) == 1) { $LibraryPath = self::Find($SourceFolders, $LibraryName); } else { $LibraryPath = self::Find($SourceFolders, $LibraryName, $FolderWhiteList); }*/ $LibraryPath = self::find($SourceFolders, $LibraryName, $FolderWhiteList); // If the mapping was found if ($LibraryPath !== false) { Gdn_LibraryMap::cache($MappingCacheName, $LibraryKey, $LibraryPath); } } return $LibraryPath; }
/** * Gets the locale sources for a given locale. * * @param string $locale The name of the locale. * @param string[] $applicationWhiteList An array of enabled application folders. * @param string[] $pluginWhiteList An array of enabled plugin folders. * @param bool $forceRemapping Whether or not to force a rebuild of the cache. * @return array Returns an array of paths to the translations for the locale. */ public function getLocaleSources($locale, $applicationWhiteList, $pluginWhiteList, $forceRemapping = false) { $safeLocale = static::canonicalize($locale); // First try and grab the locale sources from the cache. Gdn_LibraryMap::prepareCache('locale', null, 'tree'); $allLocaleSources = Gdn_LibraryMap::getCache('locale'); if ($forceRemapping || !Gdn_LibraryMap::cacheReady('locale') || $allLocaleSources === null) { // Build the entire locale sources array and cache it. $allLocaleSources = $this->crawlAllLocaleSources($applicationWhiteList, $pluginWhiteList); Gdn_LibraryMap::prepareCache('locale', $allLocaleSources); } $localeSources = val($safeLocale, $allLocaleSources, array()); return $localeSources; }
/** * This method is deprecated, but since cache files call it there will be low-level crashes without it. */ public static function prepareCache($CacheName, $ExistingCacheArray = null) { Gdn_LibraryMap::prepareCache($CacheName, $ExistingCacheArray); }