DataSift\Storyplayer\Phases\ActionPhase::doPhase PHP Method

doPhase() public method

public doPhase ( $story )
    public function doPhase($story)
    {
        // shorthand
        $st = $this->st;
        $storyResult = $story->getResult();
        // keep track of what happens with the action
        $phaseResult = $this->getNewPhaseResult();
        // do we have anything to do?
        if (!$story->hasActions()) {
            $phaseResult->setContinuePlaying($phaseResult::HASNOACTIONS, "story has no action instructions");
            return $phaseResult;
        }
        // run ONE of the actions, picked at random
        try {
            // do any setup
            $this->doPerPhaseSetup();
            // make the call
            $action = $story->getOneAction();
            $action($st);
            // if we get here, all is well
            if ($storyResult->getStoryShouldFail()) {
                $phaseResult->setPlayingFailed($phaseResult::COMPLETED, "action completed successfully; was expected to fail");
                $storyResult->setStoryHasFailed($phaseResult);
            } else {
                $phaseResult->setContinuePlaying();
            }
        } catch (E5xx_ActionFailed $e) {
            if ($storyResult->getStoryShouldFail()) {
                $phaseResult->setContinuePlaying($phaseResult::FAILED, $e->getMessage(), $e);
            } else {
                $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
                $storyResult->setStoryHasFailed($phaseResult);
            }
        } catch (E5xx_ExpectFailed $e) {
            if ($storyResult->getStoryShouldFail()) {
                $phaseResult->setContinuePlaying($phaseResult::FAILED, $e->getMessage(), $e);
            } else {
                $phaseResult->setPlayingFailed($phaseResult::FAILED, $e->getMessage(), $e);
                $storyResult->setStoryHasFailed($phaseResult);
            }
        } catch (E5xx_NotImplemented $e) {
            $phaseResult->setPlayingFailed($phaseResult::INCOMPLETE, $e->getMessage(), $e);
            $storyResult->setStoryIsIncomplete($phaseResult);
        } catch (Exception $e) {
            $phaseResult->setPlayingFailed($phaseResult::ERROR, $e->getMessage(), $e);
            $storyResult->setStoryHasError($phaseResult);
        }
        // close off any open log actions
        $st->closeAllOpenActions();
        // tidy up after ourselves
        $this->doPerPhaseTeardown();
        // all done
        return $phaseResult;
    }
ActionPhase