key() public static method

Returns (and Sets) the key used to identify the session.
public static key ( mixed $name = null, $sessionId = null ) : string
$name mixed Optional named session configuration.
return string Returns the value of the session identifier key, or `null` if no named configuration exists, no session id has been set or no session has been started.
Esempio n. 1
0
 /**
  * Tests querying session keys from the primary adapter.
  * The memory adapter returns a UUID.
  *
  * @return void
  */
 public function testKey()
 {
     $result = Session::key();
     $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\$/";
     $this->assertPattern($pattern, $result);
 }
Esempio n. 2
0
<?php

use lithium\action\Dispatcher;
use lithium\storage\Session;
/**
 * Set the token header in the response.
 */
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    $response = $chain->next($self, $params, $chain);
    $configs = Session::config();
    foreach ($configs as $name => $config) {
        if ($config['adapter'] == 'Token') {
            $header = $config['header'];
            break;
        }
    }
    if (isset($header)) {
        $response->headers($header, Session::key($name));
    }
    return $response;
});