Return the names of the needed properties for filtering.

@param array $rule The filter rule from which the properties shall be extracted from.

@return array

@throws \RuntimeException When an unexpected filter rule is encountered.
358585
private function extractNeededProperties($rule)
    {
        if (\in_array($rule['operation'], ['AND', 'OR'])) {
            $properties = [];
            foreach ($rule['children'] as $childRule) {
                $properties[] = $this->extractNeededProperties($childRule);
            }
            return $properties;
        }

        // Local is child property name.
        if (isset($rule['local'])) {
            return $rule['local'];
        }

        // Remote is parent property name.
        if (isset($rule['property'])) {
            return $rule['property'];
        }

        throw new \RuntimeException('Unexpected filter rule ' . \var_export($rule, true));
    }
37643
public function getFilterForRule(Rule $rule)
    {
        $filterIdentifier = $rule->getFilter();

        if (class_exists($filterIdentifier)) {
            return new $filterIdentifier;
        }

        $error = "Unable to locate filter for: $filterIdentifier defined in " . get_class($rule);
        throw new \UnexpectedValueException($error);
    }
16531
private function parseRule($rule)
    {
        $parameters = [];

        if (strpos($rule, ':') !== false) {
            list($rule, $parameter) = explode(':', $rule, 2);
            $parameters = $this->parseParameters($rule, $parameter);
        }

        if (!Variable::ruleExists($rule)) {
            throw new \InvalidArgumentException("validation: rule '$rule' not supported.");
        }

        return [$rule, $parameters];
    }
701115
protected static function parseParameters($rule, $parameter)
    {
        $rule = strtolower($rule);

        if (in_array($rule, ['regex', 'not_regex', 'notregex'], true)) {
            return [$parameter];
        }

        return str_getcsv($parameter);
    }
876945
protected function extractCustomValidationRules(array $rules)
    {
        $customRules = array_filter($rules, function ($rule) {
            return $this->isCustomRule($rule);
        });

        return $customRules;
    }
555843
private function validateRule(EventInterface $event, array $rule) {
        $acl = $event->getAccessControl();

        $allowedProperties = ['resources', 'group', 'users'];
        $unknownProperties = array_diff(array_keys($rule), $allowedProperties);

        if (!empty($unknownProperties)) {
            throw new RuntimeException('Found unknown properties in rule: [' . implode(', ', $unknownProperties) . ']', 400);
        }

        if (isset($rule['resources']) && isset($rule['group'])) {
            throw new RuntimeException('Both resources and group found in rule', 400);
        }

        if (!isset($rule['resources']) && !isset($rule['group'])) {
            throw new RuntimeException('Neither group nor resources found in rule', 400);
        }

        if (isset($rule['resources']) && !$this->isStringArray($rule['resources'])) {
            throw new RuntimeException('Illegal value in resources array. String array expected', 400);
        }

        if (isset($rule['group'])) {
            if (!is_string($rule['group'])) {
                throw new RuntimeException('Group must be specified as a string value', 400);
            }

            if (!$acl->getGroup($rule['group'])) {
                throw new RuntimeException('Group \'' . $rule['group'] . '\' does not exist', 400);
            }
        }

        if (!isset($rule['users'])) {
            throw new RuntimeException('Users not specified in rule', 400);
        }

        if ($rule['users'] !== '*' && !$this->isStringArray($rule['users'])) {
            throw new RuntimeException('Illegal value for users property. Allowed: \'*\' or array with users', 400);
        }
    }
209672
static protected function parseRule($rule)
    {
        switch (gettype($rule)) {
            case 'string':
                $type = $rule;
                $target = null;
                $types = [];
                break;
            case 'array':
                $type = isset($rule['type']) ? $rule['type'] : [];
                $target = isset($rule['target']) ? $rule['target'] : [];
                $types = isset($rule['types']) ? $rule['types'] : [];
                break;
            case 'object':
                $type = isset($rule->type) ? $rule->type : null;
                $target = isset($rule->target) ? $rule->target : null;
                $types = isset($rule->types) ? $rule->types : [];
                break;
            default:
                $type = null;
                $target = null;
                $types = [];
        }
        return compact('type', 'target', 'types');
    }
547500
public function filterRules($rules)
    {
        foreach ($this->_behaviors as $name => $foo) {
            if (($behavior = $this->getBehavior($name)) instanceof \nineinchnick\usr\components\FormModelBehavior) {
                $rules = $behavior->filterRules($rules);
            }
        }

        return $rules;
    }
574403
private function filterAllOf(AllOf $rule)
    {
        $rules = $rule->getRules();
        if (count($rules) != 1) {
            throw new ComponentException('AllOf rule must have only one Attribute rule');
        }

        return current($rules);
    }
1360292
protected function filterDetectedRules(array $rules, AppliesToResource $resource)
    {

        if (!$this->typeProvider) {
            return $rules;
        }

        $filteredRules = [];

        foreach ($rules as $key=>$rule) {

            if (!$type = $this->xType($key)) {
                continue;
            }

            if ($this->shouldRemoveRules($key, $type)) {
                continue;
            }

            if ($type->readonly) {
                $filteredRules[$key] = 'forbidden';
                continue;
            }

            $filteredRules[$key] = $rule;
        }

        return $filteredRules;
    }
788141
protected function checkRule($rule)
    {
        $this->assertTrue(is_array($rule) || is_string($rule));

        $parts = is_array($rule) ? $rule : explode('|', $rule);

        $this->assertTrue(isset($parts[0]));

        if ($this->enforceRequiredOrNullable()) {
            $this->assertTrue($parts[0] === 'required' || $parts[0] === 'nullable');
        }

        foreach ($parts as $part) {
            $this->assertInternalType('string', $part);
        }
    }
776659
private function getRuleClass($rule) {

		if(false === is_string($rule)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
		}

		if(true === isset($this -> custom[$rule])) {
			return $this -> custom[$rule];
		}

		return __NAMESPACE__ . self :: NAMESPACE_RULES . ucfirst(strtolower($rule));
	}
1046302
protected function getTitle($rule, $params = array())
    {
        $params['attribute'] = $this->field->getOption('label');

        return $this->formHelper->getTranslator()->trans('validation.' . $rule, $params);
    }
1232010
protected function parseValidationRule($rule)
	{
		$ruleArray = ['name' => '', 'parameters' => []];

		$explodedRule = explode(':', $rule);
		$ruleArray['name'] = array_shift($explodedRule);
		$ruleArray['parameters'] = explode(',', array_shift($explodedRule));

		return $ruleArray;
	}
376758
protected function getRelevantStyleRules(array $rules)
    {
        $styleRules = [];

        foreach ($rules as $rule) {
            if ($rule instanceof StyleRuleSet) {
                $styleRules[] = $rule;
            } else if ($rule instanceof MediaRule) {
                foreach ($rule->getQueries() as $mediaQuery) {
                    // Only add styles in media rules, if the media rule is valid for "all" and "screen" media types
                    // @note: http://premailer.dialect.ca/ also supports "handheld", but this is really useless
                    $type = $mediaQuery->getType();
                    if ($type === MediaQuery::TYPE_ALL || $type === MediaQuery::TYPE_SCREEN) {
                        // ...and only if there are no additional conditions (like screen width etc.)
                        // which are dynamic and therefore need to be ignored.
                        $conditionCount = count($mediaQuery->getConditions());
                        if ($conditionCount === 0) {
                            foreach ($this->getRelevantStyleRules($rule->getRules()) as $styleRule) {
                                $styleRules[] = $styleRule;
                            }
                            break;
                        }
                    }
                }
            }
        }

        return $styleRules;
    }
291188
protected function compileReplace(array $rule)
    {
        return array(
            'regexp' => '([' .
                preg_quote($this->compileCharacter($rule['data']['srcStart'])) . '-' .
                preg_quote($this->compileCharacter($rule['data']['srcEnd'])) .
                '])us',
            'callback' => $this->compileTargetCharacter($rule['data']['dest']),
        );
    }
1211122
public function findByKey($rule){

            $r = [];

            foreach($this->data as $k=>$v){
                if($rule($k)){
                    $r[] = $this->{$k};
                }
            }

            return $r;

        }