• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • Examples
  • File List
  • File Members

CAS/ProxiedService/Http/Post.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Copyright � 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *               * Redistributions of source code must retain the above copyright notice,
00010  *                       this list of conditions and the following disclaimer.
00011  *               * Redistributions in binary form must reproduce the above copyright notice,
00012  *                       this list of conditions and the following disclaimer in the documentation
00013  *                       and/or other materials provided with the distribution.
00014  *               * Neither the name of the ESUP-Portail consortium & the JA-SIG
00015  *                       Collaborative nor the names of its contributors may be used to endorse or
00016  *                       promote products derived from this software without specific prior
00017  *                       written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00023  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00026  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 }

Generated on Sun Jun 5 2011 19:05:26 for phpCAS by  doxygen 1.7.1