I just released version 1.0.0 of my which PHP library and a CLI to go with it. Phew! This library parses the
PATH environment variable and provides a locator in order to find where a command is located, imitating the standard
which command. For example:
$locatorFactory = new \Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $locator = $locatorFactory->create(); echo $locator->locate('php'); // /usr/bin/php
The library and CLI both include full support for POSIX systems (Linux, BSD, OSX, etc.) and for Windows. I want to give a big thanks to @DanAtDE and @chadicus for helping out with the Windows support! Trying to get it working for both platforms was a fun experience. I'm happy with how things turned out and I had the opportunity to read some interesting documents because of it.
My original inspiration for creating this library was to increase support for my still-developing sensible library, which in turn was created to support @guywithnose's release-notes tool. (future blog posts forthcoming on both of these!) I created it primarily as a means of checking whether a user has a certain command available on their system. This method of lookup allows for picking from a list of possible utilities (e.g., firefox, chrome, …) and picking the first one found. I'm not aware of anything else out there in PHP to do this, so I'm hoping this utility is of use to others as well!
There's plenty of documentation in the README, so check it out and let me know what you think!