Development

/branches/1.1/lib/response/sfResponse.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/response/sfResponse.class.php

Revision 9091, 3.8 kB (checked in by FabianLange, 7 years ago)

1.1: fixed @param phpdoc to fit specs in response (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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$
19  */
20 abstract class sfResponse implements Serializable
21 {
22   protected
23     $options    = array(),
24     $dispatcher = null,
25     $content    = '';
26
27   /**
28    * Class constructor.
29    *
30    * @see initialize()
31    */
32   public function __construct(sfEventDispatcher $dispatcher, $options = array())
33   {
34     $this->initialize($dispatcher, $options);
35   }
36
37   /**
38    * Initializes this sfResponse.
39    *
40    * Available options:
41    *
42    *  * logging: Whether to enable logging or not (false by default)
43    *
44    * @param  sfEventDispatcher  $dispatcher  An sfEventDispatcher instance
45    * @param  array              $options     An array of options
46    *
47    * @return bool true, if initialization completes successfully, otherwise false
48    *
49    * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfResponse
50    */
51   public function initialize(sfEventDispatcher $dispatcher, $options = array())
52   {
53     $this->dispatcher = $dispatcher;
54     $this->options = $options;
55
56     if (!isset($this->options['logging']))
57     {
58       $this->options['logging'] = false;
59     }
60   }
61
62   /**
63    * Sets the event dispatcher.
64    *
65    * @param sfEventDispatcher $dispatcher  An sfEventDispatcher instance
66    */
67   public function setEventDispatcher(sfEventDispatcher $dispatcher)
68   {
69     $this->dispatcher = $dispatcher;
70   }
71
72   /**
73    * Sets the response content
74    *
75    * @param string $content
76    */
77   public function setContent($content)
78   {
79     $this->content = $content;
80   }
81
82   /**
83    * Gets the current response content
84    *
85    * @return string Content
86    */
87   public function getContent()
88   {
89     return $this->content;
90   }
91
92   /**
93    * Outputs the response content
94    */
95   public function sendContent()
96   {
97     $event = $this->dispatcher->filter(new sfEvent($this, 'response.filter_content'), $this->getContent());
98     $content = $event->getReturnValue();
99
100     if ($this->options['logging'])
101     {
102       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content)))));
103     }
104
105     echo $content;
106   }
107
108   /**
109    * Sends the content.
110    */
111   public function send()
112   {
113     $this->sendContent();
114   }
115
116   public function getOptions()
117   {
118     return $this->options;
119   }
120
121   /**
122    * Calls methods defined via sfEventDispatcher.
123    *
124    * @param string $method     The method name
125    * @param array  $arguments  The method arguments
126    *
127    * @return mixed The returned value of the called method
128    *
129    * @throws <b>sfException</b> If the calls fails
130    */
131   public function __call($method, $arguments)
132   {
133     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'response.method_not_found', array('method' => $method, 'arguments' => $arguments)));
134     if (!$event->isProcessed())
135     {
136       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
137     }
138
139     return $event->getReturnValue();
140   }
141
142   /**
143    * Serializes the current instance.
144    *
145    * @return array Objects instance
146    */
147   public function serialize()
148   {
149     return serialize($this->content);
150   }
151
152   /**
153    * Unserializes a sfResponse instance.
154    *
155    * You need to inject a dispatcher after unserializing a sfResponse instance.
156    *
157    * @param string $serialized  A serialized sfResponse instance
158    *
159    */
160   public function unserialize($serialized)
161   {
162     $this->content = unserialize($serialized);
163   }
164 }
165
Note: See TracBrowser for help on using the browser.