Skip to content

Commit

Permalink
Make the session an attribute as well.
Browse files Browse the repository at this point in the history
This adds cohesion between how middleware and controllers, letting both
access the session in the same way.
  • Loading branch information
markstory committed Sep 13, 2016
1 parent f334cd2 commit e1feed3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Network/Request.php
Expand Up @@ -172,7 +172,7 @@ class Request implements ArrayAccess
*
* @var \Cake\Network\Session
*/
protected $_session;
protected $session;

/**
* Store the additional attributes attached to the request.
Expand All @@ -186,7 +186,7 @@ class Request implements ArrayAccess
*
* @var array
*/
protected $emulatedAttributes = ['webroot', 'base', 'params'];
protected $emulatedAttributes = ['session', 'webroot', 'base', 'params'];

/**
* Array of Psr\Http\Message\UploadedFileInterface objects.
Expand Down Expand Up @@ -338,7 +338,7 @@ protected function _setConfig($config)
$this->data = $this->_processFiles($config['post'], $config['files']);
$this->query = $this->_processGet($config['query'], $querystr);
$this->params = $config['params'];
$this->_session = $config['session'];
$this->session = $config['session'];
}

/**
Expand Down Expand Up @@ -526,10 +526,10 @@ public function contentType()
public function session(Session $session = null)
{
if ($session === null) {
return $this->_session;
return $this->session;
}

return $this->_session = $session;
return $this->session = $session;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -3109,7 +3109,11 @@ public function testGetAttributesCompatibility($prop)
'webroot' => '/cakeapp/'
]);

$this->assertSame($request->{$prop}, $request->getAttribute($prop));
if ($prop === 'session') {
$this->assertSame($request->session(), $request->getAttribute($prop));
} else {
$this->assertSame($request->{$prop}, $request->getAttribute($prop));
}
}

/**
Expand Down Expand Up @@ -3181,7 +3185,8 @@ public function emulatedPropertyProvider()
return [
['params'],
['base'],
['webroot']
['webroot'],
['session']
];
}

Expand Down

0 comments on commit e1feed3

Please sign in to comment.