Sets up additional custom rules

@return  void
160998
public function setup()
	{
		// Check that username conforms to rules
		$this->addRule('username', function($data)
		{
			$username = $data['username'];

			// We do this here because we need to allow one possible
			// "invalid" username to pass through, used when creating
			// temp accounts during the 3rd party auth registration
			if (is_numeric($username) && $username < 0)
			{
				return false;
			}

			if (preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $username)
			 || strlen(utf8_decode($username)) < 2
			 || trim($username) != $username)
			{
				return \Lang::txt('JLIB_DATABASE_ERROR_VALID_AZ09', 2);
			}

			return false;
		});

		// Check for existing username
		$this->addRule('username', function($data)
		{
			$user = self::oneByUsername($data['username']);

			if ($user->get('id') && $user->get('id') != $data['id'])
			{
				return \Lang::txt('JLIB_DATABASE_ERROR_USERNAME_INUSE');
			}

			return false;
		});

		// Check for valid email address
		// We do this here because we need to allow one possible
		// "invalid" address to pass through, used when creating
		// temp accounts during the 3rd party auth registration
		$this->addRule('email', function($data)
		{
			$email = $data['email'];

			if (preg_match('/^-[0-9]+@invalid$/', $email))
			{
				return false;
			}

			return (\Hubzero\Utility\Validate::email($email) ? false : 'Email does not appear to be valid');
		});
	}
1156366
public function setupRules()
    {
        $this->rules->addMany([
            'tag.open'  => [
                new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')),
                new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']])
            ],
            'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')),

            'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'constant.entity' => new Rule(new RegexMatcher('/(&(?:\#\d+|[a-z])+;)/si')),

            'comment' => new Rule(new CommentMatcher(null, [['<!--', '-->']])),
            'string'  => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['tag']]),
        ]);
    }
733921
public function addRules()
    {
        $this->property->relatedPropertiesModel->addRule($this->property->code, 'number');

        if ($this->property->isRequired) {
            $this->property->relatedPropertiesModel->addRule($this->property->code, 'required');
        }

        return $this;
    }
67034
def add_unique_rules(self, rules, customize):
        
        for rule in rules:
            if len(rule) == 0:
                continue
            opname = rule.split('::=')[0].strip()
            self.add_unique_rule(rule, opname, 0, customize)
        return
766149
protected function _setRules()
    {
        $resources = $this->getResources();

        /** @var Mage_Api2_Model_Resource_Acl_Global_Rule_Collection $rulesCollection */
        $rulesCollection = Mage::getResourceModel('api2/acl_global_rule_collection');
        foreach ($rulesCollection as $rule) {
            /** @var Mage_Api2_Model_Acl_Global_Rule $rule */
            if (Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL === $rule->getResourceId()) {
                if (in_array($rule->getRoleId(), Mage_Api2_Model_Acl_Global_Role::getSystemRoles())) {
                    /** @var Mage_Api2_Model_Acl_Global_Role $role */
                    $role = $this->_getRolesCollection()->getItemById($rule->getRoleId());
                    $privileges = $this->_getConfig()->getResourceUserPrivileges(
                        $this->_resourceType,
                        $role->getConfigNodeName()
                    );

                    if (!array_key_exists($this->_operation, $privileges)) {
                        continue;
                    }
                }

                $this->allow($rule->getRoleId());
            } elseif (in_array($rule->getResourceId(), $resources)) {
                $this->allow($rule->getRoleId(), $rule->getResourceId(), $rule->getPrivilege());
            }
        }

        return $this;
    }
445170
protected function setUpScripts()
    {
        Admin::script($this->script());

        foreach ($this->actions as $action) {
            $action->setGrid($this->grid);

            Admin::script($action->script());
        }
    }
1028983
public function setupRules()
    {
        $this->rules->addMany([
            'keyword' => new Rule(new WordMatcher([
                'ACCEPT', 'ACCESS', 'ADD', 'ADDRESS', 'ADVANCING', 'AFTER', 'ALL', 'ALPHABET',
                'ALPHABETIC(-(LOWER|UPPER))?', 'ALPHANUMERIC(-EDITED)?', 'ALSO', 'ALTER', 'ALTERNATE', 'AND', 'ANY',
                'APPLY', 'ARE', 'AREA', 'AREAS', 'ASCENDING', 'ASSIGN', 'AT', 'AUTHOR', 'BASIS', 'BEFORE', 'BEGINNING',
                'BINARY', 'BLANK', 'BLOCK', 'BOTTOM', 'BY', 'CALL', 'CANCEL', 'CBL', 'CHARACTER', 'CHARACTERS', 'CLASS',
                'CLOSE', 'CODE-SET', 'COLLATING', 'COMMA', 'COMMON', 'COMP(-[1-4])?', 'COMPUTATIONAL(-[1-4])?',
                'COMPUTE', 'CONFIGURATION', 'CONTAINS', 'CONTENT', 'CONTINUE', 'CONVERTING', 'COPY', 'CORR',
                'CORRESPONDING', 'COUNT', 'CURRENCY', 'DATA', 'DATE(-(COMPILED|WRITTEN))?', 'DAY-OF-WEEK', 'DAY',
                'DBCS', 'DEBUG-ITEM', 'DEBUGGING', 'DECIMAL-POINT', 'DECLARATIVES', 'DEGUGGING', 'DELETE', 'DELIMITED',
                'DELIMITER', 'DEPENDING', 'DESCENDING', 'DISPLAY(-1)?', 'DIVIDE', 'DIVISION', 'DOWN', 'DUPLICATES',
                'DYNAMIC', 'EBCDIC', 'EGCS', 'EJECT', 'ELSE',
                'END(-(ADD|CALL|COMPUTE|DELETE|DIVIDE|EVALUATE|IF|MULTIPLY|OF-PAGE|PERFORM|READ|RETURN|REWRITE|SEARCH|START|STRING|SUBTRACT|UNSTRING|WRITE))?',
                'ENDING', 'ENTER', 'ENTRY', 'ENVIRONMENT', 'EOP', 'EQUAL', 'ERROR', 'EVALUATE', 'EVERY', 'EXCEPTION',
                'EXIT', 'EXTEND', 'EXTERNAL', 'F', 'FALSE', 'FD', 'FILE(-CONTROL)?', 'FILLER', 'FIRST', 'FOOTING',
                'FOR', 'FROM', 'GIVING', 'GLOBAL', 'GO', 'GOBACK', 'GREATER', 'HIGH-VALUES?', 'I-O(-CONTROL)?', 'ID',
                'IDENTIFICATION', 'IF', 'IN', 'INDEX', 'INDEXED', 'INITIAL', 'INITIALIZE', 'INPUT', 'INPUT-OUTPUT',
                'INSERT', 'INSPECT', 'INSTALLATION', 'INTO', 'INVALID', 'IS', 'JUST', 'JUSTIFIED', 'KANJI', 'KEY',
                'LABEL', 'LEADING', 'LEFT', 'LENGTH', 'LESS', 'LINAGE(-COUNTER)?', 'LINE', 'LINES', 'LINKAGE', 'LIST',
                'LOCK', 'LOW-VALUES?', 'MAP', 'MEMORY', 'MERGE', 'MODE', 'MODULES', 'MORE-LABELS', 'MOVE', 'MULTIPLE',
                'MULTIPLY', 'NATIVE', 'NEGATIVE', 'NEXT', 'NO', 'NOLIST', 'NOMAP', 'NOSOURCE', 'NOT', 'NULL', 'NULLS',
                'NUMERIC(-EDITED)?', 'OBJECT-COMPUTER', 'OCCURS', 'OF', 'OFF', 'OMITTED', 'ON', 'OPEN', 'OPTIONAL',
                'OR', 'ORDER', 'ORGANIZATION', 'OTHER', 'OUTPUT', 'OVERFLOW', 'PACKED-DECIMAL', 'PADDING', 'PAGE',
                'PASSWORD', 'PERFORM', 'PIC', 'PICTURE', 'POINTER', 'POSITION', 'POSITIVE', 'PROCEDURE', 'PROCEDURES',
                'PROCEED', 'PROCESS', 'PROGRAM(-ID)?', 'QUOTE', 'QUOTES', 'RANDOM', 'READ', 'READY', 'RECORD',
                'RECORDING', 'RECORDS', 'REDEFINES', 'REEL', 'REFERENCE', 'RELATIVE', 'RELEASE', 'RELOAD', 'REMAINDER',
                'REMOVAL', 'RENAMES', 'REPLACE', 'REPLACING', 'RERUN', 'RESERVE', 'RESET', 'RETURN(-CODE)?REVERSED',
                'REWIND', 'REWRITE', 'RIGHT', 'ROUNDED', 'RUN', 'S', 'SAME', 'SD', 'SEARCH', 'SECTION', 'SECURITY',
                'SEGMENT-LIMIT', 'SELECT', 'SENTENCE', 'SEPARATE', 'SEQUENCE', 'SEQUENTIAL', 'SERVICE', 'SET',
                'SHIFT-(IN|OUT)', 'SIGN', 'SIZE', 'SKIP1', 'SKIP2', 'SKIP3',
                'SORT(-(CONTROL|CORE-SIZE|FILE-SIZE|MERGE|MESSAGE|MODE-SIZE|RETURN))?', 'SOURCE(-COMPUTER)?', 'SPACE',
                'SPACES', 'SPECIAL-NAMES', 'STANDARD(-[1-2])?', 'START', 'STATUS', 'STOP', 'STRING', 'SUBTRACT',
                'SUPPRESS', 'SYMBOLIC', 'SYNC', 'SYNCHRONIZED', 'TALLY', 'TALLYING', 'TAPE', 'TEST', 'THAN', 'THEN',
                'THROUGH', 'THRU', 'TIME', 'TIMES', 'TITLE', 'TO', 'TOP', 'TRACE', 'TRAILING', 'TRUE', 'U', 'UNIT',
                'UNSTRING', 'UNTIL', 'UP', 'UPON', 'USAGE', 'USE', 'USING', 'V', 'VALUE', 'VALUES', 'VARYING',
                'WHEN(-COMPILED)?', 'WITH', 'WORDS', 'WORKING-STORAGE', 'WRITE(-ONLY)?', 'ZERO(S|ES)?',
            ], ['case-sensitivity' => true, 'separated' => true, 'escape' => false])),
            'number'  => new Rule(new RegexMatcher('/([\+\-]?(?:[0-9]*[\.][0-9]+|[0-9]+))/')),
            'comment' => new Rule(new CommentMatcher(['*'])),
            'string'  => CommonFeatures::strings(['"', '\'']),
        ]);
    }
1296184
public  function addRules($rules) {
        if ( is_array($rules) && !empty($rules) )
		    self::$tempRules = array_merge(self::$tempRules, $rules);
	}
724168
private function setupDefaultConfigs()
    {
        $this->setLayout();
        $this->setSummary();

        if (!$this->isEmpty()) {
            $this->setActionBar();
        }

        $this->showOnEmpty = false;
    }
70523
protected function setUp(): void
    {
        parent::setUp();

        $nextToken = $this->tokens[$this->stackPos + 1];
        $prevToken = $this->tokens[$this->stackPos - 1];

        $this->nextIsWhitespace = $nextToken['code'] === T_WHITESPACE;
        $this->prevIsWhitespace = $prevToken['code'] === T_WHITESPACE;
    }
1309935
private void setUp() {
		addExamples("AJAX", ExampleData.AJAX_EXAMPLES);
		addExamples("Form controls", ExampleData.FORM_CONTROLS);
		addExamples("Feedback and indicators", ExampleData.FEEDBACK_AND_INDICATORS);
		addExamples("Layout", ExampleData.LAYOUT_EXAMPLES);
		addExamples("Menus", ExampleData.MENU_EXAMPLES);
		addExamples("Links", ExampleData.LINK_EXAMPLES);
		addExamples("Popups / dialogs", ExampleData.POPUP_EXAMPLES);
		addExamples("Subordinate", ExampleData.SUBORDINATE_EXAMPLES);
		addExamples("Tabs", ExampleData.TABSET_EXAMPLES);
		addExamples("Tables", ExampleData.WTABLE_EXAMPLES);
		addExamples("Validation", ExampleData.VALIDATION_EXAMPLES);
		addExamples("Other examples (uncategorised)", ExampleData.MISC_EXAMPLES);
		addExamples("DataTable (deprecated)", ExampleData.WDATATABLE_EXAMPLES);
	}
222388
protected function setupValidationScenario()
    {
        $current = $this->method();
        $available = [
            'POST' => 'store',
            'PUT' => 'update',
            'DELETE' => 'destroy',
        ];

        if (in_array($current, $available)) {
            $this->onValidationScenario($available[$current]);
        }
    }
310615
public function addRuleOnPk()
    {
        if (!count($this->getParameters())) {
            $pk = $this->getTable()->getPrimaryKey();
            $parameters = ['auto_rule' => [
                'column'     => $pk[0]->getName(),
                'validators' => 'Type',
                'options'    => [
                    'type'   => $pk[0]->getPhpType(),
                ],
            ]];
            $this->setParameters($parameters);
        }
    }
50515
protected function configure()
    {
        $this
            ->addArgument('stores', InputArgument::IS_ARRAY | InputArgument::REQUIRED,
                'A list of stores to re-encrypt.')
            ->addOption(
                'new-profile',
                null,
                InputOption::VALUE_REQUIRED,
                'The new profile the current data is encrypted with.',
                null
            )
            ->addOption(
                'offset',
                null,
                InputOption::VALUE_REQUIRED,
                'Starting record',
                0
            )
            ->addOption(
                'limit',
                null,
                InputOption::VALUE_REQUIRED,
                'Max records to process',
                null
            )
            ->addOption(
                'batch-size',
                null,
                InputOption::VALUE_REQUIRED,
                'Records per batch to process',
                1
            );
    }
1081568
protected function wizardAddPriceRule()
    {
        $this->validatePrompt('name', $this->text('Name'), 'price_rule');
        $this->validatePrompt('trigger_id', $this->text('Trigger ID'), 'price_rule');

        $types = array();
        foreach ($this->price_rule->getTypes() as $id => $type) {
            $types[$id] = $type['title'];
        }

        $this->validateMenu('value_type', $this->text('Value type'), 'price_rule', $types, 'percent');
        $this->validatePrompt('value', $this->text('Value'), 'price_rule');
        $this->validatePrompt('currency', $this->text('Currency'), 'price_rule', $this->currency->getDefault());
        $this->validatePrompt('code', $this->text('Code'), 'price_rule', '');
        $this->validatePrompt('status', $this->text('Status'), 'price_rule', 0);
        $this->validatePrompt('weight', $this->text('Weight'), 'price_rule', 0);

        $this->validateComponent('price_rule');
        $this->addPriceRule();
    }
1023326
public function setupRules()
    {
        $this->rules->addMany([
            'keyword' => new Rule(new WordMatcher([
                'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', 'goto',
                'if', 'register', 'return', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'volatile',
                'while',
            ])),

            'meta.newline' => new CloseRule(new RegexMatcher('/()\R/m'), [
                'factory' => new TokenFactory(TerminatorToken::class),
                'context' => ['!operator.escape', '*string', '*call.preprocessor'],
                'closes'  => ['string.double', 'preprocessor'],
            ]),

            'preprocessor' => new OpenRule(new RegexMatcher('/^(#)/m'), [
                'context' => Validator::everywhere(),
                'priority' => -1
            ]),

            'call' => [
                'preprocessor' => new Rule(new RegexMatcher('/^#\s*(\w+)\b/m'), [
                    'context' => ['preprocessor']
                ]),
                new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => -1]),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [
                'context' => Validator::everywhere()
            ]),

            'keyword.format' => new Rule(
                new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [
                    'context' => ['string']
                ]
            ),

            'string' => array_merge([
                new Rule(new RegexMatcher('/(<.*?>)/'), [
                    'context' => ['preprocessor']
                ])
            ], CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!operator.escape', '!comment', '!string'],
            ])),

            'symbol.type' => [
                new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*\*\s*)\w+\s*[=();,]/'), ['name' => 'universal']),
                new Rule(new WordMatcher(['int', 'float', 'double', 'char', 'void', 'long', 'short', 'signed', 'unsigned']), ['name' => 'builtin'])
            ],

            'comment' => [
                new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 2])
            ],

            'variable.property' => new Rule(new RegexMatcher('/(?=(?:\w|\)|\])\s*(?:->|\.)\s*([a-z_]\w*))/'), ['priority' => 0]),

            'number' => new Rule(new RegexMatcher('/\b(-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*)\b/i')),
            'operator' => [
                'punctuation' => new Rule(new RegexMatcher('/([;,])/'), ['priority' => 0]),
                new Rule(new RegexMatcher('/([*&])/'), ['priority' => 0]),
                new Rule(new RegexMatcher('/([!+\-\/*&|^<>=]{1,2}=?)/'), ['priority' => 0])
            ],

            'language.c' => [
                new Rule(new RegexMatcher('/^#define\s+\w+(.*?)(?>[^\\\]\r\n|[^\\\\\r]\n|\Z)/sim'), [
                    'factory' => new TokenFactory(LanguageToken::class),
                    'inject'  => $this,
                    'context' => ['preprocessor'],
                    'priority' => 10
                ]),
            ]
        ]);
    }
1298458
protected function registerDefaultRules()
    {
        $rulesClasses = array(
            'Alpha',
            'AlphaNumeric',
            'AlphaNumHyphen',
            'ArrayLength',
            'ArrayMaxLength',
            'ArrayMinLength',
            'Between',
            'Callback',
            'Date',
            'DateTime',
            'Email',
            'EmailDomain',
            'Equal',
            'FullName',
            'GreaterThan',
            'InList',
            'Integer',
            'IpAddress',
            'Length',
            'LessThan',
            'Match',
            'MaxLength',
            'MinLength',
            'NotInList',
            'NotRegex',
            'Number',
            'Regex',
            'Required',
            'RequiredWhen',
            'RequiredWith',
            'RequiredWithout',
            'Time',
            'Url',
            'Website',
            'File\Extension',
            'File\Image',
            'File\ImageHeight',
            'File\ImageRatio',
            'File\ImageWidth',
            'File\Size',
            'Upload\Required',
            'Upload\Extension',
            'Upload\Image',
            'Upload\ImageHeight',
            'Upload\ImageRatio',
            'Upload\ImageWidth',
            'Upload\Size',
        );
        foreach ($rulesClasses as $class) {
            $fullClassName       = '\\' . __NAMESPACE__ . '\Rule\\' . $class;
            $name                = strtolower(str_replace('\\', '', $class));
            $errorMessage        = constant($fullClassName . '::MESSAGE');
            $labeledErrorMessage = constant($fullClassName . '::LABELED_MESSAGE');
            $this->register($name, $fullClassName, $errorMessage, $labeledErrorMessage);
        }
    }