3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Validator\Sitemap
;
12 use Zend\Validator\AbstractValidator
;
15 * Validates whether a given value is valid as a sitemap <priority> value
17 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format
19 class Priority
extends AbstractValidator
22 * Validation key for not valid
25 const NOT_VALID
= 'sitemapPriorityNotValid';
26 const INVALID
= 'sitemapPriorityInvalid';
29 * Validation failure message template definitions
33 protected $messageTemplates = array(
34 self
::NOT_VALID
=> "The input is not a valid sitemap priority",
35 self
::INVALID
=> "Invalid type given. Numeric string, integer or float expected",
39 * Validates if a string is valid as a sitemap priority
41 * @link http://www.sitemaps.org/protocol.php#prioritydef <priority>
43 * @param string $value value to validate
46 public function isValid($value)
48 if (!is_numeric($value)) {
49 $this->error(self
::INVALID
);
53 $this->setValue($value);
54 $value = (float) $value;
55 if ($value < 0 ||
$value > 1) {
56 $this->error(self
::NOT_VALID
);