123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- abstract class sfResponse implements Serializable
- {
- protected
- $options = array(),
- $dispatcher = null,
- $content = '';
-
- public function __construct(sfEventDispatcher $dispatcher, $options = array())
- {
- $this->initialize($dispatcher, $options);
- }
-
- public function initialize(sfEventDispatcher $dispatcher, $options = array())
- {
- $this->dispatcher = $dispatcher;
- $this->options = $options;
- if (!isset($this->options['logging']))
- {
- $this->options['logging'] = false;
- }
- }
-
- public function setEventDispatcher(sfEventDispatcher $dispatcher)
- {
- $this->dispatcher = $dispatcher;
- }
-
- public function setContent($content)
- {
- $this->content = $content;
- }
-
- public function getContent()
- {
- return $this->content;
- }
-
- public function sendContent()
- {
- $event = $this->dispatcher->filter(new sfEvent($this, 'response.filter_content'), $this->getContent());
- $content = $event->getReturnValue();
- if ($this->options['logging'])
- {
- $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content)))));
- }
- echo $content;
- }
-
- public function send()
- {
- $this->sendContent();
- }
- public function getOptions()
- {
- return $this->options;
- }
-
- public function __call($method, $arguments)
- {
- $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'response.method_not_found', array('method' => $method, 'arguments' => $arguments)));
- if (!$event->isProcessed())
- {
- throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
- }
- return $event->getReturnValue();
- }
-
- public function serialize()
- {
- return serialize($this->content);
- }
-
- public function unserialize($serialized)
- {
- $this->content = unserialize($serialized);
- }
- }
|