mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-25 09:11:17 +02:00
35 lines
578 B
PHP
35 lines
578 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\State;
|
|
|
|
class OrderContext
|
|
{
|
|
/**
|
|
* @var State
|
|
*/
|
|
private $state;
|
|
|
|
public static function create(): OrderContext
|
|
{
|
|
$order = new self();
|
|
$order->state = new StateCreated();
|
|
|
|
return $order;
|
|
}
|
|
|
|
public function setState(State $state)
|
|
{
|
|
$this->state = $state;
|
|
}
|
|
|
|
public function proceedToNext()
|
|
{
|
|
$this->state->proceedToNext($this);
|
|
}
|
|
|
|
public function toString()
|
|
{
|
|
return $this->state->toString();
|
|
}
|
|
}
|