RulesProvider.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since CakePHP(tm) v 3.0.0
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. namespace Cake\Validation;
  16. /**
  17. * A Proxy class used to remove any extra arguments when the user intended to call
  18. * a method in another class that is not aware of validation providers signature
  19. */
  20. class RulesProvider {
  21. /**
  22. * The class to proxy, defaults to \Cake\Validation\Validation in construction
  23. *
  24. * @var object
  25. */
  26. protected $_class;
  27. /**
  28. * Constructor, sets the default class to use for calling methods
  29. *
  30. * @param string $class the default class to proxy
  31. */
  32. public function __construct($class = '\Cake\Validation\Validation') {
  33. $this->_class = $class;
  34. }
  35. /**
  36. * Proxies validation method calls to the Validation class, it slices
  37. * the arguments array to avoid passing more arguments than required to
  38. * the validation methods.
  39. *
  40. * @param string $method the validation method to call
  41. * @param array $arguments the list of arguments to pass to the method
  42. * @return boolean whether or not the validation rule passed
  43. */
  44. public function __call($method, $arguments) {
  45. $arguments = array_slice($arguments, 0, -1);
  46. return call_user_func_array([$this->_class, $method], $arguments);
  47. }
  48. }