Skip to content

Commit

Permalink
Fix #1515 Devtools version errors with Phalcon 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultimater committed Jul 13, 2021
1 parent f88378b commit 553bf00
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
25 changes: 21 additions & 4 deletions src/Utils/SystemInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
];
}
Expand Down
56 changes: 50 additions & 6 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit 553bf00

Please sign in to comment.