From 7ddd61cab4327e8d3dd98f8bd8f24d764a8724fa Mon Sep 17 00:00:00 2001 From: KUBO Atsuhiro Date: Sat, 4 Aug 2012 17:24:15 +0900 Subject: [PATCH] [PageFlow] Improved the PageFlow::getView() method. --- src/Piece/Flow/PageFlow/PageFlow.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Piece/Flow/PageFlow/PageFlow.php b/src/Piece/Flow/PageFlow/PageFlow.php index b372dd1..0a0a319 100644 --- a/src/Piece/Flow/PageFlow/PageFlow.php +++ b/src/Piece/Flow/PageFlow/PageFlow.php @@ -154,17 +154,12 @@ public function getView() { if (!$this->isActive()) return null; - if (!$this->isFinalState()) { - $viewIndex = $this->getCurrentState()->getID(); - } else { - $viewIndex = $this->getPreviousState()->getID(); + $state = $this->isFinalState() ? $this->getPreviousState() : $this->getCurrentState(); + if (!array_key_exists($state->getID(), $this->views)) { + throw new InvalidTransitionException(sprintf('An invalid transition detected. The state [ %s ] does not have a view. Maybe the state [ %s ] is an action state. Check the definition for [ %s ].', $state->getID(), $state->getID(), $this->getID())); } - if (!array_key_exists($viewIndex, $this->views)) { - throw new InvalidTransitionException("A invalid transition detected. The state [ $viewIndex ] does not have a view. Maybe The state [ $viewIndex ] is an action state. Check the definition of the flow [ {$this->id} ]."); - } - - return $this->views[$viewIndex]; + return $this->views[ $state->getID() ]; } public function getID()