| 1 | <?php |
||
| 18 | abstract class AbstractBoolean |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * |
||
| 22 | * Pseudo-true representations. |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | * |
||
| 26 | */ |
||
| 27 | protected $true = array('1', 'on', 'true', 't', 'yes', 'y'); |
||
| 28 | |||
| 29 | /** |
||
| 30 | * |
||
| 31 | * Pseudo-false representations; `null` and empty-string are *not* included. |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | * |
||
| 35 | */ |
||
| 36 | protected $false = array('0', 'off', 'false', 'f', 'no', 'n'); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * |
||
| 40 | * Is a value true-ish? |
||
| 41 | * |
||
| 42 | * @param mixed $value The value to check. |
||
| 43 | * |
||
| 44 | * @return bool |
||
| 45 | * |
||
| 46 | */ |
||
| 47 | 69 | protected function isTrue($value) |
|
| 48 | { |
||
| 49 | 69 | if (! $this->isBoolIsh($value)) { |
|
| 50 | 2 | return false; |
|
| 51 | } |
||
| 52 | 67 | return $value === true |
|
| 53 | 67 | || in_array(strtolower(trim($value)), $this->true); |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * |
||
| 58 | * Is a value false-ish? |
||
| 59 | * |
||
| 60 | * @param mixed $value The value to check. |
||
| 61 | * |
||
| 62 | * @return bool |
||
| 63 | * |
||
| 64 | */ |
||
| 65 | 37 | protected function isFalse($value) |
|
| 66 | { |
||
| 67 | 37 | if (! $this->isBoolIsh($value)) { |
|
| 68 | 2 | return false; |
|
| 69 | } |
||
| 70 | 35 | return $value === false |
|
| 71 | 35 | || in_array(strtolower(trim($value)), $this->false); |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * |
||
| 76 | * Can the value be checked for true/false-ish-ness? |
||
| 77 | * |
||
| 78 | * @param mixed $value The value to check. |
||
| 79 | * |
||
| 80 | * @return bool |
||
| 81 | * |
||
| 82 | */ |
||
| 83 | 69 | protected function isBoolIsh($value) |
|
| 90 | } |
||
| 91 |