# HttpRequest.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-2008 by Anton E. Lebedevich                        *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     final class HttpRequest
    00016     {
    00017         // contains all variables from $_GET
    00018         private $get        = array();
    00019
    00020         // from $_POST
    00021         private $post       = array();
    00022
    00023         // guess what
    00024         private $server     = array();
    00025
    00026         // fortune one
    00027         private $cookie     = array();
    00028
    00029         // reference, not copy
    00030         private $session    = array();
    00031
    00032         // uploads
    00033         private $files      = array();
    00034
    00035         // all other sh1t
    00036         private $attached   = array();
    00037
    00038         private $headers    = array();
    00039
    00040         private $method     = null;
    00041
    00042         private $url        = null;
    00043
    00047         public static function create()
    00048         {
    00049             return new self;
    00050         }
    00051
    00052         public function &getGet()
    00053         {
    00054             return $this->get;
    00055         }
    00056
    00057         public function getGetVar($name)
    00058         {
    00059             return $this->get[$name];
    00060         }
    00061
    00062         public function hasGetVar($name)
    00063         {
    00064             return isset($this->get[$name]);
    00065         }
    00066
    00070         public function setGet(array $get)
    00071         {
    00072             $this->get = $get;
    00073
    00074             return $this;
    00075         }
    00076
    00080         public function setGetVar($name, $value)
    00081         {
    00082             $this->get[$name] = $value;
    00083             return $this;
    00084         }
    00085
    00086         public function &getPost()
    00087         {
    00088             return $this->post;
    00089         }
    00090
    00091         public function getPostVar($name)
    00092         {
    00093             return $this->post[$name];
    00094         }
    00095
    00096         public function hasPostVar($name)
    00097         {
    00098             return isset($this->post[$name]);
    00099         }
    00100
    00104         public function setPost(array $post)
    00105         {
    00106             $this->post = $post;
    00107
    00108             return $this;
    00109         }
    00110
    00114         public function setPostVar($name, $value)
    00115         {
    00116             $this->post[$name] = $value;
    00117             return $this;
    00118         }
    00119
    00120         public function &getServer()
    00121         {
    00122             return $this->server;
    00123         }
    00124
    00125         public function getServerVar($name)
    00126         {
    00127             return $this->server[$name];
    00128         }
    00129
    00130         public function hasServerVar($name)
    00131         {
    00132             return isset($this->server[$name]);
    00133         }
    00134
    00138         public function setServer(array $server)
    00139         {
    00140             $this->server = $server;
    00141
    00142             return $this;
    00143         }
    00144
    00148         public function setServerVar($name, $value)
    00149         {
    00150             $this->server[$name] = $value;
    00151             return $this;
    00152         }
    00153
    00154         public function &getCookie()
    00155         {
    00156             return $this->cookie;
    00157         }
    00158
    00159         public function getCookieVar($name)
    00160         {
    00161             return $this->cookie[$name];
    00162         }
    00163
    00164         public function hasCookieVar($name)
    00165         {
    00166             return isset($this->cookie[$name]);
    00167         }
    00168
    00172         public function setCookie(array $cookie)
    00173         {
    00174             $this->cookie = $cookie;
    00175
    00176             return $this;
    00177         }
    00178
    00179         public function &getSession()
    00180         {
    00181             return $this->session;
    00182         }
    00183
    00184         public function getSessionVar($name)
    00185         {
    00186             return $this->session[$name];
    00187         }
    00188
    00189         public function hasSessionVar($name)
    00190         {
    00191             return isset($this->session[$name]);
    00192         }
    00193
    00197         public function setFiles(array $files)
    00198         {
    00199             $this->files = $files;
    00200
    00201             return $this;
    00202         }
    00203
    00204         public function &getFiles()
    00205         {
    00206             return $this->files;
    00207         }
    00208
    00209         public function getFilesVar($name)
    00210         {
    00211             return $this->files[$name];
    00212         }
    00213
    00214         public function hasFilesVar($name)
    00215         {
    00216             return isset($this->files[$name]);
    00217         }
    00218
    00222         public function setSession(array &$session)
    00223         {
    00224             $this->session = &$session;
    00225
    00226             return $this;
    00227         }
    00228
    00232         public function setAttachedVar($name, $var)
    00233         {
    00234             $this->attached[$name] = $var;
    00235
    00236             return $this;
    00237         }
    00238
    00239         public function &getAttached()
    00240         {
    00241             return $this->attached;
    00242         }
    00243
    00244         public function getAttachedVar($name)
    00245         {
    00246             return $this->attached[$name];
    00247         }
    00248
    00252         public function unsetAttachedVar($name)
    00253         {
    00254             unset($this->attached[$name]);
    00255
    00256             return $this;
    00257         }
    00258
    00259         public function hasAttachedVar($name)
    00260         {
    00261             return isset($this->attached[$name]);
    00262         }
    00263
    00264         public function getByType(RequestType $type)
    00265         {
    00266             return $this->{$type->getName()};
    00267         }
    00268
    00269         public function getHeaderList()
    00270         {
    00271             return $this->headers;
    00272         }
    00273
    00274         public function hasHeaderVar($name)
    00275         {
    00276             return isset($this->headers[$name]);
    00277         }
    00278
    00279         public function getHeaderVar($name)
    00280         {
    00281             return $this->headers[$name];
    00282         }
    00283
    00287         public function unsetHeaderVar($name)
    00288         {
    00289             unset($this->headers[$name]);
    00290             return $this;
    00291         }
    00292
    00296         public function setHeaderVar($name, $var)
    00297         {
    00298             $this->headers[$name] = $var;
    00299             return $this;
    00300         }
    00301
    00305         public function setHeaders(array $headers)
    00306         {
    00307             $this->headers = $headers;
    00308             return $this;
    00309         }
    00310
    00314         public function setMethod(HttpMethod $method)
    00315         {
    00316             $this->method = $method;
    00317             return $this;
    00318         }
    00319
    00323         public function getMethod()
    00324         {
    00325             return $this->method;
    00326         }
    00327
    00331         public function setUrl(HttpUrl $url)
    00332         {
    00333             $this->url = $url;
    00334             return $this;
    00335         }
    00336
    00340         public function getUrl()
    00341         {
    00342             return $this->url;
    00343         }
    00344     }
    00345 ?>