Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created October 27, 2023 21:50
Show Gist options
  • Save ghostwriter/97595a51ba36ee148ac6d2840e3b8f72 to your computer and use it in GitHub Desktop.
Save ghostwriter/97595a51ba36ee148ac6d2840e3b8f72 to your computer and use it in GitHub Desktop.
<?php
function getOpenBinary(): string
{
return match (PHP_OS_FAMILY) {
// Using PowerShell allows us to open the file in the background
'Windows' => 'powershell Start-Process',
'Darwin' => 'open',
'Linux' => 'xdg-open',
default => throw new Exception(500,
sprintf("Unable to find a matching binary for OS family '%s'", PHP_OS_FAMILY)
)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment