/** * {@inheritdoc} */ public function validate() { if (is_string($this->value)) { if (preg_match('~^([0-9\\.-]+)$~', $this->value)) { $this->value = floatval(Str::toNumber($this->value)); return true; } } else { if (is_bool($this->value) === false && ($newValue = filter_var($this->value, FILTER_VALIDATE_FLOAT)) !== false) { $this->value = $newValue; return true; } } return false; }
/** * Set the port portion of the url * * @param string|null $port */ public function setPort($port = null) { if (is_null($port) || is_int($port)) { $this->port = $port; } else { if (is_string($port) && preg_match('/^[0-9]+$/', $port) !== 0) { $this->port = Str::toNumber($port); } else { throw new InvalidArgumentException("invalid value provided for 'port'; " . " expecting an integer, string of integers, or null"); } } return $this; }