public function createStatemachine($subject)
{
$process = $this->processDetector->detectProcess($subject);
if ($this->stateNameDetector) {
$stateName = $this->stateNameDetector->detectCurrentStateName($subject);
} else {
$stateName = null;
}
if ($this->mutexFactory) {
$mutex = $this->mutexFactory->createMutex($subject);
} else {
$mutex = null;
}
$statemachine = new Statemachine($subject, $process, $stateName, $this->transitonSelector, $mutex);
foreach ($this->statemachineObserver as $observer) {
$statemachine->attach($observer);
}
return $statemachine;
}