lithium\console\Dispatcher::applyRules()

public static method

Attempts to apply a set of formatting rules from $_rules to a $params array.

Each formatting rule is applied if the key of the rule in $_rules is present and not empty in $params. Also performs sanity checking against $params to ensure that no value matching a rule is present unless the rule check passes.

Parameters

  • array $params

    An array of route parameters to which rules will be applied.

Returns

array

Returns the $params array with formatting rules applied to array values.

Source

	public static function applyRules($params) {
		$result = [];

		if (!$params) {
			return false;
		}

		foreach (static::$_rules as $name => $rules) {
			foreach ($rules as $rule) {
				if (!empty($params[$name]) && isset($rule[0])) {
					$options = array_merge(
						[$params[$name]], isset($rule[2]) ? (array) $rule[2] : []
					);
					$result[$name] = call_user_func_array([$rule[0], $rule[1]], $options);
				}
			}
		}
		return $result + array_diff_key($params, $result);
	}