Skip to content

Commit

Permalink
Merge branch 'develop' into 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
claar committed Jul 28, 2016
2 parents 37f6876 + 8f4c48e commit 1ad9b33
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Former/Traits/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,36 @@ public function rule($rule)
return $this;
}

/**
* Apply multiple rules passed as a string.
*
* @param $rules
* @return $this
*/
public function rules($rules)
{
foreach (explode('|', $rules) as $rule) {
$parameters = null;

// If we have a rule with a value
if (($colon = strpos($rule, ':')) !== false) {
$parameters = str_getcsv(substr($rule, $colon + 1));
}

// Exclude unsupported rules
$rule = is_numeric($colon) ? substr($rule, 0, $colon) : $rule;

// Store processed rule in Former's array
if (!isset($parameters)) {
$parameters = array();
}

call_user_func_array([$this, 'rule'], array_merge([$rule], $parameters));
}

return $this;
}

/**
* Adds a label to the group/field
*
Expand Down
9 changes: 9 additions & 0 deletions tests/LiveValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ public function testCanApplyRulesByChaining()
$this->assertHTML($matcher, $input);
}

public function testCanApplyMultipleRulesWithString()
{
$input = $this->former->number('foo')->rules('max:10|required')->__toString();
$matcher = $this->matchField(array('max' => 10, 'required' => true), 'number');

$this->assertControlGroup($input);
$this->assertHTML($matcher, $input);
}

public function testCanCreateMaxFileSizeForFiles()
{
$input = $this->former->file('foo')->rule('max', 10)->__toString();
Expand Down

0 comments on commit 1ad9b33

Please sign in to comment.