1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 04:21:27 +08:00
2023-06-15 11:39:26 +08:00

43 lines
1.0 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
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'),
'index' => $config->path('redis.index'),
'lifetime' => $config->path('session.lifetime'),
'prefix' => '_SESSION_:',
]);
$session->start();
return $session;
});
}
}