public function parse( array $args = null, $ignoreExceptions = false, $skipFirstArgument = true ) {

		if( $args === null ) {
			$args = $GLOBALS['argv'];
		}

		if( $skipFirstArgument ) {
			array_shift($args);
		}

		list($longParams, $shortParams, $this->arguments) = $this->splitArguments($args, $this->definedFlags);

		foreach( $longParams as $name => $value ) {
			if( !isset($this->definedFlags[$name]) ) {
				if( !$ignoreExceptions ) {
					throw new InvalidFlagParamException('Unknown option: --' . $name);
				}
			} else {
				$defined_flag =& $this->definedFlags[$name];

				if( $this->validateType($defined_flag[self::DEF_TYPE], $value) ) {
					$defined_flag[self::DEF_VALUE]  = $value;
					$defined_flag[self::DEF_PARSED] = true;
				} else {
					if( !$ignoreExceptions ) {
						throw new InvalidFlagTypeException('Option --' . $name . ' expected type: "' . $defined_flag[self::DEF_TYPE] . '"');
					}
				}
			}
		}

		foreach( $shortParams as $char => $value ) {
			if( !isset($this->definedShortFlags[$char]) ) {
				if( !$ignoreExceptions ) {
					throw new InvalidFlagParamException('Unknown option: -' . $char);
				}
			} else {
				$this->definedShortFlags[$char][self::DEF_VALUE] = $value;
			}
		}

		foreach( $this->definedFlags as $name => $data ) {
			if( $data[self::DEF_VALUE] === null ) {
				if( !$ignoreExceptions ) {
					throw new MissingFlagParamException('Expected option --' . $name . ' missing.');
				}
			}
		}

		$this->parsed = true;
	}
public function parse( array $args = null, $ignoreExceptions = false, $skipFirstArgument = true ) {

		if( $args === null ) {
			$args = $GLOBALS['argv'];
		}

		if( $skipFirstArgument ) {
			array_shift($args);
		}

		list($longParams, $shortParams, $this->arguments) = $this->splitArguments($args, $this->definedFlags);

		foreach( $longParams as $name => $value ) {
			if( !isset($this->definedFlags[$name]) ) {
				if( !$ignoreExceptions ) {
					throw new InvalidFlagParamException('Unknown option: --' . $name);
				}
			} else {
				$defined_flag =& $this->definedFlags[$name];

				if( $this->validateType($defined_flag[self::DEF_TYPE], $value) ) {
					$defined_flag[self::DEF_VALUE]  = $value;
					$defined_flag[self::DEF_PARSED] = true;
				} else {
					if( !$ignoreExceptions ) {
						throw new InvalidFlagTypeException('Option --' . $name . ' expected type: "' . $defined_flag[self::DEF_TYPE] . '"');
					}
				}
			}
		}

		foreach( $shortParams as $char => $value ) {
			if( !isset($this->definedShortFlags[$char]) ) {
				if( !$ignoreExceptions ) {
					throw new InvalidFlagParamException('Unknown option: -' . $char);
				}
			} else {
				$this->definedShortFlags[$char][self::DEF_VALUE] = $value;
			}
		}

		foreach( $this->definedFlags as $name => $data ) {
			if( $data[self::DEF_VALUE] === null ) {
				if( !$ignoreExceptions ) {
					throw new MissingFlagParamException('Expected option --' . $name . ' missing.');
				}
			}
		}

		$this->parsed = true;
	}
public function parse ( array $ args = null , $ ignoreExceptions = false , $ skipFirstArgument = true ) { if ( $ args === null ) { $ args = $ GLOBALS [ 'argv' ] ; } if ( $ skipFirstArgument ) { array_shift ( $ args ) ; } list ( $ longParams , $ shortParams , $ this -> arguments ) = $ this -> splitArguments ( $ args , $ this -> definedFlags ) ; foreach ( $ longParams as $ name => $ value ) { if ( ! isset ( $ this -> definedFlags [ $ name ] ) ) { if ( ! $ ignoreExceptions ) { throw new InvalidFlagParamException ( 'Unknown option: --' . $ name ) ; } } else { $ defined_flag = & $ this -> definedFlags [ $ name ] ; if ( $ this -> validateType ( $ defined_flag [ self :: DEF_TYPE ] , $ value ) ) { $ defined_flag [ self :: DEF_VALUE ] = $ value ; $ defined_flag [ self :: DEF_PARSED ] = true ; } else { if ( ! $ ignoreExceptions ) { throw new InvalidFlagTypeException ( 'Option --' . $ name . ' expected type: "' . $ defined_flag [ self :: DEF_TYPE ] . '"' ) ; } } } } foreach ( $ shortParams as $ char => $ value ) { if ( ! isset ( $ this -> definedShortFlags [ $ char ] ) ) { if ( ! $ ignoreExceptions ) { throw new InvalidFlagParamException ( 'Unknown option: -' . $ char ) ; } } else { $ this -> definedShortFlags [ $ char ] [ self :: DEF_VALUE ] = $ value ; } } foreach ( $ this -> definedFlags as $ name => $ data ) { if ( $ data [ self :: DEF_VALUE ] === null ) { if ( ! $ ignoreExceptions ) { throw new MissingFlagParamException ( 'Expected option --' . $ name . ' missing.' ) ; } } } $ this -> parsed = true ; }
Parses flag definitions from the argument list, which should include the command name.
Must be called after all flags are defined and before flags are accessed by the program.

Will throw exceptions on Missing Require Flags, Unknown Flags or Incorrect Flag Types

@param array $args The arguments to parse, defaults to $GLOBALS['argv']
@param bool  $ignoreExceptions Setting to true causes parsing to continue even after an exception has been thrown.
@param bool  $skipFirstArgument Setting to false causes the first argument to be parsed as an parameter rather than the command.
@throws Exceptions\MissingFlagParamException
@throws Exceptions\InvalidFlagParamException
@throws Exceptions\InvalidFlagTypeException
Parses flag definitions from the argument list which should include the command name . Must be called after all flags are defined and before flags are accessed by the program .