Utils.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_Service
  17. * @subpackage Technorati
  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. * Collection of utilities for various Zend_Service_Technorati classes.
  24. *
  25. * @category Zend
  26. * @package Zend_Service
  27. * @subpackage Technorati
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Service_Technorati_Utils
  32. {
  33. /**
  34. * Parses, validates and returns a valid Zend_Uri object
  35. * from given $input.
  36. *
  37. * @param string|Zend_Uri_Http $input
  38. * @return null|Zend_Uri_Http
  39. * @throws Zend_Service_Technorati_Exception
  40. * @static
  41. */
  42. public static function normalizeUriHttp($input)
  43. {
  44. // allow null as value
  45. if ($input === null) {
  46. return null;
  47. }
  48. /**
  49. * @see Zend_Uri
  50. */
  51. require_once 'Zend/Uri.php';
  52. if ($input instanceof Zend_Uri_Http) {
  53. $uri = $input;
  54. } else {
  55. try {
  56. $uri = Zend_Uri::factory((string) $input);
  57. }
  58. // wrap exception under Zend_Service_Technorati_Exception object
  59. catch (Exception $e) {
  60. /**
  61. * @see Zend_Service_Technorati_Exception
  62. */
  63. require_once 'Zend/Service/Technorati/Exception.php';
  64. throw new Zend_Service_Technorati_Exception($e->getMessage(), 0, $e);
  65. }
  66. }
  67. // allow inly Zend_Uri_Http objects or child classes
  68. if (!($uri instanceof Zend_Uri_Http)) {
  69. /**
  70. * @see Zend_Service_Technorati_Exception
  71. */
  72. require_once 'Zend/Service/Technorati/Exception.php';
  73. throw new Zend_Service_Technorati_Exception(
  74. "Invalid URL $uri, only HTTP(S) protocols can be used");
  75. }
  76. return $uri;
  77. }
  78. /**
  79. * Parses, validates and returns a valid Zend_Date object
  80. * from given $input.
  81. *
  82. * $input can be either a string, an integer or a Zend_Date object.
  83. * If $input is string or int, it will be provided to Zend_Date as it is.
  84. * If $input is a Zend_Date object, the object instance will be returned.
  85. *
  86. * @param mixed|Zend_Date $input
  87. * @return null|Zend_Date
  88. * @throws Zend_Service_Technorati_Exception
  89. * @static
  90. */
  91. public static function normalizeDate($input)
  92. {
  93. /**
  94. * @see Zend_Date
  95. */
  96. require_once 'Zend/Date.php';
  97. /**
  98. * @see Zend_Locale
  99. */
  100. require_once 'Zend/Locale.php';
  101. // allow null as value and return valid Zend_Date objects
  102. if (($input === null) || ($input instanceof Zend_Date)) {
  103. return $input;
  104. }
  105. // due to a BC break as of ZF 1.5 it's not safe to use Zend_Date::isDate() here
  106. // see ZF-2524, ZF-2334
  107. if (@strtotime($input) !== FALSE) {
  108. return new Zend_Date($input);
  109. } else {
  110. /**
  111. * @see Zend_Service_Technorati_Exception
  112. */
  113. require_once 'Zend/Service/Technorati/Exception.php';
  114. throw new Zend_Service_Technorati_Exception("'$input' is not a valid Date/Time");
  115. }
  116. }
  117. /**
  118. * @todo public static function xpathQueryAndSet() {}
  119. */
  120. /**
  121. * @todo public static function xpathQueryAndSetIf() {}
  122. */
  123. /**
  124. * @todo public static function xpathQueryAndSetUnless() {}
  125. */
  126. }