dmBridge PHP API
DMHTTPRepresentation.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMHTTPRepresentation {
00014 
00016    private $body;
00018    private $character_set;
00020    private $form_data = array();
00022    private $media_type;
00023 
00024 
00025    public function __construct() {
00026       $this->setCharacterSet("utf-8");
00027       $this->setMediaType(new DMMediaType("text", "plain"));
00028    }
00029 
00033    public function __toString() {
00034       return (string) $this->getBody();
00035    }
00036 
00040    public function getBody() {
00041       return $this->body;
00042    }
00043 
00047    public function setBody($body) {
00048       $this->body = $body;
00049    }
00050 
00054    public function getCharacterSet() {
00055       return $this->character_set;
00056    }
00057 
00061    public function setCharacterSet($character_set) {
00062       $this->character_set = $character_set;
00063    }
00064 
00074    public function addFormData($key, $value) {
00075       $this->setMediaType(
00076             new DMMediaType("application", "x-www-form-urlencoded"));
00077       $this->form_data[] = array(
00078          'key' => $key,
00079          'value' => $value
00080       );
00081    }
00082 
00089    public function getFormData() {
00090       return $this->form_data;
00091    }
00092 
00103    public function setFormData($key, $value) {
00104       $count = count($this->form_data);
00105       for ($i = 0; $i < $count; $i++) {
00106          if ($this->form_data[$i]['key'] == $key) {
00107             unset($this->form_data[$i]);
00108          }
00109       }
00110       $this->addFormData($key, $value);
00111    }
00112 
00119    public function getFormDataAsString() {
00120       $str = array();
00121       foreach ($this->form_data as $data) {
00122          $str[] = urlencode($data['key']) . "=" . urlencode($data['value']);
00123       }
00124       return implode("&", $str);
00125    }
00126 
00134    public function getFormValue($key) {
00135       foreach ($this->form_data as $data) {
00136          if ($data['key'] == $key) {
00137             return $data['value'];
00138          }
00139       }
00140       return null;
00141    }
00142 
00150    public function getFormValues($key) {
00151       $values = array();
00152       foreach ($this->form_data as $data) {
00153          if ($data['key'] == $key) {
00154             $values[] = $data['value'];
00155          }
00156       }
00157       return $values;
00158    }
00159 
00163    public function unsetFormData() {
00164       $this->form_data = array();
00165    }
00166 
00171    public final function getMediaType() {
00172       return $this->media_type;
00173    }
00174 
00179    public final function setMediaType(DMMediaType $type) {
00180       $this->media_type = $type;
00181    }
00182 
00183 }
 All Data Structures Functions Variables