diff --git a/composer.json b/composer.json index c77f40c1..44eaabd2 100644 --- a/composer.json +++ b/composer.json @@ -28,12 +28,12 @@ "ext-pcre": "*", "ext-mbstring": "*", "ext-json": "*", - "symfony/process": "^4.0|^5.0" + "symfony/process": "^4.2|^5.0" }, "require-dev": { "phpunit/phpunit": "^7.5", - "phpstan/phpstan": "^0.11", + "phpstan/phpstan": "^0.12", "friendsofphp/php-cs-fixer": "^2.16" }, "autoload": { diff --git a/src/OS/Windows.php b/src/OS/Windows.php index 01750f00..c0dc77a1 100644 --- a/src/OS/Windows.php +++ b/src/OS/Windows.php @@ -2,7 +2,6 @@ namespace Ginfo\OS; -use Ginfo\Exceptions\FatalException; use Ginfo\Info\Cpu; use Ginfo\Info\Disk\Drive; use Ginfo\Info\Disk\Mount; @@ -24,25 +23,14 @@ */ class Windows extends OS { - private $process; private $infoCache = []; + private $powershellDirectory; - /** - * Windows constructor. - * - * @throws FatalException - */ public function __construct() { - try { - $powershellDirectory = \getenv('SystemRoot').'\\System32\\WindowsPowerShell\\v1.0'; - if (!\is_dir($powershellDirectory)) { - $powershellDirectory = null; - } - - $this->process = new SymfonyProcess(null, $powershellDirectory); - } catch (\Exception $e) { - throw new FatalException($e->getMessage()); + $this->powershellDirectory = \getenv('SystemRoot').'\\System32\\WindowsPowerShell\\v1.0'; + if (!\is_dir($this->powershellDirectory)) { + $this->powershellDirectory = null; } } @@ -52,8 +40,8 @@ private function getInfo(string $name): ?array return $this->infoCache[$name]; } - $process = $this->process->setCommandLine('chcp 65001 | powershell -file '.__DIR__.'/../../bin/windows/'.$name.'.ps1'); - $process->run(); + $process = SymfonyProcess::fromShellCommandline('chcp 65001 | powershell -file "!FILE!"', $this->powershellDirectory); + $process->run(null, ['FILE' => __DIR__.'/../../bin/windows/'.$name.'.ps1']); if (!$process->isSuccessful()) { return null;