lithium\storage\session\adapter\Cookie::delete()

public method

Delete a value from the cookie store.

Parameters

  • string $key

    The key to be deleted from the cookie store.

  • array $options

    Options array.

Returns

\Closure

Function returning boolean true on successful delete, false otherwise.

Source

	public function delete($key, array $options = []) {
		$cookieClass = get_called_class();

		return function($params) use ($cookieClass) {
			$key = $params['key'];
			$path = '/' . str_replace('.', '/', $this->_config['name'] . '.' . $key) . '/.';
			$cookies = current(Set::extract($_COOKIE, $path));
			if (is_array($cookies)) {
				$cookies = array_keys(Set::flatten($cookies));
				foreach ($cookies as &$name) {
					$name = $key . '.' . $name;
				}
			} else {
				$cookies = [$key];
			}
			foreach ($cookies as &$name) {
				$result = setcookie(
					$cookieClass::keyFormat($name, $this->_config),
					"",
					1,
					$this->_config['path'],
					$this->_config['domain'],
					$this->_config['secure'],
					$this->_config['httponly']
				);
				if (!$result) {
					throw new RuntimeException("There was an error deleting {$name} cookie.");
				}
			}
			return true;
		};
	}