Extract classes and using namespaces

This commit is contained in:
2014-04-11 17:39:53 -05:00
parent ecf187ffb6
commit ee6b75a5b4
3 changed files with 306 additions and 236 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace astropenguin\botanical;
use ArrayObject;
class Args
{
//parseOptions utilitiese by tgckpg
static function PARSE ( $argStream, $handler )
{
//Chop first useless argument -- argv[0]
array_shift ( $argStream ) ;
//Initiate ArrayObject for iterator
$arrayobject = new ArrayObject ( $argStream ) ;
//Initiate iterator for iteration
$iterator = $arrayobject->getIterator();
//If options is set first
if( $iterator->valid() && preg_match ( '/^-\w$/', $iterator->current() ) )
{
//iterate through whole argument stream
for ( ; $iterator->valid(); $iterator->next() )
{
//Check if reached next option
if( preg_match ( '/^-\w$/', $opts = $iterator->current() ) )
{
//Get current options
$currOpt = $opts;
//echo "$currOpt\n";
//Test if next stream is an option
for ( $iterator->next(); $iterator->valid(); $iterator->next() )
{
if ( preg_match ( '/^-\w$/', $opts = $iterator->current() ) )
{
//echo "$currOpt $opts\n";
$handler($currOpt);
$currOpt = $opts;
} else break;
//var_dump($iterator->valid());
}
}//End if
//echo "$currOpt $opts\n";
$handler($currOpt, $opts);
//A temporary fix for infinite loop
if(!$iterator->valid()) break;
}// End for
}
// If option is not set first.
else
{
//Try other approach.
}
// End if
}
}