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 <changefreq> value
17 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format
19 class Changefreq
extends AbstractValidator
22 * Validation key for not valid
25 const NOT_VALID
= 'sitemapChangefreqNotValid';
26 const INVALID
= 'sitemapChangefreqInvalid';
29 * Validation failure message template definitions
33 protected $messageTemplates = array(
34 self
::NOT_VALID
=> "The input is not a valid sitemap changefreq",
35 self
::INVALID
=> "Invalid type given. String expected",
39 * Valid change frequencies
43 protected $changeFreqs = array(
44 'always', 'hourly', 'daily', 'weekly',
45 'monthly', 'yearly', 'never'
49 * Validates if a string is valid as a sitemap changefreq
51 * @link http://www.sitemaps.org/protocol.php#changefreqdef <changefreq>
53 * @param string $value value to validate
56 public function isValid($value)
58 if (!is_string($value)) {
59 $this->error(self
::INVALID
);
63 $this->setValue($value);
64 if (!is_string($value)) {
68 if (!in_array($value, $this->changeFreqs
, true)) {
69 $this->error(self
::NOT_VALID
);