1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-26 01:11:28 +02:00

Removed blank lines and added ?>

This commit is contained in:
CaMer0n
2008-01-22 02:06:35 +00:00
parent ad3b2bac36
commit b96596e310

View File

@@ -1,91 +1,92 @@
<?php <?php
/* /*
+ ----------------------------------------------------------------------------+ + ----------------------------------------------------------------------------+
| e107 website system | e107 website system
| |
| <20>Steve Dunstan 2001-2002 | <20>Steve Dunstan 2001-2002
| http://e107.org | http://e107.org
| jalist@e107.org | jalist@e107.org
| |
| Released under the terms and conditions of the | Released under the terms and conditions of the
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/cli_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/cli_class.php,v $
| $Revision: 1.1 $ | $Revision: 1.2 $
| $Date: 2008-01-21 13:25:42 $ | $Date: 2008-01-22 02:06:35 $
| $Author: mcfly_e107 $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
class eCLI class eCLI
{ {
/** /**
* Provided a list of command line arguments, parse them in a unix manner. * Provided a list of command line arguments, parse them in a unix manner.
* If no args are provided, will default to $_SERVER['argv'] * If no args are provided, will default to $_SERVER['argv']
* *
* @return array arg values * @return array arg values
*/ */
function parse_args($argv='') function parse_args($argv='')
{ {
if($argv == '') if($argv == '')
{ {
if(isset($_SERVER['argv'])) if(isset($_SERVER['argv']))
{ {
$argv = $_SERVER['argv']; $argv = $_SERVER['argv'];
} }
else else
{ {
return array(); return array();
} }
} }
if(!is_array($argv)) if(!is_array($argv))
{ {
return array(); return array();
} }
$_ARG = array(); $_ARG = array();
foreach ($argv as $arg) foreach ($argv as $arg)
{ {
if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches)) if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches))
{ {
$key = $matches[1]; $key = $matches[1];
switch ($matches[2]) switch ($matches[2])
{ {
case '': case '':
case 'true': case 'true':
$arg = true; $arg = true;
break; break;
case 'false': case 'false':
$arg = false; $arg = false;
break; break;
default: default:
$arg = $matches[2]; $arg = $matches[2];
} }
/* make unix like -afd == -a -f -d */ /* make unix like -afd == -a -f -d */
if(preg_match("/^-([a-zA-Z0-9]+)/", $matches[0], $match)) if(preg_match("/^-([a-zA-Z0-9]+)/", $matches[0], $match))
{ {
$string = $match[1]; $string = $match[1];
for($i=0; strlen($string) > $i; $i++) for($i=0; strlen($string) > $i; $i++)
{ {
$_ARG[$string[$i]] = true; $_ARG[$string[$i]] = true;
} }
} }
else else
{ {
/* --arg=val will assign $_ARG['arg'] to 'val' */ /* --arg=val will assign $_ARG['arg'] to 'val' */
/* --arg (or --arg=true) will assign $_ARG['arg'] to true */ /* --arg (or --arg=true) will assign $_ARG['arg'] to true */
/* --arg=false will assign $_ARG['arg'] to false */ /* --arg=false will assign $_ARG['arg'] to false */
$_ARG[$key] = $arg; $_ARG[$key] = $arg;
} }
} }
else else
{ {
/* assume command input parm, add each to input array */ /* assume command input parm, add each to input array */
$_ARG['input'][] = $arg; $_ARG['input'][] = $arg;
} }
} }
return $_ARG; return $_ARG;
} }
} }
?>