Example #1
0
 /**
  * Set the default value of the option
  * @api
  * @alias	default
  * @param	mixed	$default	The default value for the option
  * @param	null|string	$display	The default value shown in help information
  *  If null given, will show json_encode($default).
  *  i.e. false will be shown as "false" instead of an empty string
  * @return	Option				$this
  */
 public function default_($default, $display = null)
 {
     if ($this->type == 'flag') {
         Helper::throwEx("Default value is not allowed for flag option, use bool option instead.");
     }
     $this->default = $default;
     if ($this->type == 'bool') {
         if (is_bool($default)) {
             $this->default = $default;
         } elseif (Helper::isTrue($default)) {
             $this->default = true;
         } elseif (Helper::isFalse($default)) {
             $this->default = false;
         } else {
             Helper::throwEx("Invalid bool value: {$default} for option -{$this->name}");
         }
     }
     if ($this->type == 'incr') {
         if (!preg_match("/^\\d+\$/", $default)) {
             Helper::throwEx("Value for increment option -{$this->name} should be an integer.");
         } elseif ($default < 0 or $default > $this->incrMax) {
             Helper::throwEx("Value for increment option -{$this->name} should be from 0 to {$this->incrMax}.");
         }
     }
     if (is_null($display)) {
         $display = @json_encode($this->default);
     }
     $this->defaultStr = $display;
     return $this;
 }