Skip to content
Permalink
Browse files

Make the session an attribute as well.

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 e1feed3b0f44ee9039ac71089dfff1688fa5998a
Showing with 12 additions and 7 deletions.
  1. +5 −5 src/Network/Request.php
  2. +7 −2 tests/TestCase/Network/RequestTest.php
@@ -172,7 +172,7 @@ class Request implements ArrayAccess
*
* @var \Cake\Network\Session
*/
protected $_session;
protected $session;
/**
* Store the additional attributes attached to the request.
@@ -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.
@@ -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'];
}
/**
@@ -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;
}
/**
@@ -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));
}
}
/**
@@ -3181,7 +3185,8 @@ public function emulatedPropertyProvider()
return [
['params'],
['base'],
['webroot']
['webroot'],
['session']
];
}

0 comments on commit e1feed3

Please sign in to comment.
You can’t perform that action at this time.