lithium\storage\Session::write()

public static method

Writes a persistent value to one or more session stores.

Parameters

  • string $key

    Key to be written.

  • mixed $value

    Data to be stored.

  • array $options

    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.

Returns

boolean

Returns true on successful write, false otherwise.

Filter

This method can be filtered.

Source

	public static function write($key, $value = null, array $options = []) {
		$defaults = ['name' => null, 'strategies' => true];
		$options += $defaults;

		if (is_resource($value) || !static::$_configurations) {
			return false;
		}
		$methods = [];

		if ($name = $options['name']) {
			$methods = [$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);

			if ($options['strategies']) {
				$value = static::applyStrategies(__FUNCTION__, $name, $original, $options + [
					'key' => $key,
					'class' => __CLASS__
				]);
			}
			$params = compact('key', 'value', 'options');

			if (!empty($settings['filters'])) {
				$message  = 'Per adapter filters have been deprecated. Please ';
				$message .= "filter the manager class' static methods instead.";
				trigger_error($message, E_USER_DEPRECATED);

				$result = Filters::bcRun(
					get_called_class(), __FUNCTION__, $params, $method, $settings['filters']
				) || $result;
			} else {
				$result = Filters::run(get_called_class(), __FUNCTION__, $params, $method) || $result;
			}
		}
		return $result;
	}