Ejemplo n.º 1
0
        if ($parameters === null) {
            return;
        }
        if (!is_array($parameters)) {
            throw new CommandParserException('"parameters" must be an array. ' + $parameters);
        }
        // all parameters must contain only numbers
        if (!array_reduce($parameters, function ($acc, $item) {
            return $acc && self::valid($item);
        }, true)) {
            throw new CommandParserException('Command parameters must be numeric');
        }
        // parameters must be at most 'arduino.max_command_parameters'
        if (count($parameters) > self::$PARAMETERS_LENGTH) {
            throw new CommandParserException('Command parameters must be at most ' . self::$PARAMETERS_LENGTH);
        }
        $this->parameters = $parameters;
    }
    public function __toString()
    {
        $str = $this->key;
        if (!empty($this->parameters)) {
            $str .= self::$COMMAND_FIELD_SEPARATOR;
            $str .= implode(self::$COMMAND_FIELD_SEPARATOR, $this->parameters);
        }
        $str .= self::$COMMAND_TERMINATOR;
        return $str;
    }
}
Command::init();