Flintstone\Flintstone::get PHP Method

get() public method

Get a key from the database.
public get ( string $key ) : mixed
$key string
return mixed
    public function get($key)
    {
        $this->validateKey($key);
        // Fetch the key from cache
        if ($cache = $this->getConfig()->getCache()) {
            if ($cache->contains($key)) {
                return $cache->get($key);
            }
        }
        // Fetch the key from database
        $filePointer = $this->getDatabase()->openFile(Database::FILE_READ);
        $data = false;
        foreach ($filePointer as $line) {
            $data = $this->getDataFromLine($line, $key);
            if ($data !== false) {
                $data = $this->decodeData($data);
                break;
            }
        }
        $this->getDatabase()->closeFile($filePointer);
        // Save the data to cache
        if ($cache && $data !== false) {
            $cache->set($key, $data);
        }
        return $data;
    }

Usage Example

示例#1
0
 public function get($key, callable $callback = null, $default = null)
 {
     $value = $this->cache->get($key);
     if (!isset($value)) {
         $value = $default;
     }
     if (is_callable($callback)) {
         return call_user_func($callback, $value);
     }
     return $value;
 }
All Usage Examples Of Flintstone\Flintstone::get