Base::set PHP Method

set() public method

Bind value to hive key
public set ( $key, $val, $ttl ) : mixed
$key string
$val mixed
$ttl int
return mixed
    function set($key, $val, $ttl = 0)
    {
        $time = time();
        if (preg_match('/^(GET|POST|COOKIE)\\b(.+)/', $key, $expr)) {
            $this->set('REQUEST' . $expr[2], $val);
            if ($expr[1] == 'COOKIE') {
                $parts = $this->cut($key);
                $jar = $this->unserialize($this->serialize($this->hive['JAR']));
                if (isset($_COOKIE[$parts[1]])) {
                    $jar['expire'] = strtotime('-1 year');
                    call_user_func_array('setcookie', array_merge([$parts[1], NULL], $jar));
                }
                if ($ttl) {
                    $jar['expire'] = $time + $ttl;
                }
                call_user_func_array('setcookie', [$parts[1], $val] + $jar);
                $_COOKIE[$parts[1]] = $val;
                return $val;
            }
        } else {
            switch ($key) {
                case 'CACHE':
                    $val = Cache::instance()->load($val, TRUE);
                    break;
                case 'ENCODING':
                    ini_set('default_charset', $val);
                    if (extension_loaded('mbstring')) {
                        mb_internal_encoding($val);
                    }
                    break;
                case 'FALLBACK':
                    $this->fallback = $val;
                    $lang = $this->language($this->hive['LANGUAGE']);
                case 'LANGUAGE':
                    if (!isset($lang)) {
                        $val = $this->language($val);
                    }
                    $lex = $this->lexicon($this->hive['LOCALES'], $ttl);
                case 'LOCALES':
                    if (isset($lex) || ($lex = $this->lexicon($val, $ttl))) {
                        foreach ($lex as $dt => $dd) {
                            $ref =& $this->ref($this->hive['PREFIX'] . $dt);
                            $ref = $dd;
                            unset($ref);
                        }
                    }
                    break;
                case 'TZ':
                    date_default_timezone_set($val);
                    break;
            }
        }
        $ref =& $this->ref($key);
        $ref = $val;
        if (preg_match('/^JAR\\b/', $key)) {
            $jar = $this->unserialize($this->serialize($this->hive['JAR']));
            $jar['expire'] -= $time;
            call_user_func_array('session_set_cookie_params', $jar);
        }
        if ($ttl) {
            // Persist the key-value pair
            Cache::instance()->set($this->hash($key) . '.var', $val, $ttl);
        }
        return $ref;
    }

Usage Example

Esempio n. 1
0
 /**
  * set auth tokens
  * @param $token
  * @param $secret
  */
 public function setAuthToken($token, $secret)
 {
     $this->authToken = $token;
     $this->authSecret = $secret;
     $this->f3->set('SESSION.dropbox.authToken', $this->authToken);
     $this->f3->set('SESSION.dropbox.authSecret', $this->authSecret);
 }
All Usage Examples Of Base::set