Skip to content

Commit

Permalink
add basic MAMP osx support (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloep authored Oct 13, 2022
1 parent 4668edc commit 50a7902
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

require_once __DIR__ .'/lib/RexStan.php';
$cliPhpVersion = RexStan::execCmd('php -r "echo PHP_VERSION_ID;"', $lastError);
$cliPhpVersion = RexStan::execCmd(RexStan::phpExecutable().' -r "echo PHP_VERSION_ID;"', $lastError);
if (is_numeric($cliPhpVersion)) {
if ($cliPhpVersion < 70300) {
if (DIRECTORY_SEPARATOR === '\\') {
Expand Down
20 changes: 18 additions & 2 deletions lib/RexStan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

final class RexStan
{
public static function phpExecutable(): string {
if ('Darwin' === PHP_OS_FAMILY) {
$executable = 'php';
$customConfig = '/Library/Application Support/appsolute/MAMP PRO/conf/php'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION.'.ini';
if (is_file($customConfig)) {
$executable .= ' -c "'.$customConfig.'"';
}

$mampPhp = '/Applications/MAMP/bin/php/php'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION.'/bin/';
if (is_executable($mampPhp.'php')) {
return 'PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:'.$mampPhp.'" '.$executable;
}
}
return 'php';
}

/**
* @return string
*/
Expand Down Expand Up @@ -116,7 +132,7 @@ private static function phpstanBinPath(): string
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
$path = realpath(__DIR__.'/../vendor/bin/phpstan.bat');
} else {
$path = realpath(__DIR__.'/../vendor/bin/phpstan');
$path = self::phpExecutable().' '.realpath(__DIR__.'/../vendor/bin/phpstan');
}

if (false === $path) {
Expand All @@ -131,7 +147,7 @@ private static function phpstanBaselineAnalyzeBinPath(): string
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
$path = realpath(__DIR__.'/../vendor/bin/phpstan-baseline-analyze.bat');
} else {
$path = realpath(__DIR__.'/../vendor/bin/phpstan-baseline-analyze');
$path = self::phpExecutable().' '.realpath(__DIR__.'/../vendor/bin/phpstan-baseline-analyze');
}

if (false === $path) {
Expand Down

0 comments on commit 50a7902

Please sign in to comment.