lithium\storage\Session::write PHP Method

write() public static method

Writes a persistent value to one or more session stores.
public static write ( string $key, mixed $value = null, array $options = [] ) : boolean
$key string Key to be written.
$value mixed Data to be stored.
$options array Optional parameters that this method accepts: - `'name'` _string_: To force the write to a specific adapter, specify the name of the configuration (i.e. `'default'`) here. - `'strategies'` _boolean_: Indicates whether or not a configuration's applied strategy classes should be enabled for this operation. Defaults to `true`.
return boolean Returns `true` on successful write, `false` otherwise.
    public static function write($key, $value = null, array $options = array())
    {
        $defaults = array('name' => null, 'strategies' => true);
        $options += $defaults;
        if (is_resource($value) || !static::$_configurations) {
            return false;
        }
        $methods = array();
        if ($name = $options['name']) {
            $methods = array($name => static::adapter($name)->write($key, $value, $options));
        } else {
            foreach (array_keys(static::$_configurations) as $name) {
                if ($method = static::adapter($name)->write($key, $value, $options)) {
                    $methods[$name] = $method;
                }
            }
        }
        $result = false;
        $original = $value;
        foreach ($methods as $name => $method) {
            $settings = static::_config($name);
            $filters = $settings['filters'];
            if ($options['strategies']) {
                $options += array('key' => $key, 'class' => __CLASS__);
                $value = static::applyStrategies(__FUNCTION__, $name, $original, $options);
            }
            $params = compact('key', 'value', 'options');
            $result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result;
        }
        return $result;
    }

Usage Example

Esempio n. 1
0
 public function access()
 {
     $token = Session::read('oauth.request');
     $access = Consumer::token('access', compact('token'));
     Session::write('oauth.access', $access);
     $this->redirect('Tweet::index');
 }
All Usage Examples Of lithium\storage\Session::write