Parses subfield ranges into single subfields.

@internal

@param string $arg The assumed subfield range

@throws CK\MARCspec\Exception\InvalidMARCspecException

@return array $_range[string] An array of subfield tags
180479
private function handleSubfieldRanges($arg)
    {
        if (strlen($arg) < 3) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::LENGTH3,
                $arg
            );
        }

        if (preg_match('/[a-z]/', $arg[0]) && !preg_match('/[a-z]/', $arg[2])) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::RANGE,
                $arg
            );
        }
        if (preg_match('/[A-Z]/', $arg[0]) && !preg_match('/[A-Z]/', $arg[2])) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::RANGE,
                $arg
            );
        }
        if (preg_match('/[0-9]/', $arg[0]) && !preg_match('/[0-9]/', $arg[2])) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::RANGE,
                $arg
            );
        }
        if ($arg[0] > $arg[2]) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::RANGE,
                $arg
            );
        }

        return range((string) $arg[0], (string) $arg[2]);
    }
37826
public static function ArgString($arg){

		$type = gettype($arg);

		if( $type === 'object'){
			$string = $arg->cache_string;
			unset($arg->cache_string);
			return $string;

		}elseif( $type === 'array' ){
			$string = ' Array(';
			foreach($arg as $k => $a){
				$string .= var_export($k,true).' => '.self::ArgString($a).',';
			}
			return $string . ')';
		}

		return var_export($arg,true);
	}
680965
public function parseFields($fields)
    {
        switch (true) {
            case is_array($fields):
                $fields = array_values($fields);
                break;
            case is_string($fields):
                $fields = preg_split('/\s*,\s*/', trim($fields), -1, PREG_SPLIT_NO_EMPTY);
                break;
            default:
                throw new QueryException('', QueryException::SELECT_NOT_PARSE);
                break;
        }
        return $fields ? $fields :[];
    }
533259
public function parseArguments(array $args)
    {
        $this->action = null;
        $this->arguments = array();
        $parsed = array();
        $argument = reset($args);
        while ($argument) {
            if (strpos($argument, '=') > 0) {
                $arg = explode('=', $argument);
                $argKey = ltrim($arg[0], '-');
                $argValue = trim($arg[1], '"');
                $parsed[$argKey] = $argValue;
            } else {
                $parsed[ltrim($argument, '-')] = true;
            }
            $argument = next($args);
        }
        if (!isset($parsed['action']) || empty($parsed['action'])) {
            if (isset($parsed['version']) ||  isset($parsed['V'])) {
                $this->action = 'Version';
                $this->arguments = $parsed;
                return $this->arguments;
            }
            if (isset($parsed['help']) || isset($parsed['h'])) {
                $this->action = 'Help';
                $this->arguments = $parsed;
                return $this->arguments;
            }
            throw new RequestException($this, "No valid action argument specified.");
        }
        $this->action = $parsed['action'];
        unset($parsed['action']);
        $this->arguments = $parsed;
        return $this->arguments;
    }
1154071
private function parseShortOption($arg)
    {
        $shortOptions = $this->shortOptions;

        // If our program does not accept short options
        // ignore current keyword
        if (empty($shortOptions)) {
            $this->optind++;
            return null;
        }

        // We do not accept single letter options with '=' (format -o=value)
        if (is_numeric(strpos($arg, '='))) {
            $this->optind++;
            return null;
        }

        // We must accept grouped option (eg. -cvd)
        $key = substr($arg, 1);

        if (strlen($key) > 1) {
            // We are parsing an option group
            return $this->parseShortOptionGroup($key);
        }

        // Deal with a single-char option, no option group
        if (strlen($key) == 1) {
            // Check if option is allowed
            $cpos = strpos($shortOptions, $key);

            // Invalid option, go to next
            if (false === $cpos) {
                $this->optind++;
                return null;
            }

            // Option is supported, go ahead
            $option = $key;

            // Check if option allows parameters
            if (isset($shortOptions[$cpos+1]) && $shortOptions[$cpos+1] === ':') {
                // Ok, parse parameter
                
                if ($this->optind < $this->argc -1) {
                    // Get next arg from our copy of $argv
                    $optarg = $this->argv[$this->optind + 1];

                    // If arg is not an option (should not begin with - or --)
                    if (!(substr($optarg, 0, 2) === '--') && !(substr($optarg, 0, 1) === '-')) {
                        // Option value is ok, set it and update index by 2 steps
                        $this->optarg = $optarg;
                        $this->optind += 2;
                        return $option;
                    }

                }

                // Option value missing, set it to FALSE and update index by 1 step only
                $this->optarg = false;
                $this->optind++;
                return $option;

            }

            // No parameter
            // In any case we now have a supported option
            $this->optarg = true;
            $this->optind++;
            return $option;

        }

        // Invalid option, go to next
        $this->optind++;
        return null;
    }
1266501
protected function _splitArgs($args)
    {
        $out = [];
        foreach ($args as $arg) {
            if (strpos($arg, ':') !== false) {
                list($key, $value) = explode(':', $arg);
                if (in_array($value, ['true', 'false'])) {
                    $value = $value === 'true';
                }
                $out[$key] = $value;
            } else {
                $out[] = $arg;
            }
        }

        return $out;
    }
645935
private function parseSegments($field)
    {
        $segments = explode(':', $field);

        $name = array_shift($segments);
        $argument = $segments[0];

        return compact('name', 'argument');

    }
689422
protected function processArgument(Element $arg) {
		// Value of the special types:
		if (isset($arg->type)) {
			$type = strtolower(trim($arg->type));
			
			switch ($type) {
				case 'bool':
				case 'boolean':
					return $this->processArgumentBoolean($arg);
					
				case 'service':
					return $this->processArgumentService($arg);
					
				case 'parameter':
					return $this->processArgumentParameter($arg);
					
				case 'null':
					return $this->processArgumentNull($arg);
					
				case 'array':
					return $this->processArgumentArray($arg);
			}
			
			throw new InvalidConfig('Invalid type of argument: "' . $type . '"', null, null, $arg);
		}
		
		// Scalar value: string, int, float
		$definition = new stdClass();
		
		if (isset($arg->value)) {
			$definition->type  = 'value';
			$definition->value = Std::parseValue($arg->value);
			
			return $definition;
		}
		
		$value = $arg->getValue();
		
		if (! empty($value)) {
			$definition->type  = 'value';
			$definition->value = Std::parseValue($value);
			
			return $definition;
		}
		
		throw new InvalidConfig('Invalid definition of argument', null, null, $arg);
	}
487802
public static function subTree( $args )
    {
        $parentNodeID = isset( $args[0] ) ? $args[0] : null;
        $limit = isset( $args[1] ) ? $args[1] : 25;
        $offset = isset( $args[2] ) ? $args[2] : 0;
        $sort = isset( $args[3] ) ? self::sortMap( $args[3] ) : 'published';
        $order = isset( $args[4] ) ? $args[4] : false;
        $objectNameFilter = isset( $args[5] ) ? $args[5] : '';

        if ( !$parentNodeID )
        {
            throw new ezcBaseFunctionalityNotSupportedException( 'Fetch node list', 'Parent node id is not valid' );
        }

        $node = eZContentObjectTreeNode::fetch( $parentNodeID );
        if ( !$node instanceOf eZContentObjectTreeNode )
        {
            throw new ezcBaseFunctionalityNotSupportedException( 'Fetch node list', "Parent node '$parentNodeID' is not valid" );
        }

        $ezjscoreIni = eZINI::instance( 'ezjscore.ini' );
        $hardLimit = (int)$ezjscoreIni->variable( 'ezjscServer_ezjscnode', 'HardLimit' );

        if ( $hardLimit > 0 && $limit > $hardLimit )
        {
            $limit = $hardLimit;
        }

        $params = array( 'Depth' => 1,
                         'Limit' => $limit,
                         'Offset' => $offset,
                         'SortBy' => array( array( $sort, $order ) ),
                         'DepthOperator' => 'eq',
                         'ObjectNameFilter' => $objectNameFilter,
                         'AsObject' => true );

       // fetch nodes and total node count
        $count = $node->subTreeCount( $params );
        if ( $count )
        {
            $nodeArray = $node->subTree( $params );
        }
        else
        {
            $nodeArray = array();
        }
        unset( $node );// We have on purpose not checked permission on $node itself, so it should not be used

        // generate json response from node list
        if ( $nodeArray )
        {
            $list = ezjscAjaxContent::nodeEncode( $nodeArray, array( 'formatDate' => 'shortdatetime',
                                                                     'fetchThumbPreview' => true,
                                                                     'fetchSection' => true,
                                                                     'fetchCreator' => true,
                                                                     'fetchClassIcon' => true ), 'raw' );
        }
        else
        {
            $list = array();
        }

        return array( 'parent_node_id' => $parentNodeID,
                      'count' => count( $nodeArray ),
                      'total_count' => (int)$count,
                      'list' => $list,
                      'limit' => $limit,
                      'offset' => $offset,
                      'sort' => $sort,
                      'order' => $order );
    }
1285799
public function add($arg)
    {
        if ( $arg !== null && (!$arg instanceof self || $arg->count() > 0) ) {
            // If we decide to keep Expr\Base instances, we can use this check
            if ( ! is_string($arg)) {
                $class = get_class($arg);

                if ( ! in_array($class, $this->allowedClasses)) {
                    throw new \InvalidArgumentException("Expression of type '$class' not allowed in this context.");
                }
            }

            $this->parts[] = $arg;
        }

        return $this;
    }
1142145
public static function arguments($args)
    {
        $argList = '';

        // If its a string return it
        if (is_string($args)) {
            return $args;
        }

        // If its not an array, Houston, we have a problem
        if (!is_array($args)) {
            throw new InvalidArgumentException();
        }

        // Build the argument list
        foreach ($args as $arg => $val) {
            $argList .= ' ' . $arg;
            if (!empty($val)) {
                $argList .= ' ' . $val;
            }
        }

        return trim($argList);
    }
639537
protected function parseArgument($arg)
    {
        $arg = ltrim($arg, '-');
        
        $key = $arg;
        $value = true;
        
        if (strpos($arg, '=') !== false) {
            $key = substr($arg, 0, strpos($arg, '='));
            $value = substr($arg, strpos($arg, '=') + 1);
        
            if (is_numeric($value)) {
                // Transform the value into the correct data type
                $value = $value * 1;
            }
        }
        
        return array($key, $value);
    }
191231
private function _parseArgs(array $args)
	{
		$arg = '';
		if(count($args) > 0)
		{
			foreach($args as $number => $argument)
			{
				if($number === 0)
				{
					$arg .= $argument;
				}
				else
				{
					$arg .= ', ' . $argument;
				}
			}
		}

		return $arg;
	}
139206
protected function _translateArgs($args) {
		foreach ((array)$args as $k => $arg) {
			if (is_string($arg)) {
				$args[$k] = __d($this->validationDomain, $arg);
			}
		}
		return $args;
	}
1316678
public function extractArgs($args)
	{
		foreach ($args as $k => $v) {
			if (property_exists($this, $k)) {
				$this->$k = $v;
			} else {
				throw new \InvalidArgumentException("{$k} is not a valid option.");
			}
		}
	}
1242030
protected function parseArgs(string $arg)
    {
        if ($this->_lastVariadic) {
            return $this->set($this->_lastVariadic, $arg, true);
        }

        if (!$argument = \reset($this->_arguments)) {
            return $this->set(null, $arg);
        }

        $this->setValue($argument, $arg);

        // Otherwise we will always collect same arguments again!
        if (!$argument->variadic()) {
            \array_shift($this->_arguments);
        }
    }
1254736
protected function processArgumentArray(Element $arg) {
		$definition = new stdClass();
		
		$definition->type  = 'value';
		$definition->value = [];
				
		foreach ($arg->getContent() as $element) {
			if ($element->getName() !== 'element') {
				throw new InvalidConfig('Array definition must contain only "element" elements', null, null, $arg);
			}
			
			if (isset($element->key)) {
				$definition->value[$element->key] = $this->processArgument($element);
			} else {
				$definition->value[] = $this->processArgument($element);
			}
		}
		
		return $definition;
	}