라라벨 SessionManager

Jmnote (토론 | 기여)님의 2016년 9월 9일 (금) 20:22 판 (→‎같이 보기)

1 개요

라라벨
<?php

namespace Illuminate\Session;

use Illuminate\Support\Manager;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;

class SessionManager extends Manager
{
    protected function callCustomCreator($driver)
    {
        return $this->buildSession(parent::callCustomCreator($driver));
    }

    protected function createArrayDriver()
    {
        return $this->buildSession(new NullSessionHandler);
    }

    protected function createCookieDriver()
    {
        $lifetime = $this->app['config']['session.lifetime'];
        return $this->buildSession(new CookieSessionHandler($this->app['cookie'], $lifetime));
    }

    protected function createFileDriver()
    {
        return $this->createNativeDriver();
    }

    protected function createNativeDriver()
    {
        $path = $this->app['config']['session.files'];
        $lifetime = $this->app['config']['session.lifetime'];
        return $this->buildSession(new FileSessionHandler($this->app['files'], $path, $lifetime));
    }

    protected function createDatabaseDriver()
    {
        $connection = $this->getDatabaseConnection();
        $table = $this->app['config']['session.table'];
        $lifetime = $this->app['config']['session.lifetime'];
        return $this->buildSession(new DatabaseSessionHandler($connection, $table, $lifetime, $this->app));
    }

    protected function createLegacyDatabaseDriver()
    {
        $connection = $this->getDatabaseConnection();
        $table = $this->app['config']['session.table'];
        $lifetime = $this->app['config']['session.lifetime'];
        return $this->buildSession(new LegacyDatabaseSessionHandler($connection, $table, $lifetime));
    }

    protected function getDatabaseConnection()
    {
        $connection = $this->app['config']['session.connection'];
        return $this->app['db']->connection($connection);
    }

    protected function createApcDriver()
    {
        return $this->createCacheBased('apc');
    }

    protected function createMemcachedDriver()
    {
        return $this->createCacheBased('memcached');
    }

    protected function createWincacheDriver()
    {
        return $this->createCacheBased('wincache');
    }

    protected function createRedisDriver()
    {
        $handler = $this->createCacheHandler('redis');
        $handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
        return $this->buildSession($handler);
    }

    protected function createCacheBased($driver)
    {
        return $this->buildSession($this->createCacheHandler($driver));
    }

    protected function createCacheHandler($driver)
    {
        $minutes = $this->app['config']['session.lifetime'];
        return new CacheBasedSessionHandler(clone $this->app['cache']->driver($driver), $minutes);
    }

    protected function buildSession($handler)
    {
        if ($this->app['config']['session.encrypt']) {
            return new EncryptedStore(
                $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
            );
        } else {
            return new Store($this->app['config']['session.cookie'], $handler);
        }
    }

    public function getSessionConfig()
    {
        return $this->app['config']['session'];
    }

    public function getDefaultDriver()
    {
        return $this->app['config']['session.driver'];
    }

    public function setDefaultDriver($name)
    {
        $this->app['config']['session.driver'] = $name;
    }
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}