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