1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
<?php
namespace Coast\Validator\Rule;
use Coast\Validator\Rule;
class BooleanType extends Rule
{
protected $_true = [true, 'true', 1, '1'];
protected $_false = [false, 'false', 0, '0'];
public function __construct(array $true = null, array $false = null)
{
if (isset($true)) {
$this->true($true);
}
if (isset($false)) {
$this->false($false);
}
}
public function true(array $true = null)
{
if (func_num_args() > 0) {
$this->_true = $true;
return $this;
}
return $this->_true;
}
public function false(array $false = null)
{
if (func_num_args() > 0) {
$this->_false = $false;
return $this;
}
return $this->_false;
}
protected function _validate($value)
{
if (!in_array($value, $this->_true, true) && !in_array($value, $this->_false, true)) {
$this->error();
}
}
}