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 
00042    public function getBody() {
00043       return $this->body;
00044    }
00045 
00052    public function setBody($body) {
00053       $this->body = $body;
00054    }
00055 
00059    public function getCharacterSet() {
00060       return $this->character_set;
00061    }
00062 
00066    public function setCharacterSet($character_set) {
00067       $this->character_set = $character_set;
00068    }
00069 
00079    public function addFormData($key, $value) {
00080       $this->setMediaType(
00081             new DMMediaType("application", "x-www-form-urlencoded"));
00082       $this->form_data[] = array(
00083          'key' => $key,
00084          'value' => $value
00085       );
00086    }
00087 
00094    public function getFormData() {
00095       return $this->form_data;
00096    }
00097 
00108    public function setFormData($key, $value) {
00109       $count = count($this->form_data);
00110       for ($i = 0; $i < $count; $i++) {
00111          if ($this->form_data[$i]['key'] == $key) {
00112             unset($this->form_data[$i]);
00113          }
00114       }
00115       $this->addFormData($key, $value);
00116    }
00117 
00124    public function getFormDataAsString() {
00125       $str = array();
00126       foreach ($this->form_data as $data) {
00127          $str[] = urlencode($data['key']) . "=" . urlencode($data['value']);
00128       }
00129       return implode("&", $str);
00130    }
00131 
00139    public function getFormValue($key) {
00140       foreach ($this->form_data as $data) {
00141          if ($data['key'] == $key) {
00142             return $data['value'];
00143          }
00144       }
00145       return null;
00146    }
00147 
00155    public function getFormValues($key) {
00156       $values = array();
00157       foreach ($this->form_data as $data) {
00158          if ($data['key'] == $key) {
00159             $values[] = $data['value'];
00160          }
00161       }
00162       return $values;
00163    }
00164 
00168    public function unsetFormData() {
00169       $this->form_data = array();
00170    }
00171 
00176    public function getMediaType() {
00177       return $this->media_type;
00178    }
00179 
00184    public function setMediaType(DMMediaType $type) {
00185       $this->media_type = $type;
00186    }
00187 
00188 }
 All Data Structures Functions Variables