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