diff --git a/src/Utils/SystemInfo.php b/src/Utils/SystemInfo.php index 9da2b293a..1ea7857b1 100644 --- a/src/Utils/SystemInfo.php +++ b/src/Utils/SystemInfo.php @@ -12,12 +12,12 @@ namespace Phalcon\DevTools\Utils; -use Phalcon\DevTools\Version; +use Phalcon\DevTools\Version as DevToolsVersion; +use Phalcon\DevTools\PhalconVersion; use Phalcon\Di\Injectable; use Phalcon\Registry; use Phalcon\Url; use Phalcon\Url\UrlInterface; -use Phalcon\Version as PhVersion; /** * @property Registry $registry @@ -53,11 +53,28 @@ public function getUris(): array ]; } + /** + * @return string + */ + public function getPhalconVersion(): string + { + // Check if Phalcon is version >= 5.0 + if (class_exists('\Phalcon\Support\Version')) { + return (new \Phalcon\Support\Version())->get(); + } + + if (class_exists('\Phalcon\Version')) { + return \Phalcon\Version::get(); + } + + return 'Unknown'; + } + public function getVersions(): array { return [ - 'Phalcon DevTools Version' => Version::get(), - 'Phalcon Version' => PhVersion::get(), + 'Phalcon DevTools Version' => DevToolsVersion::get(), + 'Phalcon Version' => $this->getPhalconVersion(), 'AdminLTE Version' => '3.0.1', ]; } diff --git a/src/Version.php b/src/Version.php index ab0b676c2..49b43d6d6 100644 --- a/src/Version.php +++ b/src/Version.php @@ -12,22 +12,66 @@ namespace Phalcon\DevTools; -use Phalcon\Version as PhVersion; - /** * This class allows to get the installed version of the Developer Tools */ -class Version extends PhVersion +class Version { + /** - * {@inheritdoc} - * * @return array */ // phpcs:disable protected static function getVersion(): array { - return [4, 1, 1, 0, 0]; + return [4, 2, 0, 0, 0]; } // phpcs:enable + + public static function get(): string + { + list($major,$medium,$minor,$special,$specialNumber) = self::getVersion(); + + $result = $major . '.' . $medium . '.' . $minor; + $suffix = self::getSpecial($special); + + if ($suffix !== '') { + /** + * A pre-release version should be denoted by appending alpha/beta or RC and + * a patch version. + * examples 5.0.0alpha2, 5.0.0beta1, 5.0.0RC3 + */ + $result .= $suffix; + + if ($specialNumber !== 0) { + $result .= $specialNumber; + } + } + + return $result; + } + + /** + * Translates a number to a special release. + * @param int $special + * @return string + */ + protected static function getSpecial(int $special): string + { + switch($special) { + case 1: + $suffix = 'alpha'; + break; + case 2: + $suffix = 'beta'; + break; + case 3: + $suffix = 'RC'; + break; + default: + $suffix = ''; + } + return $suffix; + } + }