格式化规则
@param $rule
@param null $keys
@return array
774126
protected function converterRules($rule, $keys = null) {
        if (is_integer($keys) && is_array($rule)) {
            $keys = array_shift($rule);
        }
        $rules = $this->converterRule($rule);
        $rules['keys'] = $keys;
        return $rules;
    }
252092
public function getRulesFor($key)
    {
        if (!isset($this->_rules[$key]))
            return null;

        if (is_string($this->_rules[$key]))
            return explode('|', $this->_rules[$key]);

        return $this->_rules[$key];
    }
398352
protected function explodeRules($rules)
    {
        foreach ($rules as $key => $rule) {
            if (Str::contains($key, '*')) {
                $rules = $this->explodeWildcardRules($rules, $key, [$rule]);

                unset($rules[$key]);
            } else {
                $rules[$key] = $this->explodeExplicitRule($rule);
            }
        }

        return $rules;
    }
213378
public function parse($files, $rules, $t)
    {
        self::$counts['f'] += count($files);
        self::$time['f'] += $t;
        $this->statistics();

        //文件
        $file_details = [];
        foreach ($files as $file) {
            $file_details[] = $file;
        }

        $this->Debug->append('文件明细', $file_details);

        //规则
        $rule_details = [];
        foreach ($rules as $method => $v) {
            $totalS = count($v['S']);
            $totalD = count($v['D']);
            self::$totalRules += $totalS + $totalD;
            $rule_details[] = "$method; <font style='color:#646464'>(static: $totalS, dynamic: $totalD)</font>";
        }
        $this->Debug->append('规则明细', $rule_details);

    }
918082
private function sortRules(&$rules)
    {
        sort($rules);
        usort($rules, function ($a, $b) {
            return strlen($a) - strlen($b);
        });
    }
1004597
public function rules($key = null, $operation = null)
    {
        $ruleName = $operation ? "{$operation}Rules" : 'defaultRules';

        $ruleName = method_exists($this, $ruleName) ? $ruleName : 'defaultRules';

        $rules = $this->{$ruleName}();

        if (is_null($key)) {
            return $this->rules;
        }

        return is_array($key) ? array_only($this->rules, $key) : $this->rules[$key];
    }
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;
    }
131741
protected function buildRules($rules)
    {
        if (is_string($rules)) {
            $rules = explode('|', $rules);
        } elseif (is_object($rules)) {
            $rules = [$rules];
        }

        $built = [];

        foreach ((array) $rules as $rule) {
            if (is_string($rule) && strpos($rule, ':') !== false) {
                $args = explode(':', $rule);
                $rule = array_shift($args);

                $built[] = [$rule, $args];
            } else {
                $built[] = [$rule];
            }
        }

        return $built;
    }
995240
public function find( $primaryKeys )
    {
        if ( is_array( $primaryKeys ) )
        {
            $primaryKeys = reset( $primaryKeys );
        }

        $rootId = ( (int) $primaryKeys ) ?: null;

        return $this->createStructure( array(
            'rootId'    => $rootId,
            'extra'     => $this->getExtraMapper()
                                ->findByRoot( $rootId ),
            'rules'     => $this->getRuleMapper()
                                ->findAllByRoot(
                                    $rootId,
                                    $this->getRuleOrder()
                                ),
        ) );
    }
376900
protected function _validateData($rule, $key, $data)
    {
        if (
            (is_callable($rule) && call_user_func_array($rule, [$key, $data, $this]))
            || @preg_match($rule, $data)
        ) {
            return true;
        }

        if ($rule instanceof Closure) {
            $reflection = new ReflectionFunction($rule);
            $rule       = $reflection->__toString();
        }

        $this->_errorsList[] = [
            'message'   => 'validation_mismatch',
            'key'       => $key,
            'data'      => $data,
            'rule'      => $rule,
        ];
        $this->_hasErrors = true;

        return false;
    }
1139052
public function mergeRulesets($keys)
    {
        $keys = is_array($keys) ? $keys : func_get_args();
        $rulesets = [];
        foreach ($keys as $key) {
            $rulesets[] = (array) $this->getRuleset($key, false);
        }

        return array_filter(call_user_func_array('array_merge', $rulesets));
    }
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;
    }
580502
public function loadRuleTargetsData(Rule $rule): array
    {
        $query = $this->getTargetSelectQuery();
        $query->where(
            $query->expr()->eq('rule_id', ':rule_id')
        )
        ->setParameter('rule_id', $rule->id, Type::INTEGER)
        ->orderBy('id', 'ASC');

        $this->applyStatusCondition($query, $rule->status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
1304504
public function findByKeys(array $keys)
    {
        $result = [];
        /** @var Cursor $list */
        $list = $this->collection->find(['_id' => ['$in' => $keys]]);

        foreach ($list as $document) {
            $result[] = $this->hydrateEntity($document);
        }

        return $result;
    }
778809
public function addRules($rules)
    {
        foreach ($rules as $rule) {
            $this->addrule($rule[0], $rule[1], $rule[2], isset($rule[3])?$rule[3]:null);
        }
    }
1167171
protected function getValidationRulesFromElements(array $rules = [])
    {
        $this->getElements()->onlyActive()->each(function ($element) use (&$rules) {
            $element = $this->getElementContainer($element);

            if ($element instanceof Validable) {
                $rules += $element->getValidationRules();
            }
        });

        return $rules;
    }
1037055
public final function removeRule($field, $rule = null) {
		if ($rule == null) {
			unset($this->rules[ $field ]);
		} else {
			$idx = $this->ruleKeys[ $field ][ $rule ];
			unset($this->rules[ $field ][ $idx ]);
		}
	}