src/GameOfLife/Rules/CustomRule.php
/**
     * Initializes the rule.
     *
     * @param Getopt $_options The option list
     *
     * @throws \Exception The exception when the rules are in an invalid format or not set
     */
Initializes the rule.
@param Getopt $_options The option list

@throws \Exception The exception when the rules are in an invalid format or not set
Initializes the rule . @param Getopt $_options The option list @throws \ Exception The exception when the rules are in an invalid format or not set
public function initialize(Getopt $_options)
    {
        if ($_options->getOption("rulesString") !== null)
        {
            $rulesString = $_options->getOption("rulesString");
            if ($this->isStayAliveSlashBirthString($rulesString))
            {
                $this->parseStayAliveSlashBirthString($rulesString);
            }
            elseif ($this->isAlternateNotationString($rulesString))
            {
                $this->parseAlternateNotationString($rulesString);
            }
            else throw new \Exception("Unknown rules notation.");
        }
        elseif ($_options->getOption("rulesBirth") !== null && $_options->getOption("rulesStayAlive") !== null)
        {
            $rulesBirth = $_options->getOption("rulesBirth");
            $rulesStayAlive = $_options->getOption("rulesStayAlive");
            if (! is_numeric($rulesBirth)) throw new \Exception("The rule strings may contain only numbers.");
            elseif (! is_numeric($rulesStayAlive)) throw new \Exception("The rule strings may contain only numbers.");
            else
            {
                $this->rulesBirth = $this->getRulesFromNumericString($rulesBirth);
                $this->rulesStayAlive = $this->getRulesFromNumericString($rulesStayAlive);
            }
        }
        else throw new \Exception("The rules string is not set.");
        parent::initialize($_options);
    }
public function initialize ( Getopt $ _options ) { if ( $ _options -> getOption ( " rulesString " ) !== null ) { $ rulesString = $ _options -> getOption ( " rulesString " ) ; if ( $ this -> isStayAliveSlashBirthString ( $ rulesString ) ) { $ this -> parseStayAliveSlashBirthString ( $ rulesString ) ; } elseif ( $ this -> isAlternateNotationString ( $ rulesString ) ) { $ this -> parseAlternateNotationString ( $ rulesString ) ; } else throw new \ Exception ( " Unknown rules notation. " ) ; } elseif ( $ _options -> getOption ( " rulesBirth " ) !== null && $ _options -> getOption ( " rulesStayAlive " ) !== null ) { $ rulesBirth = $ _options -> getOption ( " rulesBirth " ) ; $ rulesStayAlive = $ _options -> getOption ( " rulesStayAlive " ) ; if ( ! is_numeric ( $ rulesBirth ) ) throw new \ Exception ( " The rule strings may contain only numbers. " ) ; elseif ( ! is_numeric ( $ rulesStayAlive ) ) throw new \ Exception ( " The rule strings may contain only numbers. " ) ; else { $ this -> rulesBirth = $ this -> getRulesFromNumericString ( $ rulesBirth ) ; $ this -> rulesStayAlive = $ this -> getRulesFromNumericString ( $ rulesStayAlive ) ; } } else throw new \ Exception ( " The rules string is not set. " ) ; parent :: initialize ( $ _options ) ; }
Initializes the rule.
Initializes the rule .