| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,69 @@ |
| 1 |
+<? |
|
| 2 |
+ |
|
| 3 |
+namespace elanpl\L3; |
|
| 4 |
+ |
|
| 5 |
+class Request{
|
|
| 6 |
+ public $Path; |
|
| 7 |
+ public $Method; |
|
| 8 |
+ public $Accept; |
|
| 9 |
+ public $AcceptTypes; |
|
| 10 |
+ public $AcceptLanguage; |
|
| 11 |
+ public $UserAgent; |
|
| 12 |
+ public $Headers; |
|
| 13 |
+ public function __construct(){
|
|
| 14 |
+ if(isset($_GET['path'])) |
|
| 15 |
+ $this->Path = $_GET['path']; |
|
| 16 |
+ $this->Method = $_SERVER['REQUEST_METHOD']; |
|
| 17 |
+ $this->Accept = $_SERVER['HTTP_ACCEPT']; |
|
| 18 |
+ $this->AcceptTypes = $this->ParseAccept($this->Accept); |
|
| 19 |
+ $this->AcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
|
| 20 |
+ $this->UserAgent = $_SERVER['HTTP_USERAGENT']; |
|
| 21 |
+ if(function_exists('apache_request_headers')){
|
|
| 22 |
+ $this->Headers = apache_request_headers(); |
|
| 23 |
+ } |
|
| 24 |
+ else{
|
|
| 25 |
+ $this->Headers = array(); |
|
| 26 |
+ foreach($_SERVER as $key => $value) {
|
|
| 27 |
+ if (substr($key, 0, 5) <> 'HTTP_') {
|
|
| 28 |
+ continue; |
|
| 29 |
+ } |
|
| 30 |
+ $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
|
|
| 31 |
+ $this->Headers[$header] = $value; |
|
| 32 |
+ } |
|
| 33 |
+ } |
|
| 34 |
+ } |
|
| 35 |
+ |
|
| 36 |
+ public function ParseAccept($accept){
|
|
| 37 |
+ //cut out the spaces |
|
| 38 |
+ $accept = str_replace(" ", "", $accept);
|
|
| 39 |
+ |
|
| 40 |
+ $result = array(); |
|
| 41 |
+ $quality_factors = array(); |
|
| 42 |
+ |
|
| 43 |
+ // find content type and corresponding quality factor value |
|
| 44 |
+ foreach(explode(",", $accept) as $AcceptParts){
|
|
| 45 |
+ $type = explode(";", $AcceptParts);
|
|
| 46 |
+ $result[] = $type[0]; |
|
| 47 |
+ if(count($type)>1){
|
|
| 48 |
+ if($type[1][0].$type[1][1] == "q="){
|
|
| 49 |
+ $quality_factors[] = substr($type[1],2); |
|
| 50 |
+ } |
|
| 51 |
+ else if($type[2][0].$type[2][1] == "q="){
|
|
| 52 |
+ $quality_factors[] = substr($type[2],2); |
|
| 53 |
+ } |
|
| 54 |
+ else{
|
|
| 55 |
+ $quality_factors[] = 1; |
|
| 56 |
+ } |
|
| 57 |
+ } |
|
| 58 |
+ else{
|
|
| 59 |
+ $quality_factors[] = 1; |
|
| 60 |
+ } |
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ // sort the types according to quality factors |
|
| 64 |
+ array_multisort($quality_factors, SORT_DESC, SORT_NUMERIC, $result); |
|
| 65 |
+ |
|
| 66 |
+ return $result; |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+} |
|
| 0 | 70 |
\ No newline at end of file |