/** * Set the specified key to the specified value. * * @param string $filename The key of the cached data * @param string $data The value to storage against the key, this data must be JSON serializable * * @return void */ public static function set($filename, $data) { $filename = static::path($filename); Json::encodeToFile($filename, $data); }
/** * 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; }
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; }