File indexing completed on 2024-12-22 05:37:12
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 * @subpackage Sitemap 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Validate_Abstract 0025 */ 0026 // require_once 'Zend/Validate/Abstract.php'; 0027 0028 /** 0029 * Validates whether a given value is valid as a sitemap <priority> value 0030 * 0031 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 0032 * 0033 * @category Zend 0034 * @package Zend_Validate 0035 * @subpackage Sitemap 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract 0040 { 0041 /** 0042 * Validation key for not valid 0043 * 0044 */ 0045 const NOT_VALID = 'sitemapPriorityNotValid'; 0046 const INVALID = 'sitemapPriorityInvalid'; 0047 0048 /** 0049 * Validation failure message template definitions 0050 * 0051 * @var array 0052 */ 0053 protected $_messageTemplates = array( 0054 self::NOT_VALID => "'%value%' is not a valid sitemap priority", 0055 self::INVALID => "Invalid type given. Numeric string, integer or float expected", 0056 ); 0057 0058 /** 0059 * Validates if a string is valid as a sitemap priority 0060 * 0061 * @link http://www.sitemaps.org/protocol.php#prioritydef <priority> 0062 * 0063 * @param string $value value to validate 0064 * @return boolean 0065 */ 0066 public function isValid($value) 0067 { 0068 if (!is_numeric($value)) { 0069 $this->_error(self::INVALID); 0070 return false; 0071 } 0072 0073 $this->_setValue($value); 0074 $value = (float) $value; 0075 if ($value < 0 || $value > 1) { 0076 $this->_error(self::NOT_VALID); 0077 return false; 0078 } 0079 0080 return true; 0081 } 0082 }