src/GameOfLife/Inputs/BoardEditor/OptionHandler/BoardEditorOptionParser.php
/**
     * Calls an option from the option list.
     *
     * @param String $_input Input string
     *
     * @return bool True: Board Editor session is finished
     *              False: Board Editor session continues
     *
     * @throws \Exception The exception when the option or its arguments are invalid
     */
Calls an option from the option list.
@param String $_input Input string

@return bool True: Board Editor session is finished
False: Board Editor session continues

@throws \Exception The exception when the option or its arguments are invalid
Calls an option from the option list . @param String $_input Input string @return bool True : Board Editor session is finished False : Board Editor session continues @throws \ Exception The exception when the option or its arguments are invalid
public function callOption(String $_input): bool
    {
        $optionData = $this->isOption($_input);
        if ($optionData)
        {
            $option = $this->parentOptionHandler->options()[$optionData["name"]];
            $numberOfArguments = count($optionData["arguments"]);
            if ($numberOfArguments > $option->getNumberOfArguments())
            {
                throw new \Exception("Invalid number of arguments (Expected " . $option->getNumberOfArguments() . ", Got " . $numberOfArguments . ").");
            }
            else
            {
                $arguments = $this->getOptionArguments($option, $optionData["arguments"]);
                $sessionFinished = call_user_func_array(array($option, $option->callback()), $arguments);
                return $sessionFinished;
            }
        }
        else
        {
            if (strlen($_input) == 0) throw new \Exception("Input is empty.");
            else
            {
                $optionParts = explode(" ", $_input);
                $optionName = $optionParts[0];
                if (is_numeric($optionName))
                {
                    if (count($optionParts) == 2) return $this->callOption($optionParts[0] . "," . $optionParts[1]);
                    else throw new \Exception("Invalid coordinates format.");
                }
                else throw new \Exception("Invalid option \"" . $optionName . "\".");
            }
        }
    }
public function callOption ( String $ _input ) : bool { $ optionData = $ this -> isOption ( $ _input ) ; if ( $ optionData ) { $ option = $ this -> parentOptionHandler -> options ( ) [ $ optionData [ " name " ] ] ; $ numberOfArguments = count ( $ optionData [ " arguments " ] ) ; if ( $ numberOfArguments > $ option -> getNumberOfArguments ( ) ) { throw new \ Exception ( " Invalid number of arguments (Expected  " . $ option -> getNumberOfArguments ( ) . " , Got  " . $ numberOfArguments . " ). " ) ; } else { $ arguments = $ this -> getOptionArguments ( $ option , $ optionData [ " arguments " ] ) ; $ sessionFinished = call_user_func_array ( array ( $ option , $ option -> callback ( ) ) , $ arguments ) ; return $ sessionFinished ; } } else { if ( strlen ( $ _input ) == 0 ) throw new \ Exception ( " Input is empty. " ) ; else { $ optionParts = explode ( " " , $ _input ) ; $ optionName = $ optionParts [ 0 ] ; if ( is_numeric ( $ optionName ) ) { if ( count ( $ optionParts ) == 2 ) return $ this -> callOption ( $ optionParts [ 0 ] . " , " . $ optionParts [ 1 ] ) ; else throw new \ Exception ( " Invalid coordinates format. " ) ; } else throw new \ Exception ( " Invalid option  \" " . $ optionName . " \" . " ) ; } } }
Calls an option from the option list.
Calls an option from the option list .