[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * sfResponse provides methods for manipulating client response information such 13 * as headers, cookies and content. 14 * 15 * @package symfony 16 * @subpackage response 17 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 18 * @version SVN: $Id: sfResponse.class.php 3250 2007-01-12 20:09:11Z fabien $ 19 */ 20 abstract class sfResponse 21 { 22 protected 23 $parameterHolder = null, 24 $context = null, 25 $content = ''; 26 27 /** 28 * Initializes this sfResponse. 29 * 30 * @param sfContext A sfContext instance 31 * 32 * @return boolean true, if initialization completes successfully, otherwise false 33 * 34 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 35 */ 36 public function initialize($context, $parameters = array()) 37 { 38 $this->context = $context; 39 40 $this->parameterHolder = new sfParameterHolder(); 41 $this->parameterHolder->add($parameters); 42 } 43 44 /** 45 * Sets the context for the current response. 46 * 47 * @param sfContext A sfContext instance 48 */ 49 public function setContext($context) 50 { 51 $this->context = $context; 52 } 53 54 /** 55 * Retrieves the current application context. 56 * 57 * @return sfContext The application context 58 */ 59 public function getContext() 60 { 61 return $this->context; 62 } 63 64 /** 65 * Retrieves a new sfResponse implementation instance. 66 * 67 * @param string A sfResponse implementation name 68 * 69 * @return sfResponse A sfResponse implementation instance 70 * 71 * @throws <b>sfFactoryException</b> If a request implementation instance cannot be created 72 */ 73 public static function newInstance($class) 74 { 75 // the class exists 76 $object = new $class(); 77 78 if (!($object instanceof sfResponse)) 79 { 80 // the class name is of the wrong type 81 $error = 'Class "%s" is not of the type sfResponse'; 82 $error = sprintf($error, $class); 83 84 throw new sfFactoryException($error); 85 } 86 87 return $object; 88 } 89 90 /** 91 * Sets the response content 92 * 93 * @param string Content 94 */ 95 public function setContent($content) 96 { 97 $this->content = $content; 98 } 99 100 /** 101 * Gets the current response content 102 * 103 * @return string Content 104 */ 105 public function getContent() 106 { 107 return $this->content; 108 } 109 110 /** 111 * Outputs the response content 112 */ 113 public function sendContent() 114 { 115 if (sfConfig::get('sf_logging_enabled')) 116 { 117 $this->getContext()->getLogger()->info('{sfResponse} send content ('.strlen($this->content).' o)'); 118 } 119 120 echo $this->content; 121 } 122 123 /** 124 * Retrieves the parameters from the current response. 125 * 126 * @return sfParameterHolder List of parameters 127 */ 128 public function getParameterHolder() 129 { 130 return $this->parameterHolder; 131 } 132 133 /** 134 * Retrieves a parameter from the current response. 135 * 136 * @param string A parameter name 137 * @param string A default paramter value 138 * @param string Namespace for the current response 139 * 140 * @return mixed A parameter value 141 */ 142 public function getParameter($name, $default = null, $ns = null) 143 { 144 return $this->parameterHolder->get($name, $default, $ns); 145 } 146 147 /** 148 * Indicates whether or not a parameter exist for the current response. 149 * 150 * @param string A parameter name 151 * @param string Namespace for the current response 152 * 153 * @return boolean true, if the parameter exists otherwise false 154 */ 155 public function hasParameter($name, $ns = null) 156 { 157 return $this->parameterHolder->has($name, $ns); 158 } 159 160 /** 161 * Sets a parameter for the current response. 162 * 163 * @param string A parameter name 164 * @param string The parameter value to be set 165 * @param string Namespace for the current response 166 */ 167 public function setParameter($name, $value, $ns = null) 168 { 169 $this->parameterHolder->set($name, $value, $ns); 170 } 171 172 /** 173 * Executes the shutdown procedure. 174 * 175 */ 176 abstract function shutdown(); 177 178 /** 179 * Overloads a given method. 180 * 181 * @param string Method name 182 * @param string Method arguments 183 * 184 * @return mixed User function callback 185 * 186 * @throws <b>sfException</b> If the calls fails 187 */ 188 public function __call($method, $arguments) 189 { 190 if (!$callable = sfMixer::getCallable('sfResponse:'.$method)) 191 { 192 throw new sfException(sprintf('Call to undefined method sfResponse::%s', $method)); 193 } 194 195 array_unshift($arguments, $this); 196 197 return call_user_func_array($callable, $arguments); 198 } 199 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |