$pear->list
I’ve seen three people ask a variation of how can I get a list of installed PEAR packages from within my PHP script
in the last few weeks on IRC, and two just in the last day. Because I’m a helpful sort, here’s a little morsel of code that will do just that:
include 'PEAR/Registry.php'; $reg = new PEAR_Registry; foreach ($reg->listPackages() as $package) { print "$package\n"; }
This should work with pretty much any version of PEAR.
(Update: Ken has a nifty bit of code in the comments to check for a specific installed version of a package.)
October 13th, 2007 at 11:46
Oh, that beats PEAR_Info
October 14th, 2007 at 02:03
Adam Harvey’s Blog: $pear->list…
…
October 14th, 2007 at 04:03
[...] Harvey has a (very) quick post with a hint for PEAR users out there – how to get a list of installaed packages on the system [...]
October 15th, 2007 at 08:05
This inspired me to find a way to check if certain packages of a specific version are installed:
include ‘PEAR/Registry.php’;
$reg = new PEAR_Registry;
$packages = array(array(“PEAR”, “1.6.2″),
array(“Date”, “1.4.7″),
array(“Date_Holidays”, “0.17.1″),
array(“Validate_IE”, “0.2.1″));
foreach($packages as $package) {
$pkg = $reg->getPackage($package[0]);
$version = $pkg->getVersion();
echo “{$package[0]} – {$package[1]} – “, version_compare($version, $package[1], “>=”) ? “OK”: “BAD”, “\n”;
}
November 25th, 2009 at 10:49
[...] $pear->list [...]