Esempio n. 1
0
 /**
  * Append the provided resource in the appropriate (named) cache under the named cache key. 
  * If the entry is not already an array, convert it to one... then append the new data.
  * 
  * @param string $CacheName name of cache library
  * @param string $CacheKey name of cache entry
  * @param mixed $CacheContents contents of cache entry
  * @param bool $CacheWrite optional, whether or not to perform a disk write after this set. default yes
  * @return array cache contents
  */
 public static function CacheArray($CacheName, $CacheKey, $CacheContents, $CacheWrite = TRUE)
 {
     $ExistingCacheData = Gdn_LibraryMap::GetCache($CacheName, $CacheKey);
     if ($ExistingCacheData === NULL) {
         $ExistingCacheData = array();
     }
     if (!is_array($ExistingCacheData)) {
         $ExistingCacheData = array($ExistingCacheData);
     }
     $ExistingCacheData[] = $CacheContents;
     // Save cache data to memory
     return Gdn_LibraryMap::Cache($CacheName, $CacheKey, $ExistingCacheData, $CacheWrite);
 }
Esempio n. 2
0
 /**
  * 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);
         }
         // If the controller was found
         if ($LibraryPath !== FALSE) {
             Gdn_LibraryMap::Cache($MappingCacheName, $LibraryKey, $LibraryPath);
         }
     }
     return $LibraryPath;
 }