3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 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\Stdlib\ErrorHandler
;
13 use Zend\Validator\AbstractValidator
;
16 * Validates whether a given value is valid as a sitemap <lastmod> value
18 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format
20 class Lastmod
extends AbstractValidator
23 * Regular expression to use when validating
26 const LASTMOD_REGEX
= '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9])(:[0-5][0-9])?(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/';
29 * Validation key for not valid
32 const NOT_VALID
= 'sitemapLastmodNotValid';
33 const INVALID
= 'sitemapLastmodInvalid';
36 * Validation failure message template definitions
40 protected $messageTemplates = array(
41 self
::NOT_VALID
=> "The input is not a valid sitemap lastmod",
42 self
::INVALID
=> "Invalid type given. String expected",
46 * Validates if a string is valid as a sitemap lastmod
48 * @link http://www.sitemaps.org/protocol.php#lastmoddef <lastmod>
50 * @param string $value value to validate
53 public function isValid($value)
55 if (!is_string($value)) {
56 $this->error(self
::INVALID
);
60 $this->setValue($value);
61 ErrorHandler
::start();
62 $result = preg_match(self
::LASTMOD_REGEX
, $value);
65 $this->error(self
::NOT_VALID
);