Parse RULE string

@param string $parse
@param array $properties
@return RuleCollection
184959
public static function parse( string $parse, array $properties = [] ): RuleCollection
	{
		$clt = new RuleCollection();

		if( preg_match('/^(https?):\/\/(.+?)(\/$)$/', $parse, $m) )
		{
			$parse = $m[3];
			$clt[] = self::getRuleHost($m[2], $m[1]);
		}
		else if( preg_match('/^\/\/(.+?)(\/$)$/', $parse, $m) )
		{
			$parse = $m[2];
			$clt[] = self::getRuleHost($m[1]);
		}

		$parse  = ltrim($parse, "/");
		$end_of = strrpos($parse, "/");
		$close  = $end_of !== false && $end_of === strlen($parse) - 1;
		$get    = '';
		$names  = [];

		if($close)
		{
			$parse = rtrim($parse, "/");
		}

		$parse = explode("/", $parse);
		$cnt = count($parse);

		for($i = 0; $i < $cnt; $i++)
		{
			$item = trim($parse[$i]);
			$last = $i + 1 === $cnt;

			if( $item[0] === "{" )
			{
				$end_of = strpos($item, "}");
				if( $end_of === false )
				{
					throw new \InvalidArgumentException("Parser error, invalid segment value '{$item}'");
				}

				$rule = self::getRuleSegment(substr($item, 1, $end_of - 2), $properties);
				if( in_array($rule->getName(), $names, true) )
				{
					throw new \InvalidArgumentException("Duplicate data name '" . $rule->getName() . "'");
				}
				else
				{
					$names[] = $rule->getName();
				}

				$clt[] = $rule;
				$end = $end_of + 1;
				$len = strlen($item);

				if( $end > $len )
				{
					// start GET queries
					if( $last && $item[$end] === "?" && $end + 1 < $len )
					{
						$get = substr($item, $end);
						$close = false;
					}
					else
					{
						throw new \InvalidArgumentException("Parser error, invalid segment value '{$item}'");
					}
				}
			}

			// start GET queries
			else if( $item[0] === "?" )
			{
				if( $last && strlen($item) > 1 )
				{
					if( $i > 0 )
					{
						$close = true;
					}
					$get = substr($item, 1);
				}
				else
				{
					throw new \InvalidArgumentException("Parser error, invalid segment value '{$item}'");
				}

				break;
			}

			// static ...
			else
			{
				$clt[] = new RuleStatic($item);
			}
		}

		if( ! $close )
		{
			$last = $clt->last();
			if( $last instanceof RuleStatic || $last instanceof RuleSegment )
			{
				$last->setOpen();
			}
		}

		if( strlen($get) )
		{
			if( strpos($get, '&amp;') !== false )
			{
				$all = explode("&amp;", $get);
			}
			else
			{
				$all = explode("&", $get);
			}

			$queries = [];

			foreach( $all as $item )
			{
				$item = trim($item);
				if( !strlen($item) )
				{
					throw new \InvalidArgumentException("Parser error, query value is empty");
				}

				if( strpos($item, '{') === false )
				{
					$m = [
						1 => $item,
						2 => $item
					];
				}
				else if( ! preg_match('/^(.+?)=\{(.+)?\}$/', $item, $m) )
				{
					throw new \InvalidArgumentException("Parser error, invalid query value '{$item}'");
				}

				$rule = self::getRuleGet($m[1], $m[2], $properties);
				if( in_array($rule->getName(), $names, true) )
				{
					throw new \InvalidArgumentException("Duplicate data name '" . $rule->getName() . "'");
				}
				else
				{
					$names[] = $rule->getName();
				}

				if( in_array($rule->getQueryName(), $queries, true) )
				{
					throw new \InvalidArgumentException("Duplicate query name '" . $rule->getName() . "'");
				}
				else
				{
					$queries[] = $rule->getName();
				}

				$clt[] = $rule;
			}
		}

		return $clt;
	}
412794
private function parse($locale)
    {
        $parts = explode('_', $locale);

        $localization = new Localization();
        $localization->setLanguage($parts[0]);
        if (count($parts) > 1) {
            $localization->setCountry($parts[1]);
        }

        return $localization;
    }
297835
public Parse parse(Parse tokens) {
    Parse p = parse(tokens,1)[0];
    setParents(p);
    return p;
  }
701959
public function Field($properties = array())
    {
        if ($this->isReadonly()) {
            $nullableCheckbox = new CheckboxField_Readonly($this->getIsNullId());
        } else {
            $nullableCheckbox = new CheckboxField($this->getIsNullId());
        }

        $nullableCheckbox->setValue(is_null($this->dataValue()));

        return sprintf(
            '%s %s&nbsp;<span>%s</span>',
            $this->valueField->Field(),
            $nullableCheckbox->Field(),
            $this->getIsNullLabel()
        );
    }
720308
public function setValidationProperty(array $properties)
    {
        if (Helpers::isKeyExists($properties, 'validation')) {
            $this->validationRules = is_array($properties['validation']) ? $properties['validation'] : Helpers::removeEmptyItems(explode('|', $properties['validation']));
        }

        if (Helpers::isNewerThanOrEqualTo('5.2') && $this->isNullable() && !in_array('nullable', $this->validationRules)) {
            $this->validationRules[] = 'nullable';
        }

        if ($this->isBoolean() && !in_array('boolean', $this->validationRules)) {
            $this->validationRules[] = 'boolean';
        }

        if ($this->isFile() && !in_array('file', $this->validationRules)) {
            $this->validationRules[] = 'file';
        }
        if ($this->isMultipleAnswers() && !in_array('array', $this->validationRules)) {
            $this->validationRules[] = 'array';
        }

        if (in_array($this->getEloquentDataMethod(), ['char', 'string']) && in_array($this->htmlType, ['text', 'textarea'])) {
            if (!in_array('string', $this->validationRules)) {
                $this->validationRules[] = 'string';
            }

            if (!Helpers::inArraySearch($this->validationRules, 'min')) {
                $this->validationRules[] = sprintf('min:%s', $this->getMinLength());
            }

            if (!Helpers::inArraySearch($this->validationRules, 'max') && !is_null($this->getMaxLength())) {
                $this->validationRules[] = sprintf('max:%s', $this->getMaxLength());
            }
        }

        $params = [];

        if (Helpers::isKeyExists($properties, 'data-type-params')) {
            $params = $this->getDataTypeParams((array) $properties['data-type-params']);
        }

        if ($this->htmlType == 'number' || (in_array($this->getEloquentDataMethod(), ['decimal', 'double', 'float'])
            && isset($params[0]) && ($length = intval($params[0])) > 0
            && isset($params[1]) && ($decimal = intval($params[1])) > 0)) {
            if (!in_array('numeric', $this->validationRules)) {
                $this->validationRules[] = 'numeric';
            }

            if (!Helpers::inArraySearch($this->validationRules, 'min') && !is_null($minValue = $this->getMinValue())) {
                $this->validationRules[] = sprintf('min:%s', $minValue);
            }

            if (!Helpers::inArraySearch($this->validationRules, 'max') && !is_null($maxValue = $this->getMaxValue())) {
                $this->validationRules[] = sprintf('max:%s', $maxValue);
            }
        }

        return $this;
    }
1067198
public function addFilter(ConditionParser $parser, string $validationRules = null)
    {
        $this->parsers[] = $parser;
        if ($validationRules !== null) {
            $rules                           = (is_object($parser->getValidationRule())) ?
                [$validationRules, $parser->getValidationRule()] : $validationRules . '|' . $parser->getValidationRule();
            $this->rules[$parser->getName()] = $rules;
        } else {
            if (!empty($parser->getValidationRule())) {
                $this->rules[$parser->getName()] = [$parser->getValidationRule()];
            }
        }
        return $this;
    }
802585
public Map<String, List<? extends SipApplicationRouterInfo>> parse(Properties properties) throws ParseException {
        this.properties = properties;
        return parse();
    }
838110
protected function parseProperties( & $properties )
    {
        if ( empty( $properties ) )
        {
            return array();
        }

        $result = array();
        foreach ( json_decode( $properties, true ) as $property )
        {
            $name = (string) $property['name'];

            $result[$name] = array(
                'name'      => $name,
                'value'     => $property['value'],
                'priority'  => $property['priority'],
            );
        }

        return $result;
    }
75478
protected function parseRuleString($ruleString)
    {
        if (is_string($ruleString)) {
            // Parse for @charset rule
            if (preg_match('/^@charset\s+(["\'])([-a-zA-Z0-9_]+)\g{1}/i', rtrim($ruleString), $matches)) {
                $this->setValue($matches[2]);
            } else {
                throw new \InvalidArgumentException("Invalid format for @charset rule.");
            }
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($ruleString) . "' for argument 'ruleString' given. String expected."
            );
        }
    }
861785
protected function parseProperties() {
		if ($this->isEntity()) {
			//property mapping
			$this->propertyMap = [];
			//associations
			$this->foreignkeys = $this->references = [];
			//read-only properties
			$this->readOnlyProperties = [];
			//duplicate checks
			$this->duplicateChecks = [];
		}
		
		$properties = $this->reflectionClass->getProperties();
		
		foreach ($properties as $reflectionProperty) {
			$propertyName = $reflectionProperty->getName();
			$propertyAnnotations = Omocha::getAnnotations($reflectionProperty);
			
			if (($this->isEntity() || $this->isResultMap()) && $this->isDynamicAttribute($propertyAnnotations))
				$this->parseDynamicAttribute($propertyName, $reflectionProperty, $propertyAnnotations);
			elseif ($this->isEntity() && $this->isAssociation($propertyAnnotations))
				$this->parseAssociation($propertyName, $reflectionProperty, $propertyAnnotations);
			else {
				$property = new ClassProperty($propertyName, $reflectionProperty, $propertyAnnotations);
				
				if ($this->isEntity()) {
					if ($property->isPrimaryKey())
						$this->primaryKey = $propertyName;
					elseif ($property->checksForDuplicates())
						$this->duplicateChecks[] = $propertyName;
						
					$this->propertyMap[$propertyName] = $property->getColumn();
					
					if ($property->isReadOnly())
						$this->readOnlyProperties[] = $propertyName;
				}
				
				$this->properties[$propertyName] = $property;
			}
		}
	}
1302820
public function parse(){
		if(!preg_match('/(.+?)\s*{/is', $this->parser->getText(), $matches)) throw new \Exception("Invalid selector at '".substr($this->getText(), 0, 20)."'");
		$this->parser->move(strlen($matches[0]));
		
		$selectors = array();
		foreach(explode(',', $matches[1]) as $selector){
			$selectors[] = self::parseSelector(trim($selector));
		}
		
		$ruleSet = new \csslib\RuleSet($selectors);
		$this->parent->add($ruleSet);
		
		$this->setPropertySet($ruleSet);
		parent::parse();
	}
13477
public function parseLiteral($valueNode, ?array $variables = null): Carbon
    {
        if (! $valueNode instanceof StringValueNode) {
            throw new Error(
                "Query error: Can only parse strings, got {$valueNode->kind}",
                [$valueNode]
            );
        }

        return $this->tryParsingDate($valueNode->value, Error::class);
    }
1183270
public function from($collection, $properties = null) {
		$this->_collection = $collection;
		
		if (is_string($properties) || is_array($properties)) {
			$this->_properties = (array) $properties;
		}
		
		return $this;
	}
1224066
protected function parse_properties($lines) {
        $result= NULL;
        foreach($lines as $i=>$line) {
            if(empty($line) || !isset($line) || strpos($line,"#") === 0){
                continue;
            }
            $key = substr($line,0,strpos($line,'='));
            $value = substr($line,strpos($line,'=') + 1, strlen($line));
            $result[$key] = $value;
        }
        return $result;
    }
308594
private function visitRulesetPaths($rulesetNode){

		$paths = array();
		foreach($rulesetNode->paths as $p){
			if( $p[0]->elements[0]->combinator === ' ' ){
				$p[0]->elements[0]->combinator = '';
			}

			foreach($p as $pi){
				if( $pi->getIsReferenced() && $pi->getIsOutput() ){
					$paths[] = $p;
					break;
				}
			}
		}

		return $paths;
	}
1178795
protected function parse_string_rules( $rules ) {
		$split_rules = explode( '|', $rules );
		$parse_rules = [];

		foreach ( $split_rules as $rule ) {
			$parameters = [];

			// Format rule and parameters follows {rule}:{parameters}.
			if ( strpos( $rule, ':' ) !== false ) {
				list( $rule, $parameter ) = explode( ':', $rule, 2 );

				$parameter = false !== strpos( $parameter, ',' )
					? str_getcsv( $parameter )
					: [ $parameter ];

				$parameters = $this->wrap_parameters( $rule, $parameter );
			}

			$parse_rules[] = [ $this->normalize( $rule ), $parameters ];
		}

		return $parse_rules;
	}
1090969
protected function normalizeValidationRuleSourceData($rules)
    {
        if (false === $rules || empty($rules)) {
            return [];
        }

        if (is_string($rules)) {
            $rules = (array) $rules;
        }

        if ( ! is_array($rules)) {
            throw new UnexpectedValueException("Form field base validation rules not array or arrayable");
        }

        // Loop through and cast anything not already a data object
        $rules = array_map([$this, 'normalizeRulesProperty'], $rules, array_keys($rules));

        // Make sure there is only one entry per rule key
        $rules = $this->getRuleMerger()->collapseRulesForDuplicateKeys($rules);

        // Key the array by the rule key
        return array_combine(
            array_map(function (ValidationRuleDataInterface $rule) {
                return $rule->key() ?: '';
            }, $rules),
            $rules
        );
    }