Вход Регистрация
Файл: concrete5.7.5.6/concrete/src/Session/SessionFactory.php
Строк: 180
<?php

namespace ConcreteCoreSession;

use 
ConcreteCoreApplicationApplication;
use 
ConcreteCoreHttpRequest;
use 
IlluminateConfigRepository;
use 
ConcreteCoreSessionStorageHandlerNativeFileSessionHandler;
use 
SymfonyComponentHttpFoundationSessionStorageHandlerPdoSessionHandler;
use 
SymfonyComponentHttpFoundationSessionStorageMockArraySessionStorage;
use 
SymfonyComponentHttpFoundationSessionStorageNativeSessionStorage;
use 
SymfonyComponentHttpFoundationSessionSession as SymfonySession;

/**
 * Class SessionFactory
 * Base concrete5 session factory
 * @package ConcreteCoreSession
 */
class SessionFactory implements SessionFactoryInterface
{

    
/** @var ConcreteCoreApplicationApplication */
    
private $app;

    
/** @var ConcreteCoreHttpRequest */
    
private $request;

    public function 
__construct(Application $appRequest $request)
    {
        
$this->app $app;
        
$this->request $request;
    }

    
/**
     * Create a new symfony session object
     * This method MUST NOT start the session
     *
     * @return SymfonyComponentHttpFoundationSessionSession
     */
    
public function createSession()
    {
        
$config $this->app['config'];
        
$storage $this->getSessionStorage($config);

        
$session = new SymfonySession($storage);
        
$session->setName($config->get('concrete.session.name'));

        
/**
         * @todo Move this to somewhere else
         */
        
$this->request->setSession($session);

        return 
$session;
    }

    
/**
     * @param IlluminateConfigRepository $config
     * @return SymfonyComponentHttpFoundationSessionStorageSessionStorageInterface
     */
    
private function getSessionStorage(Repository $config)
    {
        
$app $this->app;

        if (
$app->isRunThroughCommandLineInterface()) {
            
$storage = new MockArraySessionStorage();
        } else {
            
$handler $this->getSessionHandler($config);
            
$storage = new NativeSessionStorage(array(), $handler);

            
// Initialize the storage with some options
            
$options $config->get('concrete.session.cookie');
            if (
$options['cookie_path'] === false) {
                
$options['cookie_path'] = $app['app_relative_path'] . '/';
            }
            
$options['gc_max_lifetime'] = $config->get('concrete.session.max_lifetime');
            
$storage->setOptions($options);
        }

        return 
$storage;
    }

    
/**
     * @param IlluminateConfigRepository $config
     * @return SessionHandlerInterface
     */
    
private function getSessionHandler(Repository $config)
    {
        if (
$config->get('concrete.session.handler') == 'database') {
            
$db $this->app['database']->connection();
            
$handler = new PdoSessionHandler($db->getWrappedConnection(), array(
                
'db_table' => 'Sessions',
                
'db_id_col' => 'sessionID',
                
'db_data_col' => 'sessionValue',
                
'db_time_col' => 'sessionTime'
            
));
        } else {
            
$savePath $config->get('concrete.session.save_path') ?: null;
            
$handler = new NativeFileSessionHandler($savePath);
        }

        return 
$handler;
    }

}
Онлайн: 2
Реклама