1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 03:50:56 +08:00
2021-01-02 14:35:14 +08:00

36 lines
826 B
PHP

<?php
namespace App\Providers;
use Phalcon\Config;
use Phalcon\Session\Adapter\Redis as RedisSession;
class Session extends Provider
{
protected $serviceName = 'session';
public function register()
{
/**
* @var Config $config
*/
$config = $this->di->getShared('config');
$this->di->setShared($this->serviceName, function () use ($config) {
$session = new RedisSession([
'host' => $config->path('redis.host'),
'port' => $config->path('redis.port'),
'auth' => $config->path('redis.auth'),
'lifetime' => $config->path('session.lifetime') ?: 24 * 3600,
'prefix' => '_SESSION_:',
]);
$session->start();
return $session;
});
}
}