-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CPU architecture detection and option
- Loading branch information
Michael
committed
Nov 20, 2024
1 parent
420326e
commit bf3c48b
Showing
15 changed files
with
274 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DBrekelmans\BrowserDriverInstaller\Command\Input; | ||
|
||
use DBrekelmans\BrowserDriverInstaller\Cpu\CpuArchitecture; | ||
use DBrekelmans\BrowserDriverInstaller\Exception\UnexpectedType; | ||
use DBrekelmans\BrowserDriverInstaller\OperatingSystem\OperatingSystem; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use UnexpectedValueException; | ||
use function array_map; | ||
use function implode; | ||
use function is_string; | ||
use function sprintf; | ||
|
||
/** @implements Option<OperatingSystem> */ | ||
final class CpuArchitectureOption extends InputOption implements Option | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
self::name(), | ||
$this->shortcut(), | ||
$this->mode()->value, | ||
$this->description(), | ||
$this->default(), | ||
); | ||
} | ||
|
||
public static function name(): string | ||
{ | ||
return 'arch'; | ||
} | ||
|
||
public function shortcut(): string|null | ||
{ | ||
return null; | ||
} | ||
|
||
public function mode(): OptionMode | ||
{ | ||
return OptionMode::REQUIRED; | ||
} | ||
|
||
public function description(): string | ||
{ | ||
return sprintf( | ||
'CPU architecture for which to install the driver (%s)', | ||
implode('|', array_map(static fn ($case) => $case->value, CpuArchitecture::cases())), | ||
); | ||
} | ||
|
||
public function default(): string|null | ||
{ | ||
return CpuArchitecture::X86_64->value; | ||
} | ||
|
||
public static function value(InputInterface $input): CpuArchitecture | ||
Check failure on line 60 in src/Command/Input/CpuArchitectureOption.php GitHub Actions / phpstan
|
||
{ | ||
$value = $input->getOption(self::name()); | ||
|
||
if (! is_string($value)) { | ||
throw UnexpectedType::expected('string', $value); | ||
} | ||
|
||
if (CpuArchitecture::tryFrom($value) === null) { | ||
throw new UnexpectedValueException( | ||
sprintf( | ||
'Unexpected value %s. Expected one of: %s', | ||
$value, | ||
implode(', ', array_map(static fn ($case) => $case->value, CpuArchitecture::cases())), | ||
), | ||
); | ||
} | ||
|
||
return CpuArchitecture::from($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace DBrekelmans\BrowserDriverInstaller\Cpu; | ||
|
||
enum CpuArchitecture: string | ||
{ | ||
case X86_64 = 'x86_64'; | ||
case ARM64 = 'arm64'; | ||
|
||
public function toCommandOutput(): string | ||
{ | ||
return match ($this) { | ||
self::X86_64 => '', | ||
self::ARM64 => ' arm64', | ||
}; | ||
} | ||
|
||
public static function detectFromPhp(): CpuArchitecture | ||
{ | ||
return match (php_uname('m')) { | ||
'arm64', 'aarch64' => CpuArchitecture::ARM64, | ||
default => CpuArchitecture::X86_64, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.