MockPostForValidates.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\mocks\data;
  9. use lithium\util\Validator;
  10. class MockPostForValidates extends \lithium\data\Model {
  11. protected $_meta = array('source' => 'mock_posts', 'connection' => false);
  12. public $validates = array(
  13. 'title' => 'please enter a title',
  14. 'email' => array(
  15. array('notEmpty', 'message' => 'email is empty'),
  16. array('email', 'message' => 'email is not valid'),
  17. array('modelIsSet', 'required' => false, 'message' => 'model is not set'),
  18. array(
  19. 'inList',
  20. 'list' => array('[email protected]','[email protected]'),
  21. 'on' => 'customEvent',
  22. 'message' => 'email is not in 1st list'
  23. ),
  24. array(
  25. 'inList',
  26. 'list' => array('[email protected]'),
  27. 'on' => 'anotherCustomEvent',
  28. 'message' => 'email is not in 2nd list'
  29. )
  30. )
  31. );
  32. public static function __init() {
  33. $class = __CLASS__;
  34. Validator::add('modelIsSet', function($value, $format, $options) use ($class) {
  35. if (isset($options['model']) && $options['model'] = $class) {
  36. return true;
  37. }
  38. return false;
  39. });
  40. }
  41. }
  42. ?>