Coupling environment with PHP session info, avoids injector troubles

I'd rather have Session::get('TestSessionId') being passed in
as an identifier, but the env object is passed around so much
as a singleton that its easy to forget that argument,
and cause hard to debug errors. We need a global "app" object
which all other objects can reference somehow.
This commit is contained in:
Ingo Schommer 2014-03-03 16:19:38 +13:00
parent 808d6aa87a
commit 2b5984a73c
3 changed files with 22 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class TestSessionController extends Controller {
public function __construct() {
parent::__construct();
$this->environment = Injector::inst()->get('TestSessionEnvironment', Session::get('TestSessionId'));
$this->environment = Injector::inst()->get('TestSessionEnvironment');
}
public function init() {

View File

@ -54,7 +54,12 @@ class TestSessionEnvironment extends Object {
public function __construct($id = null) {
parent::__construct();
$this->id = $id;
if($id) {
$this->id = $id;
} else {
Session::start();
$this->id = Session::get('TestSessionId');
}
}
/**
@ -75,6 +80,20 @@ class TestSessionEnvironment extends Object {
return(file_exists($this->getFilePath()));
}
/**
* @param String $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* @return String
*/
public function getId() {
return $this->id;
}
/**
* Creates a temp database, sets up any extra requirements, and writes the state file. The database will be
* connected to as part of {@link self::applyState()}, so if you're continuing script execution after calling this

View File

@ -10,10 +10,7 @@ class TestSessionRequestFilter {
protected $testSessionEnvironment;
public function __construct() {
$this->testSessionEnvironment = Injector::inst()->get(
'TestSessionEnvironment',
Session::get('TestSessionId')
);
$this->testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
}
public function preRequest($req, $session, $model) {