Response.php

00001 <?php
00009 class Dsao_Ajax_Response
00010 {
00014   const JSON = 'application/json';
00015 
00019   const PLAIN = 'text/plain';
00020 
00024   protected $_callbackHandler = null;
00025 
00029   protected $_contentType = null;
00030 
00034   protected $_data = array();
00035 
00039   protected $_messages = array();
00040 
00044   protected $_plainContent = '';
00045 
00053   public function getCallbackHandler()
00054   {
00055     return $this->_callbackHandler;
00056   }
00057 
00065   public function getContent()
00066   {
00067     // Falls reiner Text zurueckgegeben werden soll
00068     if (self::PLAIN == $this->_contentType)
00069     {
00070       return (string) $this->_data;
00071     }
00072     // Ansonsten kodieren
00073     else
00074     {
00075       return Zend_Json::encode(array
00076         (
00077           'callbackHandler' => $this->_callbackHandler,
00078           'data'            => $this->_data,
00079           'messages'        => $this->_messages,
00080         ));
00081     }
00082   }
00083 
00092   public function getContentType()
00093   {
00094     return ($this->_contentType ? $this->_contentType : self::JSON);
00095   }
00096 
00105   public function setCallbackHandler($callbackHandler)
00106   {
00107     $this->_callbackHandler = $callbackHandler;
00108 
00109     return $this;
00110   }
00111 
00122   public function setData($data, $contentType = self::JSON, $overwrite = true)
00123   {
00124     // Falls bereits Daten uebergeben wurden, neue ignorieren, sofern alte
00125     // Daten nicht ueberschrieben werden sollen
00126     if (!$overwrite && !empty($this->_data))
00127     {
00128       return $this;
00129     }
00130 
00131     $this->_data = $data;
00132     $this->_contentType = $contentType;
00133 
00134     return $this;
00135   }
00136 
00145   public function setMessages($messages)
00146   {
00147     // Falls ArrayObjekt uebergeben wurde
00148     if (is_object($messages))
00149     {
00150       $messages = $messages->getArrayCopy();
00151     }
00152 
00153     $this->_messages = $messages;
00154 
00155     return $this;
00156   }
00157 }

Erzeugt am Fri Sep 18 19:04:11 2009 für DSA online - Morgendaemmerung von  doxygen 1.5.7.1