Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 require_once(dirname(__FILE__).'/Abstract.php');
00032 include_once(dirname(__FILE__).'/../Exception.php');
00033 include_once(dirname(__FILE__).'/../../InvalidArgumentException.php');
00034 include_once(dirname(__FILE__).'/../../OutOfSequenceException.php');
00035
00068 class CAS_ProxiedService_Http_Post
00069 extends CAS_ProxiedService_Http_Abstract
00070 {
00071
00077 private $_contentType;
00078
00084 private $_body;
00085
00093 public function setContentType ($contentType) {
00094 if ($this->hasBeenSent())
00095 throw new CAS_OutOfSequenceException('Cannot set the content type, request already sent.');
00096
00097 $this->_contentType = $contentType;
00098 }
00099
00107 public function setBody ($body) {
00108 if ($this->hasBeenSent())
00109 throw new CAS_OutOfSequenceException('Cannot set the body, request already sent.');
00110
00111 $this->_body = $body;
00112 }
00113
00120 protected function populateRequest (CAS_RequestInterface $request) {
00121 if (empty($this->_contentType) && !empty($this->_body))
00122 throw new CAS_ProxiedService_Exception("If you pass a POST body, you must specify a content type via ".get_class($this).'->setContentType($contentType).');
00123
00124 $request->makePost();
00125 if (!empty($this->_body)) {
00126 $request->addHeader('Content-Type: '.$this->_contentType);
00127 $request->addHeader('Content-Length: '.strlen($this->_body));
00128 $request->setPostBody($this->_body);
00129 }
00130 }
00131
00132
00133 }