classes/options.php
private function parseOption($rawOption) {
		$regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#";
		if (preg_match($regex, trim($rawOption), $matches)) {
			if (isset($matches['option'])) {
				$option = ltrim($matches['option'], '-');
				if (isset($matches['value'])) {
					$value = $matches['value'];
				}

				if (strlen($option) == 1) {
					//Short Option
					$validOptions = $this->validShortOptions;
				} elseif (strlen($option) >= 2) {
					//Long Option
					$validOptions = $this->validLongOptions;
				}
				if (!isset($validOptions[$option])) {
					die("The option `{$option}` does not exist.\n");
				}
				if ($validOptions[$option]['value'] === self::VALUE_REQUIRED && !isset($value)) {
					die("The option `{$option}` requires a value, but none was given.\n");
				}
				if (isset($validOptions[$option]['allowed']) || (isset($validOptions[$option]['comma_delimited']) && $validOptions[$option]['comma_delimited'] == true)) {
					$value = explode(',', $value);
					$value = array_map('trim', $value);
				}
				if (isset($validOptions[$option]['allowed'])) {
					foreach ($value as $_value) {
						if (!in_array($_value, $validOptions[$option]['allowed'])) {
							die("The value `{$_value}` for `{$option}` is not valid.\n");
						}
					}
				}
				$this->options[$option] = (isset($value) ? $value : true);
			}
		}
	}
private function parseOption($rawOption) {
		$regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#";
		if (preg_match($regex, trim($rawOption), $matches)) {
			if (isset($matches['option'])) {
				$option = ltrim($matches['option'], '-');
				if (isset($matches['value'])) {
					$value = $matches['value'];
				}

				if (strlen($option) == 1) {
					//Short Option
					$validOptions = $this->validShortOptions;
				} elseif (strlen($option) >= 2) {
					//Long Option
					$validOptions = $this->validLongOptions;
				}
				if (!isset($validOptions[$option])) {
					die("The option `{$option}` does not exist.\n");
				}
				if ($validOptions[$option]['value'] === self::VALUE_REQUIRED && !isset($value)) {
					die("The option `{$option}` requires a value, but none was given.\n");
				}
				if (isset($validOptions[$option]['allowed']) || (isset($validOptions[$option]['comma_delimited']) && $validOptions[$option]['comma_delimited'] == true)) {
					$value = explode(',', $value);
					$value = array_map('trim', $value);
				}
				if (isset($validOptions[$option]['allowed'])) {
					foreach ($value as $_value) {
						if (!in_array($_value, $validOptions[$option]['allowed'])) {
							die("The value `{$_value}` for `{$option}` is not valid.\n");
						}
					}
				}
				$this->options[$option] = (isset($value) ? $value : true);
			}
		}
	}
private function parseOption ( $ rawOption ) { $ regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#" ; if ( preg_match ( $ regex , trim ( $ rawOption ) , $ matches ) ) { if ( isset ( $ matches [ 'option' ] ) ) { $ option = ltrim ( $ matches [ 'option' ] , '-' ) ; if ( isset ( $ matches [ 'value' ] ) ) { $ value = $ matches [ 'value' ] ; } if ( strlen ( $ option ) == 1 ) { //Short Option $ validOptions = $ this -> validShortOptions ; } elseif ( strlen ( $ option ) >= 2 ) { //Long Option $ validOptions = $ this -> validLongOptions ; } if ( ! isset ( $ validOptions [ $ option ] ) ) { die ( "The option `{$option}` does not exist.\n" ) ; } if ( $ validOptions [ $ option ] [ 'value' ] === self :: VALUE_REQUIRED && ! isset ( $ value ) ) { die ( "The option `{$option}` requires a value, but none was given.\n" ) ; } if ( isset ( $ validOptions [ $ option ] [ 'allowed' ] ) || ( isset ( $ validOptions [ $ option ] [ 'comma_delimited' ] ) && $ validOptions [ $ option ] [ 'comma_delimited' ] == true ) ) { $ value = explode ( ',' , $ value ) ; $ value = array_map ( 'trim' , $ value ) ; } if ( isset ( $ validOptions [ $ option ] [ 'allowed' ] ) ) { foreach ( $ value as $ _value ) { if ( ! in_array ( $ _value , $ validOptions [ $ option ] [ 'allowed' ] ) ) { die ( "The value `{$_value}` for `{$option}` is not valid.\n" ) ; } } } $ this -> options [ $ option ] = ( isset ( $ value ) ? $ value : true ) ; } } }
Parse a raw option

@access	private
@param	string	Raw option from the command line.
@return	array	Option name, value if provided.
Parse a raw option