/*!
\private
\static
\return array of transformation rules on success, false otherwise
764216
function loadSchemaTransformationRules( $schemaType )
    {
        $ini = eZINI::instance( 'dbschema.ini' );

        if ( !$ini )
        {
            eZDebug::writeError( "Error loading $schemaType schema transformation rules" );
            return false;
        }

        $transformationRules = array();

        if ( $ini->hasVariable( $schemaType, 'ColumnNameTranslation' ) )
            $transformationRules['column-name'] = $ini->variable( $schemaType, 'ColumnNameTranslation' );

        if ( $ini->hasVariable( $schemaType, 'ColumnTypeTranslation' ) )
        {
            $transformationRules['column-type'] = $ini->variable( $schemaType, 'ColumnTypeTranslation' );

            // substitute values like "type1;type2" with an appropriate arrays
            if ( is_array( $transformationRules['column-type'] ) )
            {
                foreach ( $transformationRules['column-type'] as $key => $val )
                {
                    $types = explode( ';', $val );
                    $transformationRules['column-type'][$key] = $types;
                }
            }
        }

        $indexTranslations = array();
        if ( $ini->hasVariable( $schemaType, 'IndexTranslation' ) )
        {
            $translations = $ini->variable( $schemaType, 'IndexTranslation' );
            foreach ( $translations as $combinedName => $translation )
            {
                list( $tableName, $indexName ) = explode( '.', $combinedName );
                $indexTranslations[$tableName][$indexName] = array();
                $fields = explode( ';', $translation );
                foreach ( $fields as $field )
                {
                    $entries = explode( '.', $field );
                    $fieldName = $entries[0];
                    $fieldData = array();
                    for ( $i = 1; $i < count( $entries ); ++$i )
                    {
                        list( $metaName, $metaValue ) = explode( '/', $entries[$i], 2 );
                        if ( is_numeric( $metaValue ) )
                            $metaValue = (int)$metaValue;
                        $fieldData[$metaName] = $metaValue;
                    }
                    $indexTranslations[$tableName][$indexName][$fieldName] = $fieldData;
                }
            }
        }
        $transformationRules['index-field'] = $indexTranslations;

        $tableTranslations = array();
        if ( $ini->hasVariable( $schemaType, 'TableOptionTranslation' ) )
        {
            $translations = $ini->variable( $schemaType, 'TableOptionTranslation' );
            foreach ( $translations as $tableName => $optionTexts )
            {
                $tableTranslations[$tableName] = array();
                $options = explode( ';', $optionTexts );
                $optionData = array();
                foreach ( $options as $option )
                {
                    list( $metaName, $metaValue ) = explode( '/', $option, 2 );
                    if ( is_numeric( $metaValue ) )
                        $metaValue = (int)$metaValue;
                    $optionData[$metaName] = $metaValue;
                    $tableTranslations[$tableName] = $optionData;
                }
            }
        }
        $transformationRules['table-option'] = $tableTranslations;

        if ( $ini->hasVariable( $schemaType, 'IndexNameTranslation' ) )
        {
            $tmpIdxNameTranslations = $ini->variable( $schemaType, 'IndexNameTranslation' );

            if ( is_array( $tmpIdxNameTranslations ) )
            {
                foreach ( $tmpIdxNameTranslations as $key => $val )
                {
                    list( $tableName, $genericIdxName ) = explode( '.', $key );
                    $localIdxName = $val;
                    if ( !$tableName || !$genericIdxName || !$localIdxName )
                    {
                        eZDebug::writeWarning( "Malformed index name translation rule: $key => $val" );
                        continue;
                    }
                    $transformationRules['index-name'][] = array( $tableName, $genericIdxName, $localIdxName );

                }
            }
            unset( $tmpIdxNameTranslations );
        }

        if ( $ini->hasVariable( $schemaType, 'ColumnOptionTranslations' ) )
        {
            $transformationRules['column-option'] = array();
            foreach( $ini->variable( $schemaType, 'ColumnOptionTranslations' ) as $key => $val )
            {
                list( $tableName, $colName ) = explode( '.', $key );
                $colOptOverride = $val;
                if ( !$tableName || !$colName || !$colOptOverride )
                {
                    eZDebug::writeWarning( "Malformed column option translation rule: $key => $val" );
                    continue;
                }
                $transformationRules['column-option'][] = array( $tableName, $colName, $colOptOverride );
            }
        }

        // prevent PHP warnings when cycling through the rules
        foreach ( array( 'column-name', 'column-type', 'column-option', 'index-name' ) as $rulesType )
        {
            if( !isset( $transformationRules[$rulesType] ) )
                $transformationRules[$rulesType] = array();
        }

        return $transformationRules;
    }
413580
protected function getBoundRules()
    {
        if ($this->bypass === true) {
            return [];
        }

        $rules = $this->getRules();

        foreach ($rules as $key => $value) {
            if ($binding = array_get($this->bindings, $key)) {
                $rules[$key] = str_replace('{'.$key.'}', $binding, $value);
            }
        }

        return $rules;
    }
265622
protected function _getRules() {
        $relation = $this->getRelation();
        $localModel = $relation->getLocalModel();

        $hasNameConflict = $relation->name === $localModel->id;
        if ($hasNameConflict) {
            return array($relation->name . '1', $relation->name . '2');
        }

        $modelIds = $this->_getModelIdsAlphabetically();

        $rules = array($relation->name, $this->_getSecondRule());
        $rules = $this->_sortRulesEgocentrically($rules);

        return $rules;
    }
953352
function validate() {
        $rules = [];
        foreach ($this->rules as $field => $_rules) {
            $this->rules[$field] = array_values($_rules);
        }

        $replacers = [];
        $id        = (int)Arr::get($this->data, $this->field_id);

        foreach ($this->rules as $field => $_rules) {
            foreach ($_rules as $rule) {
                if (is_string($rule)) {
                    $rules[$field][]           = str_replace('{id}', $id, $rule);
                    $replacer_name             = explode(":", $rule);
                    $replacer_rule             = array_shift($replacer_name);
                    $replacers[$replacer_rule] = [];
                }
                else {
                    $rules[$field][] = $rule;
                }

            }
        }
        if (count($replacers)) {
            /*foreach ($replacers as $rule => $vb) {
//                dd($replacers);
                \Validator::replacer(
                    $rule,
                    function ($message, $attribute, $rule, $parameters) {
                        $fields    = array_keys($this->data);
                        $replacers = array_map(
                            function ($value) {
                                return ':value=' . $value;
                            },
                            $fields
                        );
                        $replacers = array_merge(
                            $replacers,
                            array_map(
                                function ($value) {
                                    return ':label=' . $value;
                                },
                                $fields
                            )
                        );
                        return str_replace($replacers, $this->data + $this->labels, $message);
                    }
                );
            }*/
        }
        //        dd($this->messages);
        //        dd($this->labels);
        //        dump($this->labels);
        $this->validator = \Validator::make($this->data, $rules, $this->messages, $this->labels);
        foreach ($this->data as $k => $v) {
            $values['value__' . $k] = $v;
        }
        $this->validator->setValueNames($values);
        //        dd($this->validator);

        //        $this->validator->addReplacer()
        return !$this->validator->fails();
    }
127112
public function rules() : array
    {
        $referral = mb_strtolower($this->request->get('referral') ?? 'profile');

        $resolver = 'rulesFor' . ucfirst($referral);

        return $this->$resolver();
    }
228861
function get_rules( $nt ){
		$rules = array();
		if( isset($this->ntindex[$nt]) ){
			foreach( $this->ntindex[$nt] as $i ){
				$rules[$i] = $this->rules[$i]; 
			}
		} 
		return $rules;
	}
412037
public function transform($params, $rules)
    {
        if (!is_array($params)) {
            throw new InvalidArgumentException('Please use array params when call transform.');
        }
        if (!is_array($rules)) {
            throw new InvalidArgumentException('Please use array rules when call transform.');
        }
        foreach ($params as $key => $param) {
            if (isset($rules[$key])) {
                $formatted = call_user_func([$rules[$key], 'format'], $param);
                $params[$key] = $formatted;
            }
        }
        return $params;
    }
531361
public function getRule(){
        $returnValue = (string) '';

        foreach($this->components as $irp){
            $returnValue .= $irp->getRule();
        }
        foreach($this->getCompositionRules() as $rule){
            $returnValue .= $rule->getRule();
        }

        return (string) $returnValue;
    }
468517
public function getRule()
    {
        $returnValue = (string) '';

        
    // Get subExpressions
        $subExpressionsRules = array();
        foreach ($this->subExpressions as $subExpression){
            $subExpressionsRules[] = $subExpression->getRule();
        }
        $subExpressionsJSON = implode(',', $subExpressionsRules);

        // Format options
        $optionsJSON = count($this->attributes) ? '"'.addslashes(json_encode($this->attributes)).'"' : 'null';
        
        // Format rule function of the expression operator
        switch ($this->name) {
            case 'correct':
                $returnValue = 'getCorrect("'.$this->attributes['identifier'].'")';
                break;
            case 'mapResponse':
                $identifier = $this->attributes['identifier'];
                $returnValue = 'mapResponse('
                    . $optionsJSON
                    .', getMap("'.$identifier.'"), getResponse("'.$identifier.'"))';
                break;
            // Multiple is a Creation of List from parameters
            case 'multiple':
                $returnValue = 'createVariable("{\"type\":\"list\"}", '.$subExpressionsJSON.')';
                break;
            // Null is a Creation of empty BaseTypeVariable
            case 'null':
                $returnValue = 'createVariable(null, null)';
                break;
            // Ordered is a Creation of Tuple from parameters
            case 'ordered':
                $returnValue = 'createVariable("{\"type\":\"tuple\"}", '.$subExpressionsJSON.')';
                break;
            case 'outcome':
                $returnValue = 'getOutcome("'.$this->attributes['identifier'].'")';
                break;
            case 'setOutcomeValue':
                //@todo remove this
                throw new common_Exception('setOutcomeValue is not a valid expression');
                break;
            case 'variable':
                $returnValue = 'getVariable("'.$this->attributes['identifier'].'")';
                break;
            
            default:                 
                $returnValue = 
                    $this->name.'('
                        . $optionsJSON
                        . ($subExpressionsJSON!="" ? ', '.$subExpressionsJSON : '')
                    .')';
        }
        

        return (string) $returnValue;
    }
727838
public function list_rules()
    {
        $result = array();
        $i      = 1;

        foreach ($this->script as $idx => $filter) {
            if (empty($filter['actions'])) {
                continue;
            }
            $fname = $filter['name'] ?: "#$i";
            $result[] = array(
                'id'    => $idx,
                'name'  => $fname,
                'class' => $filter['disabled'] ? 'disabled' : '',
            );
            $i++;
        }

        return $result;
    }
719850
public function getRules()
    {
        return array(
            // degree
            'd' => array(
                'format_positive' => '%v%s',
                'format_negative' => '-%v%s',
                'symbol'          => '°',
            ),

            // radian
            'r' => array(
                'symbol' => 'pi',
                'rate'   => function ($value, $ruleTo) {
                    if ($ruleTo === 'd') {
                        return $value * 180;
                    }
                    return $value / 180;
                },
            ),

            // grads
            'g' => array(
                'symbol' => 'Grad',
                'rate'   => function ($value, $ruleTo) {
                    if ($ruleTo === 'd') {
                        return $value * 0.9;
                    }
                    return $value / 0.9;
                },
            ),

            // turn (loop)
            't' => array(
                'symbol' => 'Turn',
                'rate'   => 360,
            ),
        );
    }
544307
public function createRules(array $data): array
    {
        return array_map(function ($data) {
            if ($data instanceof Rule) {
                return $data;
            }

            return Rule::createFromData((array) $data);
        }, $data);
    }
479738
private function _getTransforms(): array
    {
        if (!$this->availableTransforms) {
            return [];
        }

        $allTransforms = Craft::$app->getAssetTransforms()->getAllTransforms();
        $transformList = [];

        foreach ($allTransforms as $transform) {
            if (!is_array($this->availableTransforms) || in_array($transform->uid, $this->availableTransforms, false)) {
                $transformList[] = [
                    'handle' => Html::encode($transform->handle),
                    'name' => Html::encode($transform->name)
                ];
            }
        }

        return $transformList;
    }
542401
public function getRules($rules): \Generator
    {
        foreach ($this->parser->split($rules) as $id => $rule) {
            if (empty($id) || $rule instanceof \Closure) {
                yield new CallableRule($rule);
                continue;
            }

            // fetch from cache
            if (isset($this->rules[$id])) {
                yield $this->rules[$id];
                continue;
            }

            $function = $this->parser->parseCheck($rule);
            $conditions = $this->parser->parseConditions($rule);

            $check = $this->makeRule(
                $this->config->mapFunction($function),
                $rule
            );

            yield $this->rules[$id] = $check->withConditions($this->makeConditions($conditions));
        }
    }
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;
    }
787460
public function getRules(bool $inherited = true): array {
        $ret = array();
        foreach ($this->resRules as $i) {
            $ret[] = $i->getData();
        }
        if ($inherited) {
            foreach ($this->extRules as $i) {
                $ret[] = $i->getData();
            }
        }
        return $ret;
    }
268630
public function getRules()
    {
        if (!$this->rules) {
            return 'return [];';
        }

        $parser = new SchemaParser($this->rules);

        $results = 'return ['.PHP_EOL;

        foreach ($parser->toArray() as $field => $rules) {
            $results .= $this->createRules($field, $rules);
        }

        $results .= "\t\t];";

        return $results;
    }