Skip to content

Commit d385e95

Browse files
Merge pull request #23 from utopia-php/feat-add-new-arch
Add ARMV7 and ARMV8 differentiators
2 parents 289c432 + eb39279 commit d385e95

File tree

11 files changed

+178
-25
lines changed

11 files changed

+178
-25
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ arch:
77
- arm64
88

99
php:
10-
- 7.4
1110
- 8.0
1211
- 8.0.23
1312

@@ -24,4 +23,4 @@ script:
2423
- vendor/bin/phpunit --configuration phpunit.xml --testsuite General
2524
- vendor/bin/psalm --show-info=true
2625
- if [ "$TRAVIS_CPU_ARCH" = "amd64" ]; then vendor/bin/phpunit --configuration phpunit.xml --testsuite X86; fi
27-
- if [ "$TRAVIS_CPU_ARCH" = "arm64" ]; then vendor/bin/phpunit --configuration phpunit.xml --testsuite ARM; fi
26+
- if [ "$TRAVIS_CPU_ARCH" = "arm64" ]; then vendor/bin/phpunit --configuration phpunit.xml --testsuite ARM64; fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ echo System::isX86(); // bool
3434

3535
## System Requirements
3636

37-
Utopia Framework requires PHP 7.4 or later. We recommend using the latest PHP version whenever possible.
37+
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
3838

3939
## Supported Methods
4040
| | getCPUCores | getCPUUsage | getMemoryTotal | getMemoryFree | getDiskTotal | getDiskFree | getIOUsage | getNetworkUsage |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"format": "./vendor/bin/pint"
2424
},
2525
"require": {
26-
"php": ">=7.4",
26+
"php": ">=8.0.0",
2727
"laravel/pint": "1.2.*"
2828
},
2929
"require-dev": {

phpunit.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
<testsuite name="PPC">
1919
<file>tests/System/SystemTestPPC.php</file>
2020
</testsuite>
21-
<testsuite name="ARM">
22-
<file>tests/System/SystemTestARM.php</file>
21+
<testsuite name="ARM64">
22+
<file>tests/System/SystemTestARM64.php</file>
23+
</testsuite>
24+
<testsuite name="ARMV7">
25+
<file>tests/System/SystemTestARMV7.php</file>
26+
</testsuite>
27+
<testsuite name="ARMV8">
28+
<file>tests/System/SystemTestARMV8.php</file>
2329
</testsuite>
2430
</testsuites>
2531
</phpunit>

src/System/System.php

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ class System
1010

1111
public const PPC = 'ppc';
1212

13-
public const ARM = 'arm';
13+
public const ARM64 = 'arm64';
14+
15+
public const ARMV7 = 'armv7';
16+
17+
public const ARMV8 = 'armv8';
1418

1519
private const RegExX86 = '/(x86*|i386|i686)/';
1620

17-
private const RegExARM = '/(aarch*|arm*)/';
21+
private const RegexARM64 = '/(aarch64)/';
22+
23+
private const RegexARMV7 = '/(armv7)/';
24+
25+
private const RegexARMV8 = '/(armv8)/';
1826

1927
private const RegExPPC = '/(ppc*)/';
2028

@@ -96,8 +104,12 @@ public static function getArchEnum(): string
96104
case preg_match(self::RegExPPC, $arch):
97105
return System::PPC;
98106
break;
99-
case preg_match(self::RegExARM, $arch):
100-
return System::ARM;
107+
case preg_match(self::RegexARM64, $arch):
108+
return System::ARM64;
109+
case preg_match(self::ARMV7, $arch):
110+
return System::ARMV7;
111+
case preg_match(self::ARMV8, $arch):
112+
return System::ARMV8;
101113
break;
102114

103115
default:
@@ -117,13 +129,33 @@ public static function getHostname(): string
117129
}
118130

119131
/**
120-
* Checks if the system is running on an ARM architecture.
132+
* Checks if the system is running on an ARM64 architecture.
133+
*
134+
* @return bool
135+
*/
136+
public static function isArm64(): bool
137+
{
138+
return (bool) preg_match(self::RegexARM64, self::getArch());
139+
}
140+
141+
/**
142+
* Checks if the system is running on an ARMV7 architecture.
143+
*
144+
* @return bool
145+
*/
146+
public static function isArmV7(): bool
147+
{
148+
return (bool) preg_match(self::RegexARMV7, self::getArch());
149+
}
150+
151+
/**
152+
* Checks if the system is running on an ARM64 architecture.
121153
*
122154
* @return bool
123155
*/
124-
public static function isArm(): bool
156+
public static function isArmV8(): bool
125157
{
126-
return (bool) preg_match(self::RegExARM, self::getArch());
158+
return (bool) preg_match(self::RegexARMV8, self::getArch());
127159
}
128160

129161
/**
@@ -164,8 +196,14 @@ public static function isArch(string $arch): bool
164196
case self::PPC:
165197
return self::isPPC();
166198
break;
167-
case self::ARM:
168-
return self::isArm();
199+
case self::ARM64:
200+
return self::isArm64();
201+
break;
202+
case self::ARMV7:
203+
return self::isArmV7();
204+
break;
205+
case self::ARMV8:
206+
return self::isArmV8();
169207
break;
170208

171209
default:

tests/System/SystemTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public function testOs()
3333
$this->assertIsString(System::getArch());
3434
$this->assertIsString(System::getArchEnum());
3535
$this->assertIsString(System::getHostname());
36-
$this->assertIsBool(System::isArm());
36+
$this->assertIsBool(System::isArm64());
37+
$this->assertIsBool(System::isArmV7());
38+
$this->assertIsBool(System::isArmV8());
3739
$this->assertIsBool(System::isPPC());
3840
$this->assertIsBool(System::isX86());
39-
$this->assertIsBool(System::isArch(System::ARM));
41+
$this->assertIsBool(System::isArch(System::ARM64));
42+
$this->assertIsBool(System::isArch(System::ARMV7));
43+
$this->assertIsBool(System::isArch(System::ARMV8));
4044
$this->assertIsBool(System::isArch(System::X86));
4145
$this->assertIsBool(System::isArch(System::PPC));
4246
$this->expectException('Exception');

tests/System/SystemTestARM.php renamed to tests/System/SystemTestARM64.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use PHPUnit\Framework\TestCase;
1919
use Utopia\System\System;
2020

21-
class SystemTestARM extends TestCase
21+
class SystemTestARM64 extends TestCase
2222
{
2323
public function setUp(): void
2424
{
@@ -30,14 +30,18 @@ public function tearDown(): void
3030

3131
public function testOs()
3232
{
33-
$this->assertTrue(System::isArm());
33+
$this->assertTrue(System::isArm64());
34+
$this->assertFalse(System::isArmV7());
35+
$this->assertFalse(System::isArmV8());
3436
$this->assertFalse(System::isPPC());
3537
$this->assertFalse(System::isX86());
3638

37-
$this->assertTrue(System::isArch(System::ARM));
39+
$this->assertTrue(System::isArch(System::ARM64));
40+
$this->assertFalse(System::isArch(System::ARMV7));
41+
$this->assertFalse(System::isArch(System::ARMV8));
3842
$this->assertFalse(System::isArch(System::PPC));
3943
$this->assertFalse(System::isArch(System::X86));
4044

41-
$this->assertEquals(System::ARM, System::getArchEnum());
45+
$this->assertEquals(System::ARM64, System::getArchEnum());
4246
}
4347
}

tests/System/SystemTestARMV7.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* Utopia PHP Framework
5+
*
6+
*
7+
* @link https://github.com/utopia-php/framework
8+
*
9+
* @author Eldad Fux <[email protected]>
10+
*
11+
* @version 1.0 RC4
12+
*
13+
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
14+
*/
15+
16+
namespace Utopia\Tests;
17+
18+
use PHPUnit\Framework\TestCase;
19+
use Utopia\System\System;
20+
21+
class SystemTestARMV7 extends TestCase
22+
{
23+
public function setUp(): void
24+
{
25+
}
26+
27+
public function tearDown(): void
28+
{
29+
}
30+
31+
public function testOs()
32+
{
33+
$this->assertFalse(System::isArm64());
34+
$this->assertTrue(System::isArmV7());
35+
$this->assertFalse(System::isArmV8());
36+
$this->assertFalse(System::isPPC());
37+
$this->assertFalse(System::isX86());
38+
39+
$this->assertFalse(System::isArch(System::ARM64));
40+
$this->assertTrue(System::isArch(System::ARMV7));
41+
$this->assertFalse(System::isArch(System::ARMV8));
42+
$this->assertFalse(System::isArch(System::PPC));
43+
$this->assertFalse(System::isArch(System::X86));
44+
45+
$this->assertEquals(System::ARMV7, System::getArchEnum());
46+
}
47+
}

tests/System/SystemTestARMV8.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* Utopia PHP Framework
5+
*
6+
*
7+
* @link https://github.com/utopia-php/framework
8+
*
9+
* @author Eldad Fux <[email protected]>
10+
*
11+
* @version 1.0 RC4
12+
*
13+
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
14+
*/
15+
16+
namespace Utopia\Tests;
17+
18+
use PHPUnit\Framework\TestCase;
19+
use Utopia\System\System;
20+
21+
class SystemTestARMV8 extends TestCase
22+
{
23+
public function setUp(): void
24+
{
25+
}
26+
27+
public function tearDown(): void
28+
{
29+
}
30+
31+
public function testOs()
32+
{
33+
$this->assertFalse(System::isArm64());
34+
$this->assertFalse(System::isArmV7());
35+
$this->assertTrue(System::isArmV8());
36+
$this->assertFalse(System::isPPC());
37+
$this->assertFalse(System::isX86());
38+
39+
$this->assertFalse(System::isArch(System::ARM64));
40+
$this->assertFalse(System::isArch(System::ARMV7));
41+
$this->assertTrue(System::isArch(System::ARMV8));
42+
$this->assertFalse(System::isArch(System::PPC));
43+
$this->assertFalse(System::isArch(System::X86));
44+
45+
$this->assertEquals(System::ARMV8, System::getArchEnum());
46+
}
47+
}

tests/System/SystemTestPPC.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ public function tearDown(): void
3030

3131
public function testOs()
3232
{
33-
$this->assertFalse(System::isArm());
33+
$this->assertFalse(System::isArm64());
34+
$this->assertFalse(System::isArmV7());
35+
$this->assertFalse(System::isArmV8());
3436
$this->assertTrue(System::isPPC());
3537
$this->assertFalse(System::isX86());
3638

37-
$this->assertFalse(System::isArch(System::ARM));
39+
$this->assertFalse(System::isArch(System::ARM64));
40+
$this->assertFalse(System::isArch(System::ARMV7));
41+
$this->assertFalse(System::isArch(System::ARMV8));
3842
$this->assertTrue(System::isArch(System::PPC));
3943
$this->assertFalse(System::isArch(System::X86));
4044

tests/System/SystemTestX86.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ public function tearDown(): void
3030

3131
public function testOs()
3232
{
33-
$this->assertFalse(System::isArm());
33+
$this->assertFalse(System::isArm64());
34+
$this->assertFalse(System::isArmV7());
35+
$this->assertFalse(System::isArmV8());
3436
$this->assertFalse(System::isPPC());
3537
$this->assertTrue(System::isX86());
3638

37-
$this->assertFalse(System::isArch(System::ARM));
39+
$this->assertFalse(System::isArch(System::ARM64));
40+
$this->assertFalse(System::isArch(System::ARMV7));
41+
$this->assertFalse(System::isArch(System::ARMV8));
3842
$this->assertFalse(System::isArch(System::PPC));
3943
$this->assertTrue(System::isArch(System::X86));
4044

0 commit comments

Comments
 (0)