Skip to content

Commit 553bf00

Browse files
committed
Fix #1515 Devtools version errors with Phalcon 5
1 parent f88378b commit 553bf00

File tree

2 files changed

+71
-10
lines changed

2 files changed

+71
-10
lines changed

src/Utils/SystemInfo.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
namespace Phalcon\DevTools\Utils;
1414

15-
use Phalcon\DevTools\Version;
15+
use Phalcon\DevTools\Version as DevToolsVersion;
16+
use Phalcon\DevTools\PhalconVersion;
1617
use Phalcon\Di\Injectable;
1718
use Phalcon\Registry;
1819
use Phalcon\Url;
1920
use Phalcon\Url\UrlInterface;
20-
use Phalcon\Version as PhVersion;
2121

2222
/**
2323
* @property Registry $registry
@@ -53,11 +53,28 @@ public function getUris(): array
5353
];
5454
}
5555

56+
/**
57+
* @return string
58+
*/
59+
public function getPhalconVersion(): string
60+
{
61+
// Check if Phalcon is version >= 5.0
62+
if (class_exists('\Phalcon\Support\Version')) {
63+
return (new \Phalcon\Support\Version())->get();
64+
}
65+
66+
if (class_exists('\Phalcon\Version')) {
67+
return \Phalcon\Version::get();
68+
}
69+
70+
return 'Unknown';
71+
}
72+
5673
public function getVersions(): array
5774
{
5875
return [
59-
'Phalcon DevTools Version' => Version::get(),
60-
'Phalcon Version' => PhVersion::get(),
76+
'Phalcon DevTools Version' => DevToolsVersion::get(),
77+
'Phalcon Version' => $this->getPhalconVersion(),
6178
'AdminLTE Version' => '3.0.1',
6279
];
6380
}

src/Version.php

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,66 @@
1212

1313
namespace Phalcon\DevTools;
1414

15-
use Phalcon\Version as PhVersion;
16-
1715
/**
1816
* This class allows to get the installed version of the Developer Tools
1917
*/
20-
class Version extends PhVersion
18+
class Version
2119
{
20+
2221
/**
23-
* {@inheritdoc}
24-
*
2522
* @return array
2623
*/
2724
// phpcs:disable
2825
protected static function getVersion(): array
2926
{
30-
return [4, 1, 1, 0, 0];
27+
return [4, 2, 0, 0, 0];
3128
}
3229
// phpcs:enable
30+
31+
public static function get(): string
32+
{
33+
list($major,$medium,$minor,$special,$specialNumber) = self::getVersion();
34+
35+
$result = $major . '.' . $medium . '.' . $minor;
36+
$suffix = self::getSpecial($special);
37+
38+
if ($suffix !== '') {
39+
/**
40+
* A pre-release version should be denoted by appending alpha/beta or RC and
41+
* a patch version.
42+
* examples 5.0.0alpha2, 5.0.0beta1, 5.0.0RC3
43+
*/
44+
$result .= $suffix;
45+
46+
if ($specialNumber !== 0) {
47+
$result .= $specialNumber;
48+
}
49+
}
50+
51+
return $result;
52+
}
53+
54+
/**
55+
* Translates a number to a special release.
56+
* @param int $special
57+
* @return string
58+
*/
59+
protected static function getSpecial(int $special): string
60+
{
61+
switch($special) {
62+
case 1:
63+
$suffix = 'alpha';
64+
break;
65+
case 2:
66+
$suffix = 'beta';
67+
break;
68+
case 3:
69+
$suffix = 'RC';
70+
break;
71+
default:
72+
$suffix = '';
73+
}
74+
return $suffix;
75+
}
76+
3377
}

0 commit comments

Comments
 (0)