Adds specified scenario to the given set of rules.
@param  array  $rules
@param  string $scenario
@return array
195820
public function rulesAddScenario(array $rules, $scenario)
    {
        foreach ($rules as $key => $rule) {
            $rules[$key]['on'] = $scenario;
        }

        return $rules;
    }
846681
public function setRelationScenario($relationName, $scenario)
    {
        /** @var BaseActiveRecord $owner */
        $owner = $this->owner;
        $relation = $owner->getRelation($relationName, false);
        if (in_array($relationName, $this->_relations) && !is_null($relation)) {
            $this->_relationsScenario[$relationName] = $scenario;
        } else {
            throw new InvalidArgumentException('Unknown ' . $relationName . ' relation');
        }

    }
498857
public function addConditions(array $conditions)
    {
        foreach ($conditions as $condition) {
            call_user_func_array([$this, key($condition)], current($condition));
        }

        return $this;
    }
1247451
public function addLexerRule($rulename, $rule)
	{
		$this->rules[$rulename] = [];
		$this->rules[$rulename][] = $rule; 
	}
142742
public function add(\Caridea\Validate\Rule ...$rules): self
    {
        $this->rules = array_merge($this->rules, $rules);
        return $this;
    }
798723
public function addField($field, $title, array $rules = array()) {
        $this->_fields[$field] = $title;

        /**
         * 0 => rule
         * rule => [opt, ...]
         */
        if ($rules) {
            foreach ($rules as $rule => $options) {
                if (is_numeric($rule)) {
                    $rule = $options;
                    $options = array();
                }

                $this->addRule($field, $rule, null, $options);
            }
        }

        return $this;
    }
1205089
public function rules($field, array $rules)
    {
        foreach ($rules as $rule)
        {
            $this->rule($field, $rule[0], Arr::get($rule, 1));
        }

        return $this;
    }
1054991
private function getSteps(ScenarioInterface $scenario)
    {
        if (! $scenario->hasSteps()) {
            return;
        }

        $step = new Step($this->align);

        return $step->format($scenario->getSteps()) . "\n";
    }
417506
protected function rulesArrayContainsAnyNestedRules(array $rules)
    {
        foreach ($rules as $rule) {

            if ( ! empty($rule->key())) {
                return true;
            }
        }

        return false;
    }
809727
public static function match($scenario1, $scenario2)
	{
		$match1 = $match2 = [];
		if ( preg_match_all('/([^\\}{]*)\{([^\{\}]+)\}/', $scenario1, $match1, PREG_SET_ORDER) &&
			   preg_match_all('/([^\\}{]*)\{([^\{\}]+)\}/', $scenario2, $match2, PREG_SET_ORDER) ) {

			if ( count($match1) != count($match2) ) {
				return false;
			}
			for ($i = 0; $i < count($match1); $i++) {
				if ( str_replace(' ', '', $match1[$i][1]) != str_replace(' ', '', $match2[$i][1]) ) {
					return false;
				}
				if ( $match1[$i][2] != $match2[$i][2] &&  $match1[$i][2] != '*' && $match2[$i][2] != '*' ) {
					return false;
				}
			}
		} else {
			return false;
		}
		return true;
	}
934039
protected function build_propositions( array $rules ) {
		$props = [];

		foreach ( $rules as $rule ) {
			if ( ! is_array( $rule ) || ! static::is_proposition( $rule ) ) {
				continue;
			}

			try {
				$props[] = $this->create_proposition( ... $rule );
			} catch ( \Exception $e ) {
				continue;
			}
		}

		return array_filter( $props );
	}
209370
protected function findScenario($scenario = null)
    {
        $scenarios = $this->scenarios();
        if ($scenario === null) {
            $scenario = $this->getScenario();
        }
        return isset($scenarios[$scenario]) ? $scenarios[$scenario] : [];
    }
1273952
public function addConditions( $conditions )
	{
		if( !is_array( $conditions ) )
			throw new InvalidArgumentException( 'An Array should be given.' );
		foreach( $conditions as $condition )
			$this->addCondition( $condition );
	}
79939
public function save(int $scenario = Model::INSERT_NORMAL) {
        $pkName = $this->model->pkName;
        if ($this->model->isNewRecord) {
            $pk = 0;
            switch ($scenario) {
                case Model::INSERT_NORMAL:
                    $this->model->builder
                        ->insertInto($this->model->tableName)
                        ->columns($this->model->tableSchema->columnNames)
                        ->values($this->model->properties)
                        ->query();
                    $pk = $this->model->db->getLastInsertId();
                    if (empty($pk) && !empty($this->model->pk)) {
                        $pk = $this->model->pk;
                    }
                    break;
                case Model::INSERT_IGNORE:
                    $this->model->builder
                        ->insertIgnoreInto($this->model->tableName)
                        ->columns($this->model->tableSchema->columnNames)
                        ->values($this->model->properties)
                        ->query();
                    $pk = $this->model->db->getLastInsertId();
                    break;
                case Model::INSERT_UPDATE:
                    $this->model->builder
                        ->insertInto($this->model->tableName)
                        ->columns($this->model->tableSchema->columnNames)
                        ->values($this->model->properties)
                        ->onDupKeyUpdate($this->model->modified)
                        ->query();
                    $pk = $this->model->db->getLastInsertId();
                    break;
            }
            if ($pk) {
                $this->load($pk);
            }
        } else if (0 !== count($this->model->modified)) {
            $this->model->builder
                ->update($this->model->tableName)
                ->set($this->model->modified)
                ->where("`$pkName`=:_table_pk", array(
                    ':_table_pk' => $this->model->oldPK,
                ))->query();
            $this->load($this->model->pk);
        }
        return $this->model;
    }
376165
protected function addRule(array $rules, $name, array $abbreviations) {
        if (array_get($rules, $name) === null) {
            $rules[$name] = [];
        }

        $patterns = $this->createPatternsForStrings($abbreviations);

        foreach ($patterns as $pattern) {
            $rules[$name][] = $pattern;
        }

        return $rules;
    }
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;
    }
502827
public function setConditions($conditions)
    {
        $this->conditions = [];
        if (!is_array($conditions)) {
            $conditions = [$conditions];
        }
        foreach ($conditions as $condition) {
            $this->addCondition($condition);
        }

        return $this;
    }