Skip to content

Commit

Permalink
[PageFlow] Improved the PageFlow::getView() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
iteman committed Sep 18, 2012
1 parent 36c830d commit 7ddd61c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Piece/Flow/PageFlow/PageFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7ddd61c

Please sign in to comment.