12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php namespace System\Validation\Rules;
- use System\Validation\Rule;
- class Presence_Of extends Rule {
-
- public $allow_empty = false;
-
- public $allow_null = false;
-
- public function check($attribute, $attributes)
- {
- if ( ! array_key_exists($attribute, $attributes))
- {
- return false;
- }
- if (is_null($attributes[$attribute]) and ! $this->allow_null)
- {
- return false;
- }
- if (trim((string) $attributes[$attribute]) === '' and ! $this->allow_empty)
- {
- return false;
- }
- return true;
- }
-
- public function allow_empty()
- {
- $this->allow_empty = true;
- return $this;
- }
-
- public function allow_null()
- {
- $this->allow_null = true;
- return $this;
- }
- }
|