NasirNobin / zsh-valet

This zsh plugin will read `.valetphprc` from the project root and will switch to that PHP version automatically real time
MIT License
9 stars 1 forks source link

Test on older Homebrew & MacOS versions #2

Open NasirNobin opened 2 years ago

NasirNobin commented 2 years ago

Currently, this package assumes PHP binary is located at/opt/homebrew/opt/php@$PHP_VERSION/bin

But older homebrew versions don't store PHP bin into /opt/homebrew/ prefix also, it doesn't store on the same location.

NasirNobin commented 2 years ago

Possible paths:

- /usr/local/opt/php@7.2/bin
- /usr/local/opt/php@7.2/bin
- /opt/homebrew/etc/php/7.0/bin
- /opt/homebrew/opt/php@7.0/bin
- /usr/local/opt/php@5.6/bin
- /usr/local/opt/php@7.3/bin
- /usr/local/Cellar/php/8.0.2/bin
- /usr/local/Cellar/php/8.1.2/bin
- 

Sources:

NasirNobin commented 2 years ago

use brew --prefix to determine homebrew prefix

NasirNobin commented 2 years ago

from valet

/**
* Typical homebrew path resolutions are like:
* "../Cellar/php@7.4/7.4.13/bin/php"
* or older styles:
* "../Cellar/php/7.4.9_2/bin/php
* "../Cellar/php55/bin/php.
*/
preg_match('~\w{3,}/(php)(@?\d\.?\d)?/(\d\.\d)?([_\d\.]*)?/?\w{3,}~', $resolvedPath, $matches);