Skip to content

Commit

Permalink
Use model alias instead of full class name for Session.handler.model
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 16, 2013
1 parent 2c9503d commit b7c29cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
16 changes: 6 additions & 10 deletions Cake/Network/Session/DatabaseSession.php
Expand Up @@ -50,20 +50,16 @@ class DatabaseSession implements SessionHandlerInterface {
*
*/
public function __construct() {
$modelName = Configure::read('Session.handler.model');
$modelAlias = Configure::read('Session.handler.model');

if (empty($modelName)) {
$settings = array(
'alias' => 'Sessions',
if (empty($modelAlias)) {
$this->_table = TableRegistry::get('Sessions', [
'table' => 'cake_sessions',
);
]);
} else {
$settings = array(
'className' => $modelName,
'alias' => 'Sessions',
);
$this->_table = TableRegistry::get($modelAlias);
}
$this->_table = TableRegistry::get('Sessions', $settings);

$this->_timeout = Configure::read('Session.timeout') * 60;
}

Expand Down
18 changes: 7 additions & 11 deletions Cake/Test/TestCase/Network/Session/DatabaseSessionTest.php
Expand Up @@ -27,21 +27,16 @@
use Cake\TestSuite\TestCase;

/**
* Class SessionTestModel
* Database session test.
*
*/
class SessionTestTable extends Table {

protected $_table = 'sessions';

}
class DatabaseSessionTest extends TestCase {

/**
* Database session test.
* sessionBackup
*
* @var array
*/
class DatabaseSessionTest extends TestCase {

protected static $_sessionBackup;

/**
Expand All @@ -58,8 +53,9 @@ class DatabaseSessionTest extends TestCase {
*/
public static function setupBeforeClass() {
static::$_sessionBackup = Configure::read('Session');

Configure::write('Session.handler', array(
'model' => __NAMESPACE__ . '\SessionTestTable'
'model' => 'Sessions'
));
Configure::write('Session.timeout', 100);
}
Expand Down Expand Up @@ -105,7 +101,7 @@ public function testConstructionSettings() {
new DatabaseSession();

$session = TableRegistry::get('Sessions');
$this->assertInstanceOf(__NAMESPACE__ . '\SessionTestTable', $session);
$this->assertInstanceOf('Cake\ORM\Table', $session);
$this->assertEquals('Sessions', $session->alias());
$this->assertEquals(ConnectionManager::get('test'), $session->connection());
$this->assertEquals('sessions', $session->table());
Expand Down

0 comments on commit b7c29cd

Please sign in to comment.