PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/Validate/Digits.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 91 lines | 35 code | 10 blank | 46 comment | 6 complexity | 3bd9c26db35e9196a26e6eafaadb3a48 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Digits.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Validate_Abstract
  23. */
  24. require_once 'Zend/Validate/Abstract.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Validate
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Validate_Digits extends Zend_Validate_Abstract
  32. {
  33. const NOT_DIGITS = 'notDigits';
  34. const STRING_EMPTY = 'digitsStringEmpty';
  35. const INVALID = 'digitsInvalid';
  36. /**
  37. * Digits filter used for validation
  38. *
  39. * @var Zend_Filter_Digits
  40. */
  41. protected static $_filter = null;
  42. /**
  43. * Validation failure message template definitions
  44. *
  45. * @var array
  46. */
  47. protected $_messageTemplates = array(
  48. self::NOT_DIGITS => "'%value%' must contain only digits",
  49. self::STRING_EMPTY => "'%value%' is an empty string",
  50. self::INVALID => "Invalid type given. String, integer or float expected",
  51. );
  52. /**
  53. * Defined by Zend_Validate_Interface
  54. *
  55. * Returns true if and only if $value only contains digit characters
  56. *
  57. * @param string $value
  58. * @return boolean
  59. */
  60. public function isValid($value)
  61. {
  62. if (!is_string($value) && !is_int($value) && !is_float($value)) {
  63. $this->_error(self::INVALID);
  64. return false;
  65. }
  66. $this->_setValue((string) $value);
  67. if ('' === $this->_value) {
  68. $this->_error(self::STRING_EMPTY);
  69. return false;
  70. }
  71. if (null === self::$_filter) {
  72. require_once 'Zend/Filter/Digits.php';
  73. self::$_filter = new Zend_Filter_Digits();
  74. }
  75. if ($this->_value !== self::$_filter->filter($this->_value)) {
  76. $this->_error(self::NOT_DIGITS);
  77. return false;
  78. }
  79. return true;
  80. }
  81. }