NotEmpty.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ vYU7R9k9TD+wzOEsP6abcD6yZiCpCtyH1vgSu5zDDUM=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * not empty validator class (will work with the isRequired form validation method)
  14. * will use the isValid method from the parent class
  15. */
  16. namespace Cube\Validate;
  17. class NotEmpty extends AbstractValidate
  18. {
  19. protected $_message = "'%s' is required and cannot be empty.";
  20. /**
  21. *
  22. * checks if the variable is empty
  23. *
  24. * @return bool return true if the validation is successful
  25. */
  26. public function isValid()
  27. {
  28. if (empty($this->_value) && $this->_value !== '0') {
  29. return false;
  30. }
  31. else if (is_array($this->_value)) {
  32. $array = array_filter($this->_value);
  33. if (empty($array)) {
  34. return false;
  35. }
  36. }
  37. return true;
  38. }
  39. }