comparison common-functions.inc @ 88:7a9c45b53866

Add possibility to validate using validator.w3.org
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 17 Oct 2012 20:43:07 +0200
parents ff5fc61aa5ea
children aafc23919e79
comparison
equal deleted inserted replaced
86:b9654b9c4a66 88:7a9c45b53866
9 $baseDir = dirname(__FILE__); 9 $baseDir = dirname(__FILE__);
10 10
11 $cache = ScriptIncludeCache::instance(__FILE__); 11 $cache = ScriptIncludeCache::instance(__FILE__);
12 $cache->includeOnce('StatusCodes.inc', $baseDir); 12 $cache->includeOnce('StatusCodes.inc', $baseDir);
13 /// @endcond 13 /// @endcond
14
15 class RequestException extends RuntimeException
16 {
17 private $_info;
18
19 function __construct($info)
20 {
21 $this->_info = $info;
22 if (array_key_exists('error', $info)) {
23 parent::__construct($info['error']);
24 }
25 }
26
27 function info()
28 {
29 return $this->_info;
30 }
31 }
14 32
15 /** 33 /**
16 * Generates a representation for an array of key => value pairs 34 * Generates a representation for an array of key => value pairs
17 * 35 *
18 * @note Behaviour is undefined if value is a composite structure. 36 * @note Behaviour is undefined if value is a composite structure.
192 * Queries a URL for headers 210 * Queries a URL for headers
193 * 211 *
194 * @param $url the url to query 212 * @param $url the url to query
195 * @return an associative array of all headers returned 213 * @return an associative array of all headers returned
196 */ 214 */
197 function getHeaders($url) 215 function getHeaders($url, $timeout = 1)
198 { 216 {
199 $response = http_head($url, array("timeout" => 1), $info); 217 $response = @http_head($url, array("timeout" => $timeout), $info);
218
219 if (array_key_exists('error', $info) && $info['error']) {
220 throw new RequestException($info);
221 }
222
200 $headers = array(); 223 $headers = array();
201 $response = trim($response); 224 $response = trim($response);
202 $str = explode("\n", $response); 225 $str = explode("\n", $response);
203 $headers[''] = trim($str[0]); 226 $headers[''] = trim($str[0]);
204 foreach($str as $kv) { 227 foreach($str as $kv) {