forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New object syntax for the rule in (laravel#15923)
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Illuminate\Validation\Rules; | ||
|
||
class In | ||
{ | ||
/** | ||
* The accepted values. | ||
* | ||
* @var array | ||
*/ | ||
protected $values; | ||
|
||
/** | ||
* Create a new in rule instance. | ||
* | ||
* @param array $values | ||
* @return void | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
$this->values = $values; | ||
} | ||
|
||
/** | ||
* Convert the rule to a validation string. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return 'in:'.implode(',', $this->values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use Illuminate\Validation\Rule; | ||
use Illuminate\Validation\Rules\In; | ||
|
||
class ValidationInRuleTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testItCorrectlyFormatsAStringVersionOfTheRule() | ||
{ | ||
$rule = new In(['Laravel', 'Framework', 'PHP']); | ||
|
||
$this->assertEquals('in:Laravel,Framework,PHP', (string) $rule); | ||
|
||
$rule = Rule::in([1, 2, 3, 4]); | ||
|
||
$this->assertEquals('in:1,2,3,4', (string) $rule); | ||
} | ||
} |