コード例 #1
0
ファイル: DiskCache.php プロジェクト: Masterfion/plugin-sonos
 /**
  * Get the stored value of the specified key.
  *
  * @param string $filename The key of the cached data
  * @param int $mins The number of minutes to use the cache for, if the cache is present but older than this time then return null
  *
  * @return mixed
  */
 public static function get($filename, $mins = 0)
 {
     if (!($cache = static::check($filename))) {
         return null;
     }
     $limit = time() - $mins * 60;
     if (!$mins || $cache > $limit) {
         $filename = static::path($filename);
         $return = Json::decodeFromFile($filename);
         return $return;
     }
     return null;
 }
コード例 #2
0
ファイル: Env.php プロジェクト: Masterfion/plugin-sonos
 /**
  * Get all defined environment variables.
  *
  * @return array
  */
 public static function getVars()
 {
     if (!is_array(static::$vars)) {
         $path = static::path("data/env.json");
         try {
             $vars = Json::decodeFromFile($path);
         } catch (\Exception $e) {
             $vars = [];
         }
         static::$vars = Helper::toArray($vars);
     }
     return static::$vars;
 }
コード例 #3
0
ファイル: Cache.php プロジェクト: ian-Tr/le-huard
 public function orderBy($col, $desc = null)
 {
     # Check if the data has already been sorted by this column
     $sorted = Json::decodeFromFile($this->dir . "/.sorted");
     $this->indexMap = $sorted[$col];
     # If the data hasn't already been sorted then create an index map for it now
     if (!is_array($this->indexMap)) {
         $sort = [];
         $pos = 0;
         $this->seek(0);
         while ($row = $this->fetch()) {
             $sort[$pos] = $row[$col];
             $pos++;
         }
         $this->seek(0);
         asort($sort);
         $this->indexMap = array_keys($sort);
         $sorted[$col] = $this->indexMap;
         Json::encodeToFile($this->dir . "/.sorted", $sorted);
     }
     if ($desc) {
         $this->indexMap = array_reverse($this->indexMap);
     }
     return true;
 }