File indexing completed on 2024-05-12 06:03:14

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Validate
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Validate_Abstract
0024  */
0025 // require_once 'Zend/Validate/Abstract.php';
0026 
0027 /**
0028  * @category   Zend
0029  * @package    Zend_Validate
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Validate_LessThan extends Zend_Validate_Abstract
0034 {
0035     const NOT_LESS = 'notLessThan';
0036 
0037     /**
0038      * @var array
0039      */
0040     protected $_messageTemplates = array(
0041         self::NOT_LESS => "'%value%' is not less than '%max%'"
0042     );
0043 
0044     /**
0045      * @var array
0046      */
0047     protected $_messageVariables = array(
0048         'max' => '_max'
0049     );
0050 
0051     /**
0052      * Maximum value
0053      *
0054      * @var mixed
0055      */
0056     protected $_max;
0057 
0058     /**
0059      * Sets validator options
0060      *
0061      * @param  mixed|Zend_Config $max
0062      * @throws Zend_Validate_Exception
0063      */
0064     public function __construct($max)
0065     {
0066         if ($max instanceof Zend_Config) {
0067             $max = $max->toArray();
0068         }
0069 
0070         if (is_array($max)) {
0071             if (array_key_exists('max', $max)) {
0072                 $max = $max['max'];
0073             } else {
0074                 // require_once 'Zend/Validate/Exception.php';
0075                 throw new Zend_Validate_Exception("Missing option 'max'");
0076             }
0077         }
0078 
0079         $this->setMax($max);
0080     }
0081 
0082     /**
0083      * Returns the max option
0084      *
0085      * @return mixed
0086      */
0087     public function getMax()
0088     {
0089         return $this->_max;
0090     }
0091 
0092     /**
0093      * Sets the max option
0094      *
0095      * @param  mixed $max
0096      * @return Zend_Validate_LessThan Provides a fluent interface
0097      */
0098     public function setMax($max)
0099     {
0100         $this->_max = $max;
0101         return $this;
0102     }
0103 
0104     /**
0105      * Defined by Zend_Validate_Interface
0106      *
0107      * Returns true if and only if $value is less than max option
0108      *
0109      * @param  mixed $value
0110      * @return boolean
0111      */
0112     public function isValid($value)
0113     {
0114         $this->_setValue($value);
0115         if ($this->_max <= $value) {
0116             $this->_error(self::NOT_LESS);
0117             return false;
0118         }
0119         return true;
0120     }
0121 
0122 }