hholzgra Wed Jul 2 12:54:46 2003 EDT
Added files:
/pear/PECL_Gen/Tools Platform.php
Modified files:
/pear/PECL_Gen package.xml
Log:
yet another helper class
Index: pear/PECL_Gen/package.xml
diff -u pear/PECL_Gen/package.xml:1.6 pear/PECL_Gen/package.xml:1.7
--- pear/PECL_Gen/package.xml:1.6 Wed Jul 2 11:58:29 2003
+++ pear/PECL_Gen/package.xml Wed Jul 2 12:54:46 2003
@@no-spam -65,6 +65,7 @@no-spam
<file role="php">ExtensionParser.php</file>
<dir name="Tools">
<file role="php">Getopt.php</file>
+ <file role="php">Platform.php</file>
</dir>
</dir>
</filelist>
Index: pear/PECL_Gen/Tools/Platform.php
+++ pear/PECL_Gen/Tools/Platform.php
<?php
/**
* A helper class for platform management
*
* @no-spam public
*/
class PECL_Gen_Tools_Platform
extends PEAR
{
/**
* The supported platforms are collected here
*
* @no-spam private
* @no-spam array the platform short names
*/
var $platforms = array();
/**
* Constructor gets a list of names or "all"
*
* @no-spam public
* @no-spam string|array names as comma separated string or array
*/
function __construct($names)
{
if (is_string($names)) {
$names = explode(",", $names);
}
foreach ($names as $name) {
switch (strtolower(trim($name))) {
case "all":
$this->platforms["win"] = true;
$this->platforms["unix"] = true;
break;
case "win":
case "win23":
case "windows":
case "microsoft":
$this->platforms["win"] = true;
break;
case "unix":
case "posix":
case "gnu":
$this->platforms["unix"] = true;
break;
default:
$this = $this->raiseError("'$name' is not a supported platform");
break(2);
}
}
}
/**
* Test for a platform shortname
*
* @no-spam public
* @no-spam string shortname
* @no-spam bool true if supported else false
*/
function test($name)
{
switch (strtolower(trim($name))) {
case "all":
return 2 == $this->count();
case "win":
case "win23":
case "windows":
case "microsoft":
return isset($this->platform["win"]);
case "unix":
case "posix":
case "gnu":
return ($this->platform["unix"]);
default:
return false;
}
}
/**
* Count the number of supported platforms
*
* @no-spam public
* @no-spam int platform count
*/
function count()
{
return count($this->platforms());
}
}
?>