, , , factory, ?
, (, , ).
, - :
class StateFactory {
$currentState;
function __construct(){
if(!isset($_SESSION['currentState'])){
$this->currentState = 'StateOne';
}
else{
$this->currentState = $_SESSION['currentState'];
}
$this->currentState = new {$this->currentState}->processState();
}
function __deconstruct(){
$_SESSION['currentState'] = $this->currentState;
}
}
abstract class State{
abstract function processState();
}
class StateOne extends State{
function processState(){
if(<check what is needed for this state>){
<do what you need to do for this state>
return 'StateTwo';
}
else
{
return 'StateWhatever';
}
}
}
class StateTwo extends State{
function processState(){
if(<check what is needed for this state>){
<do what you need to do for this state>
return 'StateThree';
}
else
{
return 'StateWhatever';
}
}
}
class StateThree extends State{
...
}
, , , -, , , , , .