DataSift\Storyplayer\Cli\PlayStory_Command::initPlayerList PHP Method

initPlayerList() protected method

protected initPlayerList ( Phix_Project\CliEngine $cliEngine, DataSift\Storyplayer\Injectables $injectables, array $cliParams ) : void
$cliEngine Phix_Project\CliEngine
$injectables DataSift\Storyplayer\Injectables
$cliParams array
return void
    protected function initPlayerList(CliEngine $cliEngine, Injectables $injectables, $cliParams)
    {
        // our list of stories to play
        $this->playerList = [];
        // do we have any parameters at this point?
        if (empty($cliParams)) {
            $msg = "no stories listed on the command-line." . PHP_EOL . PHP_EOL . "see 'storyplayer help play-story' for required params" . PHP_EOL;
            $this->output->logCliError($msg);
            exit(1);
        }
        // keep track of the stories to play
        $storiesToPlay = [];
        foreach ($cliParams as $cliParam) {
            // figure out what to do?
            if (is_dir($cliParam)) {
                $storiesToPlay = array_merge($storiesToPlay, $this->addStoriesFromFolder($cliEngine, $injectables, $cliParam));
            } else {
                if (is_file($cliParam)) {
                    // are we loading a story, or a list of stories?
                    $paramParts = explode('.', $cliParams[0]);
                    $paramSuffix = end($paramParts);
                    switch ($paramSuffix) {
                        case 'php':
                            $storiesToPlay = array_merge($storiesToPlay, $this->addStoryFromFile($cliEngine, $injectables, $cliParam));
                            break;
                        default:
                            $this->output->logCliError("unsupported story file '{$cliParam}'");
                            exit(1);
                    }
                } else {
                    // if we get here, we've no idea what to do
                    $this->output->logCliError("no such file: '{$cliParam}'");
                    exit(1);
                }
            }
        }
        // did we find any stories to play?
        if (count($storiesToPlay) == 0) {
            $this->output->logCliError("no stories to play :(");
            exit(1);
        }
        // wrap all of the stories in a TestEnvironment
        $this->playerList[] = new TestEnvironment_Player($storiesToPlay, $injectables);
    }