Number() { return intval($this->value); } /** * Return the version as a human readable string * * @return string */ public function toString() { if (!empty($this->alias)) { return $this->alias; } $version = ''; if (!empty($this->nickname)) { $version .= $this->nickname . ' '; } if (!empty($this->value)) { if (preg_match("/([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(?:\.([0-9]+))?(?:([ab])([0-9]+))?/", $this->value, $match)) { $v = [ $match[1] ]; if (array_key_exists(2, $match) && strlen($match[2])) { $v[] = $match[2]; } if (array_key_exists(3, $match) && strlen($match[3])) { $v[] = $match[3]; } if (array_key_exists(4, $match) && strlen($match[4])) { $v[] = $match[4]; } if (!empty($this->details)) { if ($this->details < 0) { array_splice($v, $this->details, 0 - $this->details); } if ($this->details > 0) { array_splice($v, $this->details, count($v) - $this->details); } } if (isset($this->builds) && !$this->builds) { $count = count($v); for ($i = 0; $i < $count; $i++) { if ($v[$i] > 999) { array_splice($v, $i, 1); } } } $version .= implode('.', $v); if (array_key_exists(5, $match) && strlen($match[5])) { $version .= $match[5] . (!empty($match[6]) ? $match[6] : ''); } } } return $version; } /** * Get an array of all defined properties * * @internal * * @return array */ public function toArray() { $result = []; if (!empty($this->value)) { if (!empty($this->details)) { $parts = explode('.', $this->value); $result['value'] = join('.', array_slice($parts, 0, $this->details)); } else { $result['value'] = $this->value; } } if (!empty($this->alias)) { $result['alias'] = $this->alias; } if (!empty($this->nickname)) { $result['nickname'] = $this->nickname; } if (isset($result['value']) && !isset($result['alias']) && !isset($result['nickname'])) { return $result['value']; } return $result; } }