From 16026b4ce3536bf94d49c0e2fd6d603c323ea281 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 11:57:54 +0200 Subject: [PATCH 1/6] Added getEnv method --- Dockerfile | 2 + composer.lock | 202 +++++++++++++++++++----------------- src/System/System.php | 152 ++++++++++++++------------- tests/System/SystemTest.php | 7 ++ 4 files changed, 195 insertions(+), 168 deletions(-) diff --git a/Dockerfile b/Dockerfile index 668b676..744a528 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM composer:2.0 as composer ARG TESTING=false ENV TESTING=$TESTING +ENV TESTA=VALUEA +ENV TESTB=VALUEB WORKDIR /usr/local/src/ diff --git a/composer.lock b/composer.lock index 2e19ae7..c8a8c55 100644 --- a/composer.lock +++ b/composer.lock @@ -79,16 +79,16 @@ }, { "name": "laravel/pint", - "version": "v1.13.3", + "version": "v1.13.11", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "93b2d0d49719bc6e444ba21cd4dbbccec935413d" + "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/93b2d0d49719bc6e444ba21cd4dbbccec935413d", - "reference": "93b2d0d49719bc6e444ba21cd4dbbccec935413d", + "url": "https://api.github.com/repos/laravel/pint/zipball/60a163c3e7e3346a1dec96d3e6f02e6465452552", + "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552", "shasum": "" }, "require": { @@ -99,13 +99,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.34.1", - "illuminate/view": "^10.23.1", - "laravel-zero/framework": "^10.1.2", - "mockery/mockery": "^1.6.6", - "nunomaduro/larastan": "^2.6.4", + "friendsofphp/php-cs-fixer": "^3.49.0", + "illuminate/view": "^10.43.0", + "larastan/larastan": "^2.8.1", + "laravel-zero/framework": "^10.3.0", + "mockery/mockery": "^1.6.7", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.18.2" + "pestphp/pest": "^2.33.6" }, "bin": [ "builds/pint" @@ -141,7 +141,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2023-10-10T15:39:09+00:00" + "time": "2024-02-13T17:20:13+00:00" }, { "name": "myclabs/deep-copy", @@ -204,25 +204,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.17.1", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -230,7 +232,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -254,26 +256,27 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2023-08-13T19:53:39+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -314,9 +317,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -371,16 +380,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.39", + "version": "1.10.66", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4" + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d9dedb0413f678b4d03cbc2279a48f91592c97c4", - "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd", + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd", "shasum": "" }, "require": { @@ -429,27 +438,27 @@ "type": "tidelift" } ], - "time": "2023-10-17T15:46:26+00:00" + "time": "2024-03-28T16:17:31+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.29", + "version": "9.2.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -499,7 +508,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" }, "funding": [ { @@ -507,7 +516,7 @@ "type": "github" } ], - "time": "2023-09-19T04:57:46+00:00" + "time": "2024-03-02T06:37:42+00:00" }, { "name": "phpunit/php-file-iterator", @@ -752,16 +761,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.13", + "version": "9.6.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", "shasum": "" }, "require": { @@ -835,7 +844,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.18" }, "funding": [ { @@ -851,20 +860,20 @@ "type": "tidelift" } ], - "time": "2023-09-19T05:39:22+00:00" + "time": "2024-03-21T12:07:32+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", "shasum": "" }, "require": { @@ -899,7 +908,7 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" }, "funding": [ { @@ -907,7 +916,7 @@ "type": "github" } ], - "time": "2020-09-28T06:08:49+00:00" + "time": "2024-03-02T06:27:43+00:00" }, { "name": "sebastian/code-unit", @@ -1096,20 +1105,20 @@ }, { "name": "sebastian/complexity", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", "shasum": "" }, "require": { - "nikic/php-parser": "^4.7", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1141,7 +1150,7 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" }, "funding": [ { @@ -1149,20 +1158,20 @@ "type": "github" } ], - "time": "2020-10-26T15:52:27+00:00" + "time": "2023-12-22T06:19:30+00:00" }, { "name": "sebastian/diff", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", "shasum": "" }, "require": { @@ -1207,7 +1216,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" }, "funding": [ { @@ -1215,7 +1224,7 @@ "type": "github" } ], - "time": "2023-05-07T05:35:17+00:00" + "time": "2024-03-02T06:30:58+00:00" }, { "name": "sebastian/environment", @@ -1282,16 +1291,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", "shasum": "" }, "require": { @@ -1347,7 +1356,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" }, "funding": [ { @@ -1355,20 +1364,20 @@ "type": "github" } ], - "time": "2022-09-14T06:03:37+00:00" + "time": "2024-03-02T06:33:00+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.6", + "version": "5.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bde739e7565280bda77be70044ac1047bc007e34" + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", - "reference": "bde739e7565280bda77be70044ac1047bc007e34", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", "shasum": "" }, "require": { @@ -1411,7 +1420,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" }, "funding": [ { @@ -1419,24 +1428,24 @@ "type": "github" } ], - "time": "2023-08-02T09:26:13+00:00" + "time": "2024-03-02T06:35:11+00:00" }, { "name": "sebastian/lines-of-code", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", "shasum": "" }, "require": { - "nikic/php-parser": "^4.6", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1468,7 +1477,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" }, "funding": [ { @@ -1476,7 +1485,7 @@ "type": "github" } ], - "time": "2020-11-28T06:42:11+00:00" + "time": "2023-12-22T06:20:34+00:00" }, { "name": "sebastian/object-enumerator", @@ -1655,16 +1664,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -1676,7 +1685,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -1697,8 +1706,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -1706,7 +1714,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", @@ -1819,16 +1827,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.1", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -1857,7 +1865,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -1865,7 +1873,7 @@ "type": "github" } ], - "time": "2021-07-28T10:34:58+00:00" + "time": "2024-03-03T12:36:25+00:00" } ], "aliases": [], @@ -1880,5 +1888,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/System/System.php b/src/System/System.php index c5b849c..c44dbef 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -119,77 +119,6 @@ public static function getHostname(): string return php_uname('n'); } - /** - * Checks if the system is running on an ARM64 architecture. - * - * @return bool - */ - public static function isArm64(): bool - { - return (bool) preg_match(self::RegexARM64, self::getArch()); - } - - /** - * Checks if the system is running on an ARMV7 architecture. - * - * @return bool - */ - public static function isArmV7(): bool - { - return (bool) preg_match(self::RegexARMV7, self::getArch()); - } - - /** - * Checks if the system is running on an ARM64 architecture. - * - * @return bool - */ - public static function isArmV8(): bool - { - return (bool) preg_match(self::RegexARMV8, self::getArch()); - } - - /** - * Checks if the system is running on an X86 architecture. - * - * @return bool - */ - public static function isX86(): bool - { - return (bool) preg_match(self::RegExX86, self::getArch()); - } - - /** - * Checks if the system is running on an PowerPC architecture. - * - * @return bool - */ - public static function isPPC(): bool - { - return (bool) preg_match(self::RegExPPC, self::getArch()); - } - - /** - * Checks if the system is the passed architecture. - * You should pass `System::X86`, `System::PPC`, `System::ARM` or an equivalent string. - * - * @param string $arch - * @return bool - * - * @throws Exception - */ - public static function isArch(string $arch): bool - { - return match ($arch) { - self::X86 => self::isX86(), - self::PPC => self::isPPC(), - self::ARM64 => self::isArm64(), - self::ARMV7 => self::isArmV7(), - self::ARMV8 => self::isArmV8(), - default => throw new Exception("'{$arch}' not found."), - }; - } - /** * Gets the system's total amount of CPU cores. * @@ -589,4 +518,85 @@ public static function getNetworkUsage(int $duration = 1): array return $IOUsage; } + + /** + * Checks if the system is running on an ARM64 architecture. + * + * @return bool + */ + public static function getEnv(string $name, string $default = null): ?string + { + return getenv($name) ?? $default; + } + + /** + * Checks if the system is running on an ARM64 architecture. + * + * @return bool + */ + public static function isArm64(): bool + { + return (bool) preg_match(self::RegexARM64, self::getArch()); + } + + /** + * Checks if the system is running on an ARMV7 architecture. + * + * @return bool + */ + public static function isArmV7(): bool + { + return (bool) preg_match(self::RegexARMV7, self::getArch()); + } + + /** + * Checks if the system is running on an ARM64 architecture. + * + * @return bool + */ + public static function isArmV8(): bool + { + return (bool) preg_match(self::RegexARMV8, self::getArch()); + } + + /** + * Checks if the system is running on an X86 architecture. + * + * @return bool + */ + public static function isX86(): bool + { + return (bool) preg_match(self::RegExX86, self::getArch()); + } + + /** + * Checks if the system is running on an PowerPC architecture. + * + * @return bool + */ + public static function isPPC(): bool + { + return (bool) preg_match(self::RegExPPC, self::getArch()); + } + + /** + * Checks if the system is the passed architecture. + * You should pass `System::X86`, `System::PPC`, `System::ARM` or an equivalent string. + * + * @param string $arch + * @return bool + * + * @throws Exception + */ + public static function isArch(string $arch): bool + { + return match ($arch) { + self::X86 => self::isX86(), + self::PPC => self::isPPC(), + self::ARM64 => self::isArm64(), + self::ARMV7 => self::isArmV7(), + self::ARMV8 => self::isArmV8(), + default => throw new Exception("'{$arch}' not found."), + }; + } } diff --git a/tests/System/SystemTest.php b/tests/System/SystemTest.php index c9b3e9e..e746701 100644 --- a/tests/System/SystemTest.php +++ b/tests/System/SystemTest.php @@ -112,4 +112,11 @@ public function testGetNetworkUsage(): void System::getNetworkUsage(); } } + + public function testGetEnv(): void + { + $this->assertEquals(System::getEnv('TESTA', 'DEFAULTA'), 'VALUEA'); + $this->assertEquals(System::getEnv('TESTB', 'DEFAULTB'), 'VALUEB'); + $this->assertEquals(System::getEnv('TESTC', 'DEFAULTC'), 'DEFAULTC'); + } } From 6752e7e1d1afa92378fac1d8198fadf409b07a50 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 12:02:30 +0200 Subject: [PATCH 2/6] Updated return value --- src/System/System.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/System.php b/src/System/System.php index c44dbef..2510038 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -524,7 +524,7 @@ public static function getNetworkUsage(int $duration = 1): array * * @return bool */ - public static function getEnv(string $name, string $default = null): ?string + public static function getEnv(string $name, string $default = null): string|bool { return getenv($name) ?? $default; } From 11b40af60fb78b8c36d5fa2ab362a47574f0bb8b Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 12:06:02 +0200 Subject: [PATCH 3/6] Added one more test --- src/System/System.php | 4 ++-- tests/System/SystemTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/System/System.php b/src/System/System.php index 2510038..e78de7a 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -524,9 +524,9 @@ public static function getNetworkUsage(int $duration = 1): array * * @return bool */ - public static function getEnv(string $name, string $default = null): string|bool + public static function getEnv(string $name, string $default = null): ?string { - return getenv($name) ?? $default; + return getenv($name) ?: $default; } /** diff --git a/tests/System/SystemTest.php b/tests/System/SystemTest.php index e746701..0ede284 100644 --- a/tests/System/SystemTest.php +++ b/tests/System/SystemTest.php @@ -118,5 +118,6 @@ public function testGetEnv(): void $this->assertEquals(System::getEnv('TESTA', 'DEFAULTA'), 'VALUEA'); $this->assertEquals(System::getEnv('TESTB', 'DEFAULTB'), 'VALUEB'); $this->assertEquals(System::getEnv('TESTC', 'DEFAULTC'), 'DEFAULTC'); + $this->assertEquals(System::getEnv('TESTC'), null); } } From 2ab5d72a62786025447a8ccd7ac8e1bf58601e35 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 12:08:59 +0200 Subject: [PATCH 4/6] Fixed error --- src/System/System.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System/System.php b/src/System/System.php index e78de7a..f602dfe 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -167,7 +167,7 @@ private static function getProcStatData(): array $cpus = explode("\n", $cpustats); // Remove non-CPU lines - $cpus = array_filter($cpus, function ($cpu) { + $cpus = array_filter($cpus, function (string $cpu) { return preg_match('/^cpu[0-999]/', $cpu); }); @@ -522,7 +522,7 @@ public static function getNetworkUsage(int $duration = 1): array /** * Checks if the system is running on an ARM64 architecture. * - * @return bool + * @return string|null */ public static function getEnv(string $name, string $default = null): ?string { From d0ec6411b62140c7b352d67e23b5ff942e6bfdf6 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 12:10:27 +0200 Subject: [PATCH 5/6] Fixed error --- src/System/System.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/System.php b/src/System/System.php index f602dfe..80cb859 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -167,7 +167,7 @@ private static function getProcStatData(): array $cpus = explode("\n", $cpustats); // Remove non-CPU lines - $cpus = array_filter($cpus, function (string $cpu) { + $cpus = array_filter($cpus, function (string $cpu): bool { return preg_match('/^cpu[0-999]/', $cpu); }); From ecfc5ed540f9e7d74abc4a24db3f553ffe889b94 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 1 Apr 2024 12:11:58 +0200 Subject: [PATCH 6/6] Fixed error --- src/System/System.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/System.php b/src/System/System.php index 80cb859..c40034c 100644 --- a/src/System/System.php +++ b/src/System/System.php @@ -168,7 +168,7 @@ private static function getProcStatData(): array // Remove non-CPU lines $cpus = array_filter($cpus, function (string $cpu): bool { - return preg_match('/^cpu[0-999]/', $cpu); + return (bool)preg_match('/^cpu[0-999]/', $cpu); }); foreach ($cpus as $cpu) {