Parse failed rules.

@author Morten Rugaard <moru@nodes.dk>
@param  $failedRules
@return array
773201
protected function parseFailedRules($failedRules)
    {
        // Parsed failed rules container
        $parsedFailedRules = [];

        foreach ($failedRules as $field => $ruleAttributes) {
            foreach ($ruleAttributes as $rule => $attributes) {
                $parsedFailedRules[$field] = strtolower($field.'.'.$rule);
            }
        }

        return $parsedFailedRules;
    }
1027003
protected function parseFailedJob(array $failed)
    {
        $row = array_values(Arr::except($failed, ['payload', 'exception']));

        array_splice($row, 3, 0, $this->extractJobName($failed['payload']));

        return $row;
    }
555433
private function parse_diacritics_rules( array $diacritics_rules, array &$patterns, array &$replacements ) {

		foreach ( $diacritics_rules as $needle => $replacement ) {
			$patterns[]              = '/\b(?<!\w[' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . '])' . $needle . '\b(?![' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . ']\w)/u';
			$replacements[ $needle ] = $replacement;
		}
	}
205433
public static function getRulesIndexes(array $arrayRulesIndexes): array
    {
        assert(array_key_exists(static::RULES_ARRAY_INDEXES, $arrayRulesIndexes));
        $result = $arrayRulesIndexes[static::RULES_ARRAY_INDEXES];

        return $result;
    }
550690
public function getRules()
    {
        $rules = empty($this->rules) ? $this->rules($this->request, $this->params) : $this->rules;
        return $this->explodeRules($rules);
    }
277873
public static function parseDotRule($rule)
    {
        $result = preg_split('#(?<!\\\)\.#', $rule);
        array_walk($result, function(&$value, $key){
            if(false !== strpos($value,'\.'))
            {
                $value = str_replace('\.', '.', $value);
            }
        });
        return $result;
    }
1116687
public function mayAll($permissions, &$failed = null)
    {
        $this->mayOne($permissions, $failed);

        return $failed instanceof Collection ? $failed->isEmpty() : false;
    }
1308195
protected function getTermRules()
    {
        $rules = [];

        foreach ($this->repository as $field) {
            $rules[$field->getName()] = $field->getOption('rules');
        }

        return $rules;
    }
1000686
private function loadRules(array $ruleIds): Generator
    {
        foreach ($ruleIds as $ruleId) {
            try {
                yield $this->layoutResolverService->loadRule($ruleId);
            } catch (NotFoundException $e) {
                continue;
            }
        }
    }
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];
    }
196092
public function rules()
    {
        if ($this->parsedRules !== null) {
            return $this->parsedRules;
        }

        $rules = $this->buildRules();

        $this->callBeforeListeners('parseRules', [&$rules]);
        $rules = $this->parseRules($rules);
        $this->callAfterListeners('parseRules', [&$rules]);

        $this->parsedRules = $rules;

        return $this->parsedRules;
    }
572120
private function formatForwardRules($forwardRules)
    {
        if (isset($forwardRules)) {
            return array_map(function ($rule) {
                return $this->formatConfigurationOptions($rule);
            }, $forwardRules);
        } else {
            return [
                (new ForwardRuleEntity())->setStandardHttpRules()->toArray(),
                (new ForwardRuleEntity())->setStandardHttpsRules()->toArray(),
            ];
        }
    }
308830
protected function buildRules()
    {
        if ($this->rules) {
            return $this->rules;
        }

        if ($resource = $this->resource()) {
            $this->rules = $this->filterDetectedRules($this->detectRules($resource), $resource);
        }

        return $this->rules;
    }
517256
public function processRules($aRules)
    {
        if (empty($aRules)) {
            return null;
        }

        $aOut = [];

        //  Min/max length
        $aOut['min'] = !empty($aRules['min']) ? (int) $aRules['min'] : null;
        $aOut['max'] = !empty($aRules['max']) ? (int) $aRules['max'] : null;

        //  Expiration
        $aOut['expiresAfter'] = !empty($aRules['expires_after']) ? (int) $aRules['expires_after'] : null;

        //  Requirements
        $aOut['requirements'] = [];
        if (!empty($aRules['requirements'])) {
            $aOut['requirements']['symbol']      = in_array('symbol', $aRules['requirements']);
            $aOut['requirements']['number']      = in_array('number', $aRules['requirements']);
            $aOut['requirements']['lower_alpha'] = in_array('lower_alpha', $aRules['requirements']);
            $aOut['requirements']['upper_alpha'] = in_array('upper_alpha', $aRules['requirements']);
            $aOut['requirements']                = array_filter($aOut['requirements']);
        }

        //  Banned words
        $aOut['banned'] = [];
        if (!empty($aRules['banned'])) {
            $aRules['banned'] = trim($aRules['banned']);
            $aOut['banned']   = explode(',', $aRules['banned']);
            $aOut['banned']   = array_map('trim', $aOut['banned']);
            $aOut['banned']   = array_map('strtolower', $aOut['banned']);
            $aOut['banned']   = array_filter($aOut['banned']);
        }
        $aOut = array_filter($aOut);

        return empty($aOut) ? null : json_encode($aOut);
    }
153330
public function addRules(array $rules): array
    {
        // serialize the rules altogether

        $this->getSerializer()->clearBlocksWithStart()->clearBlocksWithEnd();

        $indexes = [];
        foreach ($rules as $name => $rule) {
            assert($rule instanceof RuleInterface);

            $ruleName = $rule->getName();
            if (empty($ruleName) === true) {
                $ruleName = $name;
            }

            $block          = $rule->setName($ruleName)->enableCapture()->toBlock();
            $indexes[$name] = $this->getSerializer()->addBlock($block);
        }

        $ruleIndexes = [
            static::RULES_ARRAY_INDEXES       => $indexes,
            static::RULES_ARRAY_START_INDEXES => $this->getSerializer()->getBlocksWithStart(),
            static::RULES_ARRAY_END_INDEXES   => $this->getSerializer()->getBlocksWithEnd(),
        ];

        $this->getSerializer()->clearBlocksWithStart()->clearBlocksWithEnd();

        // sometimes (e.g. update in relationship) an individual validation rule is needed
        // so we should have a second serialization of each rule individually

        $individualRules = [];
        foreach ($rules as $name => $rule) {
            $individualRules[$name] = $this->addRule($rule);
        }
        $ruleIndexes[static::RULES_ARRAY_SINGLE_INDEXES] = $individualRules;

        return $ruleIndexes;
    }
1024650
protected function getBindedRules(): array
    {
        $rules = $this->getValidationRules();

        if (! empty($this->validationBindings)) {
            foreach ($rules as $key => $value) {
                $rules[$key] = Str::replace($value, $this->validationBindings);
            }
        }

        return $rules;
    }
291529
protected function getValidationRules(): array
    {
        $validationRulesFromRepository = $this->repository->getModelValidationRules();

        return !empty($validationRulesFromRepository) ? $validationRulesFromRepository : $this->validationRules;
    }