Loc.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Validate_Abstract
  24. */
  25. #require_once 'Zend/Validate/Abstract.php';
  26. /**
  27. * @see Zend_Uri
  28. */
  29. #require_once 'Zend/Uri.php';
  30. /**
  31. * Validates whether a given value is valid as a sitemap <loc> value
  32. *
  33. * @link http://www.sitemaps.org/protocol.php Sitemaps XML format
  34. *
  35. * @category Zend
  36. * @package Zend_Validate
  37. * @subpackage Sitemap
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract
  42. {
  43. /**
  44. * Validation key for not valid
  45. *
  46. */
  47. const NOT_VALID = 'sitemapLocNotValid';
  48. const INVALID = 'sitemapLocInvalid';
  49. /**
  50. * Validation failure message template definitions
  51. *
  52. * @var array
  53. */
  54. protected $_messageTemplates = array(
  55. self::NOT_VALID => "'%value%' is not a valid sitemap location",
  56. self::INVALID => "Invalid type given. String expected",
  57. );
  58. /**
  59. * Validates if a string is valid as a sitemap location
  60. *
  61. * @link http://www.sitemaps.org/protocol.php#locdef <loc>
  62. *
  63. * @param string $value value to validate
  64. * @return boolean
  65. */
  66. public function isValid($value)
  67. {
  68. if (!is_string($value)) {
  69. $this->_error(self::INVALID);
  70. return false;
  71. }
  72. $this->_setValue($value);
  73. $result = Zend_Uri::check($value);
  74. if ($result !== true) {
  75. $this->_error(self::NOT_VALID);
  76. return false;
  77. }
  78. return true;
  79. }
  80. }