Generates content rules
@return array
480403
private function generateContentRules()
	{
		$rules = array();
		$criteria = Content::model()->getBaseCriteria();
		$content = Content::model()->findAll($criteria);
		foreach ($content as $el)
		{
			if ($el->slug == NULL)
				continue;

			$pageRule = $el->slug.'/<page:\d+>';
			$rule = $el->slug;


			$pageRule = $el->slug . '/<page:\d+>';
			$rule = $el->slug;

			$rules[$pageRule] = "content/index/id/{$el->id}/vid/{$el->vid}";
			$rules[$rule] = "content/index/id/{$el->id}/vid/{$el->vid}";
		}

		return $rules;
	}
1255122
public function getRules()
    {
        $rules = [
            static::FIRST_NAME => "required|max:100",
            static::LAST_NAME => "required|max:100",
            static::EMAIL => "required|max:100|email|unique:users,email,{$this->id},id",
        ];
        if (!$this->id) {
            $rules[static::PWD_FIELD] = 'required|min:' . config('app.model.user.password.min', 6)
                . '|max:' . config('app.model.user.password.max', 20);
        }
        return $rules;
    }
907432
public function rules()
    {
        $rules = [];

        $multiLangFlag = Session::get('multi_language_enabled');
        $defaultLang = Session::get('default_language');
        $requestLanguageId = $this->request->get('language_id', $defaultLang->id);

        if ($requestLanguageId === $defaultLang) {
            $rules['name'] = 'required|max:255';
            $rules['sort_order'] = 'required';
            $rules['is_visible_frontend'] = 'required';
            $rules['use_for_all_products'] = 'required';
            $rules['data_type'] = 'required';
            $rules['field_type'] = 'required';
            if ($this->getMethod() == 'POST') {
                $rules['identifier'] = 'required|max:255|alpha_dash|unique:properties';
            }
            if ($this->getMethod() == 'PUT') {
                $rules['identifier'] = 'required|max:255|alpha_dash';
            }
        } else {
            $rules['name'] = 'required|max:255';
            $rules['identifier'] = 'required|max:255|alpha_dash';
        }

        return $rules;
    }
591308
protected function generateFilters()
    {

        $filters = $this->request->query->get('filters');

        $filters = json_decode($filters, true);
        $rules = $filters['rules'];
        $groupOp = $filters['groupOp']; //AND or OR

        if ($rules) {
            foreach ($rules as $rule) {
                foreach ($this->columns as $column) {
                    if ($column->getFieldIndex() == $rule['field']) {
                        $filterMapper = FilterMapperFactory::getFilterMapper($this, $column);
                        $filterMapper->execute($rule, $groupOp);
                    }
                }
            }
        }
    }
688294
protected function getRules()
    {
        $result = [];
        $relationNames = [];
        foreach ($this->relations as $key => $value) {
            $relationNames[] = is_array($value) ? $key : $value;
        }

        foreach ($this->owner->rules() as $key => $rule) {
            $attributes = is_array($rule[0]) ? $rule[0] : [$rule[0]];
            if (!$relations = array_intersect($relationNames, $attributes)) {
                continue;
            }
            $rule[0] = $relations;
            $result[$key] = $rule;
        }
        return $result;
    }
1113034
public function generateRules($attributes)
    {
        $rules = [];
        $safeAttributes = [];
        foreach ($attributes as $attribute) {
            if ($attribute == '_id') {
                continue;
            }
            $safeAttributes[] = $attribute;
        }
        if (!empty($safeAttributes)) {
            $rules[] = "[['" . implode("', '", $safeAttributes) . "'], 'safe']";
        }
        return $rules;
    }
697798
public function rules()
    {
        $admin_id = request('admin.id');
        $rules    = [
            'name'     => 'required|max:255',
            'email'    => "required|email|max:255|unique:admins,email,{$admin_id}",
            'password' => 'required|min:8|confirmed',
            'role_id'  => 'required',
        ];
        $rules = $this->mergeClientRules($rules);
        $rules = $this->checkForUpdate($rules);

        return $rules;
    }
416275
public function generateSearchRules()
    {
        if (($table = $this->getTableSchema()) === false) {
            return ["[['" . implode("', '", $this->getColumnNames()) . "'], 'safe']"];
        }
        $types = [];
        foreach ($table->columns as $column) {
            switch ($column->type) {
                case Schema::TYPE_SMALLINT:
                case Schema::TYPE_INTEGER:
                case Schema::TYPE_BIGINT:
                    $types['integer'][] = $column->name;
                    break;
                case Schema::TYPE_BOOLEAN:
                    $types['boolean'][] = $column->name;
                    break;
                case Schema::TYPE_FLOAT:
                case Schema::TYPE_DECIMAL:
                case Schema::TYPE_MONEY:
                    //$types['number'][] = $column->name;
                    //break;
                case Schema::TYPE_DATE:
                case Schema::TYPE_TIME:
                case Schema::TYPE_DATETIME:
                case Schema::TYPE_TIMESTAMP:
                default:
                    $types['safe'][] = $column->name;
                    break;
            }
        }   
		
        $rules = [];
        foreach ($types as $type => $columns) {            
            $sf = "";
            if ($type == "safe")
            {
				$tabs = $this->generateRelations();				
				foreach ($tabs as $tab)
				{
					if ($tab) {			
						$sf .= ($sf == ""?"/*, '":", '").$tab."Id'";
					}					
				}     					
				$sf .= ($sf == ""?"":"*/");
			}
			$rules[] = "[['" . implode("', '", $columns) . "'".$sf."], '$type']";
        }

        return $rules;
    }
325970
protected function generateRules($rules)
    {
        return collect($rules)->mapWithKeys(function ($rules, $key) {
            return [$this->attribute . '.' . $key => $rules];
        })->toArray();
    }
1321808
public function rules()
    {
        $crude = CrudeInstance::get($this->crudeName);

        if ($crude == null)
            return [];

        if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface)
            return [];

        $attr = $crude->getCrudeSetup()->getEditForm();

        return $crude->getValidationRules($attr, $this->all());
    }
1058030
public function getValidationRules()
    {
        $rules = $this->getOption('rules', []);
        $name = $this->getNameKey();
        $messages = $this->getOption('error_messages', []);
        $formName = $this->formHelper->transformToDotSyntax($this->parent->getName());

        if ($messages && $formName) {
            $newMessages = [];
            foreach ($messages as $messageKey => $message) {
                $messageKey = sprintf('%s.%s', $formName, $messageKey);
                $newMessages[$messageKey] = $message;
            }
            $messages = $newMessages;
        }

        if (!$rules) {
            return (new Rules([]))->setFieldName($this->getNameKey());
        }

        if (is_array($rules)) {
            $rules = array_map(function ($rule) use ($name) {
                if ($rule instanceof \Closure) {
                    return $rule($name);
                }

                return $rule;
            }, $rules);
        }

        return (new Rules(
            [$name => $rules],
            [$name => $this->getOption('label')],
            $messages
        ))->setFieldName($this->getNameKey());
    }
341773
public function setupRules()
    {
        $this->rules->addMany([
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!operator.escape', '!comment', '!string', '!expression'],
            ]),

            'string.heredoc' => new Rule(new RegexMatcher('/<<<\s*(\w+)\R(?P<string>.*?)\R\1;/sm', ['string' => Token::NAME, 0 => 'keyword.heredoc']), ['context' => ['!comment']]),
            'string.nowdoc'  => new Rule(new RegexMatcher('/<<<\s*\'(\w+)\'\R(?P<string>.*?)\R\1;/sm', ['string' => Token::NAME, 0 => 'keyword.nowdoc']), ['context' => ['!comment']]),

            'variable' => new Rule(new RegexMatcher('/(?:[^\\\]|^)(\$[a-z_]\w*)/i'), [
                'context' => ['*comment.docblock', '!string.nowdoc', '!string.single', '!comment']
            ]),
            'variable.property' => new Rule(new RegexMatcher('/(?=(?:\w|\)|\])\s*->([a-z_]\w*))/i'), [
                'priority' => -2,
                'context' => ['*comment.docblock', '!string.nowdoc', '!string.single', '!comment']
            ]),

            'symbol.function' => new Rule(new RegexMatcher('/function\s+([a-z_]\w+)\s*\(/i')),
            'symbol.class'    => [
                new Rule(new RegexMatcher('/(?:class|new|use|extends)\s+([\w\\\]+)/i')),
                new Rule(new RegexMatcher('/([\w\\\]+)::/i')),
                new Rule(new RegexMatcher('/@(?:var|property(?:-read|-write)?)(?:\s+|\s+\$\w+\s+)([^$][\w\\\]+)/i'), ['context' => ['comment.docblock']]),
            ],
            
            'expression.in-string' => new Rule(new RegexMatcher('/(?=(\{\$((?>[^${}]+|(?1))+)\}))/x'), [
                'context' => ['string'],
                'factory' => new TokenFactory(LanguageToken::class),
                'inject'  => $this
            ]),

            'symbol.class.interface' => [
                new Rule(new RegexMatcher('/interface\s+([\w\\\]+)/i')),
                new Rule(new DelegateRegexMatcher(
                    '/implements\s+((?:[\w\\\]+)(?:,\s*([\w\\\]+))+)/i',
                    function($match, TokenFactoryInterface $factory) {
                        foreach (preg_split('/,\s*/', $match[1][0], 0, PREG_SPLIT_OFFSET_CAPTURE) as $interface) {
                            yield $factory->create(Token::NAME, [
                                'pos' => $match[1][1] + $interface[1],
                                'length' => strlen($interface[0])]
                            );
                        }
                    }
                )),
            ],

            'symbol.namespace' => [
                /*new Rule(new RegexMatcher('/(\\\{0,2}(?:\w+\\\{1,2})+)\w+/i'), [
                    'context' => ['*symbol', '*none']
                ]),*/

                new Rule(new RegexMatcher('/namespace\s*(\\\{0,2}(?:\w+\\\{1,2})+\w+);/i'), [
                    'context' => ['*symbol', '*none']
                ]),
            ],

            'operator.escape' => [
                new Rule(new RegexMatcher('/(\\\(?:x[0-9a-fA-F]{1,2}|u\{[0-9a-fA-F]{1,6}\}|[0-7]{1,3}|[^\'\\\]))/i'), [
                    'context' => ['string.double', '!operator.escape']
                ]),
                new Rule(new RegexMatcher('/(\\\[\'\\\])/i'), [
                    'context' => ['string', '!operator.escape']
                ]),
            ],

            'comment' => new Rule(new CommentMatcher(['//', '#'], [
                '$.docblock' => ['/**', '*/'],
                ['/*', '*/']
            ]), ['priority' => 4]),

            'symbol.annotation' => new Rule(new RegexMatcher('/[\s]+(@[\w-]+)/i'), [
                'context' => ['comment.docblock']
            ]),

            'call' => new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => -1]),

            'constant' => new Rule(new WordMatcher(array_merge([
                '__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__',
                '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__',
            ], array_keys(get_defined_constants(true)["Core"]))), ['priority' => -2]),
            'constant.static' => new Rule(new RegexMatcher('/(?:[\w\\\]+::|const\s+)(\w+)/i'), ['priority' => -2]),

            'keyword' => new Rule(new WordMatcher([
                '__halt_compiler', 'abstract', 'and', 'array',
                'as', 'break', 'callable', 'case', 'catch',
                'class', 'clone', 'const', 'continue', 'declare',
                'default', 'die', 'do', 'echo', 'else', 'elseif',
                'empty', 'enddeclare', 'endfor', 'endforeach', 'endif',
                'endswitch', 'endwhile', 'eval', 'exit', 'extends',
                'final', 'finally', 'for', 'foreach', 'function',
                'global', 'goto', 'if', 'implements', 'include', 'include_once',
                'instanceof', 'insteadof', 'interface', 'isset', 'list',
                'namespace', 'new', 'or', 'print', 'private', 'protected',
                'public', 'require', 'require_once', 'return', 'static',
                'switch', 'throw', 'trait', 'try', 'unset', 'parent', 'self',
                'use', 'var', 'while', 'xor', 'yield'
            ]), ['context' => ['!string', '!variable', '!comment']]),

            'keyword.cast' => new Rule(
                new RegexMatcher('/(\((?:int|integer|bool|boolean|float|double|real|string|array|object|unset)\))/')
            ),

            'delimiter' => new Rule(new RegexMatcher('/(<\?php|<\?=|\?>)/')),
            'number'    => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),

            'operator.punctuation' => new Rule(new WordMatcher([',', ';'], ['separated' => false]), ['priority' => 0]),
        ]);
    }
620714
public function rules(): array
    {
        $event = $this->route('event') ?? app('cortex.bookings.event');
        $event->updateRulesUniques();

        return array_merge($event->getRules(), [
            'duration' => 'required',
        ]);
    }
578694
public function rules()
    {
        $validationRule = [];
        $validationRule['name'] = 'required|max:255';

        if (null !== $this->request->get('dropdown-options')) {
            foreach ($this->request->get('dropdown-options') as $key => $val) {
                if ($key == '__RANDOM_STRING__') {
                    continue;
                }
                $validationRule['dropdown-options.' . $key . '.display_text'] = 'required';
            }
        }

        if ($this->getMethod() == 'POST') {
            $validationRule['identifier'] = 'required|max:255|alpha_dash|unique:attributes';
        }
        if ($this->getMethod() == 'PUT') {
            $validationRule['identifier'] = 'required|max:255|alpha_dash';
        }

        return $validationRule;
    }
1216861
private function generateRule($ruleset)
    {
        $regex = '';
        $content = 'index.php';

        $count = 0;
        $total = count($ruleset);

        foreach($ruleset as $ruleChunk)
        {
            $count++;

            if($count === 1) {
                $content .= '?post_type=' . $this->postType->postType;
            }

            if(preg_match('/\{\w+\}/', $ruleChunk))
            {
                // Add to the url catcher
                $regex .= '/([^/]+)';

                // Add to the query string
                $string = preg_match('/\{(.*?)\}/', $ruleChunk, $matches);
                $index = '$matches[' . ($count - 1) . ']';
                $content .= '&' . $matches[1] . '=' . $index;
            }
            else
            {
                // Add to the url catcher
                $regex .= '/' . $ruleChunk;
            }
        }

        $regex .= '/?$';

        return array($regex, $content);
    }
285464
public function rules(): array
    {
        $manager = $this->route('manager') ?? app('cortex.auth.manager');
        $manager->updateRulesUniques();
        $rules = $manager->getRules();

        $rules['roles'] = 'nullable|array';
        $rules['tenants'] = 'nullable|array';
        $rules['abilities'] = 'nullable|array';
        $rules['password'] = $manager->exists
            ? 'confirmed|min:'.config('cortex.auth.password_min_chars')
            : 'required|confirmed|min:'.config('cortex.auth.password_min_chars');

        return $rules;
    }
347069
public function rules()
    {
        $except = is_integer($id = optional($this->article)->id)  ? ",$id,id" : '';

        return [
            // Main content.
            'title' => [
                'bail',
                'required',
                'string',
                'max:255',
                'unique:articles,title'.$except,
            ],
            'slug' => [
                'bail',
                'nullable',
                'string',
                'max:255',
                'unique:articles,slug'.$except,
                'required_with:title',
            ],
            'teaser' => [
                'nullable',
                'string',
                'max:255',
            ],
            'content' => [
                'nullable',
                'string',
            ],
            'description' => [
                'nullable',
                'string',
                'max:255',
            ],
            'keywords' => [
                'nullable',
                'string',
                'max:255',
            ],

            // Flags ?
            'state' => [
                'required',
                'string',
                'in:draft,unpublished,published',
            ],
            'on_mainpage' => [
                'nullable',
                'boolean',
            ],
            'is_favorite' => [
                'nullable',
                'boolean',
            ],
            'is_pinned' => [
                'nullable',
                'boolean',
            ],
            'is_catpinned' => [
                'nullable',
                'boolean',
            ],

            // DateTime.
            'currdate' => [
                'nullable',
                'boolean',
            ],
            'customdate' => [
                'nullable',
                'boolean',
            ],
            'created_at' => [
                'nullable',
                'date_format:"Y-m-d H:i:s"',
                'required_with:customdate',
            ],

            // Extension.
            'allow_com' => [
                'required',
                'numeric',
                'in:0,1,2',
            ],
            'views' => [
                'nullable',
                'integer',
            ],
            'votes' => [
                'nullable',
                'integer',
            ],
            'rating' => [
                'nullable',
                'integer',
            ],

            // Relations types.
            'image_id' => [
                'nullable',
                'integer',
                'exists:files,id',
            ],
            'categories' => [
                'nullable',
                'array',
            ],
            'categories.*' => [
                'integer',
                'exists:categories,id',
            ],
            'files' => [
                'nullable',
                'array',
            ],
            'files.*' => [
                'integer',
                'exists:files,id',
            ],
            'images' => [
                'nullable',
                'array',
            ],
            'images.*' => [
                'integer',
                'exists:files,id',
            ],
            'tags' => [
                'nullable',
                'array',
            ],
            'tags.*' => [
                'string',
                'max:255',
                'regex:/^[\w-]+$/u',
            ],
        ];
    }