本文整理汇总了PHP中Cake\Network\Session::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::create方法的具体用法?PHP Session::create怎么用?PHP Session::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Session
的用法示例。
在下文中一共展示了Session::create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromGlobals
/**
* {@inheritDoc}
*/
public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
{
$request = parent::fromGlobals($server, $query, $body, $cookies, $files);
list($base, $webroot) = static::getBase($request);
$sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php', 'cookiePath' => $webroot];
$session = Session::create($sessionConfig);
$request = $request->withAttribute('base', $base)->withAttribute('webroot', $webroot)->withAttribute('session', $session);
if ($base) {
$request = static::updatePath($base, $request);
}
return $request;
}
示例2: getSession
/**
* Get instance of the session.
*
* @return \Cake\Network\Session
*/
public function getSession()
{
if (!empty($this->cake['session'])) {
return $this->cake['session'];
}
if (!empty($this->cake['request'])) {
$this->cake['session'] = $this->cake['request']->session();
return $this->cake['session'];
}
$config = (array) Configure::read('Session') + ['defaults' => 'php'];
$this->cake['session'] = Session::create($config);
return $this->cake['session'];
}
示例3: createFromGlobals
/**
* Wrapper method to create a new request from PHP superglobals.
*
* Uses the $_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV and php://input data to construct
* the request.
*
* @return \Cake\Network\Request
*/
public static function createFromGlobals()
{
list($base, $webroot) = static::_base();
$sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php', 'cookiePath' => $webroot];
$config = ['query' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'cookies' => $_COOKIE, 'environment' => $_SERVER + $_ENV, 'base' => $base, 'webroot' => $webroot, 'session' => Session::create($sessionConfig)];
$config['url'] = static::_url($config);
return new static($config);
}
示例4: _buildRequest
/**
* Creates a request object with the configured options and parameters.
*
* @param string|array $url The URL
* @param string $method The HTTP method
* @param array|null $data The request data.
* @return \Cake\Network\Request The built request.
*/
protected function _buildRequest($url, $method, $data)
{
$sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php'];
$session = Session::create($sessionConfig);
$session->write($this->_session);
list($url, $query) = $this->_url($url);
$props = ['url' => $url, 'post' => $data, 'cookies' => $this->_cookie, 'session' => $session, 'query' => $query];
$env = [];
if (isset($this->_request['headers'])) {
foreach ($this->_request['headers'] as $k => $v) {
$env['HTTP_' . str_replace('-', '_', strtoupper($k))] = $v;
}
unset($this->_request['headers']);
}
$env['REQUEST_METHOD'] = $method;
$props['environment'] = $env;
$props = Hash::merge($props, $this->_request);
return new Request($props);
}
示例5: _buildRequest
/**
* Creates a request object with the configured options and parameters.
*
* @param string|array $url The URL
* @param string $method The HTTP method
* @param array|null $data The request data.
* @return array The request context
*/
protected function _buildRequest($url, $method, $data)
{
$sessionConfig = (array) Configure::read('Session') + ['defaults' => 'php'];
$session = Session::create($sessionConfig);
$session->write($this->_session);
list($url, $query) = $this->_url($url);
$tokenUrl = $url;
if ($query) {
$tokenUrl .= '?' . http_build_query($query);
}
$props = ['url' => $url, 'post' => $this->_addTokens($tokenUrl, $data), 'cookies' => $this->_cookie, 'session' => $session, 'query' => $query];
if (is_string($data)) {
$props['input'] = $data;
}
$env = [];
if (isset($this->_request['headers'])) {
foreach ($this->_request['headers'] as $k => $v) {
$name = strtoupper(str_replace('-', '_', $k));
if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'])) {
$name = 'HTTP_' . $name;
}
$env[$name] = $v;
}
unset($this->_request['headers']);
}
$env['REQUEST_METHOD'] = $method;
$props['environment'] = $env;
$props = Hash::merge($props, $this->_request);
return $props;
}
示例6: testUsingPluginHandler
/**
* test using a handler from a plugin.
*
* @return void
*/
public function testUsingPluginHandler()
{
Configure::write('App.namespace', 'TestApp');
\Cake\Core\Plugin::load('TestPlugin');
$config = ['defaults' => 'cake', 'handler' => ['engine' => 'TestPlugin.TestPluginSession']];
$session = Session::create($config);
$this->assertInstanceOf('TestPlugin\\Network\\Session\\TestPluginSession', $session->engine());
$this->assertEquals('user', ini_get('session.save_handler'));
}
示例7: _getUserId
/**
* Gets current User's ID.
*
* @return int User ID, zero if not found
*/
protected function _getUserId()
{
$callable = $this->config('idCallable');
$id = 0;
if (is_string($callable)) {
$session = Session::create();
$id = $session->read($callable);
} elseif (is_callable($callable)) {
$id = $callable();
}
return (int) $id;
}