source: trunk/library/Zend/Validate/Sitemap/Changefreq.php @ 5146

Revision 5146, 2.6 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus. Library: adicionando arquivos.

Line 
1<?php
2/**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category   Zend
16 * @package    Zend_Validate
17 * @subpackage Sitemap
18 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
20 * @version    $Id: Changefreq.php 22668 2010-07-25 14:50:46Z thomas $
21 */
22
23/**
24 * @see Zend_Validate_Abstract
25 */
26require_once 'Zend/Validate/Abstract.php';
27
28/**
29 * Validates whether a given value is valid as a sitemap <changefreq> value
30 *
31 * @link       http://www.sitemaps.org/protocol.php Sitemaps XML format
32 *
33 * @category   Zend
34 * @package    Zend_Validate
35 * @subpackage Sitemap
36 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license    http://framework.zend.com/license/new-bsd     New BSD License
38 */
39class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract
40{
41    /**
42     * Validation key for not valid
43     *
44     */
45    const NOT_VALID = 'sitemapChangefreqNotValid';
46    const INVALID   = 'sitemapChangefreqInvalid';
47
48    /**
49     * Validation failure message template definitions
50     *
51     * @var array
52     */
53    protected $_messageTemplates = array(
54        self::NOT_VALID => "'%value%' is no valid sitemap changefreq",
55        self::INVALID   => "Invalid type given. String expected",
56    );
57
58    /**
59     * Valid change frequencies
60     *
61     * @var array
62     */
63    protected $_changeFreqs = array(
64        'always',  'hourly', 'daily', 'weekly',
65        'monthly', 'yearly', 'never'
66    );
67
68    /**
69     * Validates if a string is valid as a sitemap changefreq
70     *
71     * @link http://www.sitemaps.org/protocol.php#changefreqdef <changefreq>
72     *
73     * @param  string  $value  value to validate
74     * @return boolean
75     */
76    public function isValid($value)
77    {
78        if (!is_string($value)) {
79            $this->_error(self::INVALID);
80            return false;
81        }
82
83        $this->_setValue($value);
84        if (!is_string($value)) {
85            return false;
86        }
87
88        if (!in_array($value, $this->_changeFreqs, true)) {
89            $this->_error(self::NOT_VALID);
90            return false;
91        }
92
93        return true;
94    }
95}
Note: See TracBrowser for help on using the repository browser.