Action.php

00001 <?php
00011 abstract class Dsao_Controller_Action extends Zend_Controller_Action
00012 {
00016   private $_config = null;
00017 
00021   private $_helpersArray = array();
00022 
00026   private $_isXmlHttpRequest = null;
00027 
00031   private $_log = null;
00032 
00036   private $_modelClassDefault = null;
00037 
00041   private $_smarty = null;
00042 
00046   private $_user = null;
00047 
00058   public function __call($action, $parameters)
00059   {
00060     // Falls nicht vorhandene Aktion aufgerufen wurde, auf Fehlerseite
00061     // weiterleiten
00062     if (substr($action, -6, 6) == 'Action')
00063     {
00064       return $this->_forward('exception', 'error', 'default');
00065     }
00066 
00067     throw new Dsao_Exception(array(
00068       'message' => 'dsao_controller_action_method_not_found',
00069       'variables' => array('method' => $action),
00070       ), 500);
00071   }
00072 
00076   public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
00077   {
00078     $this->_log = Dsao_Registry::get('log');
00079 
00080     // Konfiguration aus Registry setzen
00081     $this->_config = Dsao_Registry::get('config');
00082 
00083     // Helper instanziieren
00084     $this->_initHelpers();
00085 
00086     parent::__construct($request, $response, $invokeArgs);
00087   }
00088 
00108   protected function _addJsFile($action = null, $controller = null, $module = null)
00109   {
00110     // string, Pfad zur JavaScript-Datei
00111     $path = null;
00112 
00113     $parameters = array(
00114       'Module'      => $module,
00115       'Controller'  => $controller,
00116       'Action'      => $action
00117       );
00118 
00119     foreach ($parameters as $name => $value)
00120     {
00121       // Falls false übergeben wurde, abbrechen
00122       if (false === $value)
00123       {
00124         break;
00125       }
00126 
00127       // Slash anhängen
00128       $path .= '/';
00129 
00130       // Methodenname für Standardparameter
00131       $method = 'get'.$name.'Name';
00132 
00133       $path .= (null === $value ? $this->getRequest()->$method() : $value);
00134     }
00135 
00136     // Falls kein Pfad gebildet wurde
00137     if (!$path)
00138     {
00139       return false;
00140     }
00141 
00142     // /module/controller/action uebergeben, Endung wird automatisch
00143     // hinzugefügt
00144     return $this->getView()->addJsFile($path);
00145   }
00146 
00155   protected function _getModel($modelClass = null)
00156   {
00157     return Dsao_Registry::getModel
00158       ((null === $modelClass ? $this->_modelClassDefault : $modelClass));
00159   }
00160 
00171   protected function _gotoSimple($action, $controller = null, $module = null, array $parameters = array(), $exit = true)
00172   {
00173     $this->getHelper('Redirector')->setExit($exit)
00174       ->gotoSimple($action, $controller, $module, $parameters);
00175   }
00176 
00182   protected function _initHelpers()
00183   {
00184     // Falls dies nicht der erste instanziierte Controller ist
00185     if (0 !== Zend_Controller_Action_HelperBroker::getStack()->count())
00186     {
00187       return;
00188     }
00189 
00190     // Action-Helper initialisieren
00191     Zend_Controller_Action_HelperBroker::addPrefix
00192       ('Dsao_Controller_Action_Helper');
00193 
00194     // Zur Reihenfolge: alle Methoden werden in umgekehrter Reihenfolge
00195     // ausgeführt
00196 
00197     // Renderer (nach unten, damit postDispatch() als letztes ausgeführt wird)
00198     Zend_Controller_Action_HelperBroker::getStaticHelper('Renderer');
00199 
00200     // Garbage-Collector (nach unten, da unwichtig und ohne Abhängigkeiten)
00201     Zend_Controller_Action_HelperBroker::getStaticHelper('GarbageCollector');
00202 
00203     // Menü-Erstellung (braucht Benutzerobjekt)
00204     Zend_Controller_Action_HelperBroker::getStaticHelper('Menu');
00205 
00206     // History (braucht Benutzerobjekt)
00207     $this->_helpersArray['History'] =
00208       Zend_Controller_Action_HelperBroker::getStaticHelper('History');
00209 
00210     // Translator (braucht Benutzerobjekt)
00211     $this->_helpersArray['Translate'] =
00212       Zend_Controller_Action_HelperBroker::getStaticHelper('Translator');
00213 
00214     // Berechtigungsverwaltung (braucht Benutzerobjekt)
00215     Zend_Controller_Action_HelperBroker::getStaticHelper('AccessControl');
00216 
00217     // Authentifizierung (keine Abhängigkeiten, möglichst weit oben, da
00218     // spätere Änderungen auf das Benutzerobjekt keine Wirkung mehr haben)
00219     Zend_Controller_Action_HelperBroker::getStaticHelper('Auth');
00220 
00221     // Session Tokens (braucht URI-Objekt)
00222     $this->_helpersArray['SessionToken'] =
00223       Zend_Controller_Action_HelperBroker::getStaticHelper('SessionToken');
00224 
00225     // URI (kann nach oben, da es keine Abhängigkeiten hat und nur init())
00226     $this->_helpersArray['Uri'] =
00227       Zend_Controller_Action_HelperBroker::getStaticHelper('Uri');
00228   }
00229 
00236   protected function _setDefaultModelClass($modelClass)
00237   {
00238     $this->_modelClassDefault = $modelClass;
00239 
00240     return $this;
00241   }
00242 
00251   public function forward($action, $controller = null, $module = null, array $parameters = array())
00252   {
00253     $this->_forward($action, $controller, $module, $parameters);
00254   }
00255 
00261   public final function getConfig()
00262   {
00263     return $this->_config;
00264   }
00265 
00272   public final function getHelper($helperName)
00273   {
00274     $helperName = (string) $helperName;
00275 
00276     // Falls Helper noch nicht in Array vorhanden
00277     if (!isset($this->_helpersArray[$helperName]))
00278     {
00279       // Falls Helper-Broker noch nicht initialisiert
00280       if (null === $this->_helper)
00281       {
00282         // Bei der Instanziierung des Helper-Brokers werden alle Helper
00283         // neu initialisiert, allerdings ist während dessen das $_helper-
00284         // Objekt des Controllers leer. Also müssen wir über diesen Umweg
00285         // an die Helper herankommen.
00286         // Es werden nur schon vorhandene zurückgegeben, da ansonsten keine
00287         // Bindung an den Controller gegeben wäre
00288         $this->_helpersArray[$helperName] =
00289           Zend_Controller_Action_HelperBroker::getExistingHelper($helperName);
00290       }
00291       else
00292       {
00293         $this->_helpersArray[$helperName] = $this->_helper
00294           ->getHelper($helperName);
00295       }
00296     }
00297 
00298     return $this->_helpersArray[$helperName];
00299   }
00300 
00306   public final function getLog()
00307   {
00308     return $this->_log;
00309   }
00310 
00316   public function getModuleNavigation()
00317   {
00318     return $this->_getModel()->getModuleNavigation();
00319   }
00320 
00326   public final function getTranslate()
00327   {
00328     return $this->getHelper('Translate')->getTranslate();
00329   }
00330 
00336   public final function getUri()
00337   {
00338     return $this->getHelper('Uri')->getUri();
00339   }
00340 
00346   public final function getUser()
00347   {
00348     return $this->_user;
00349   }
00350 
00356   public final function getView()
00357   {
00358     return $this->_smarty;
00359   }
00360 
00368   public final function init()
00369   {
00370     // Smarty instanziieren (braucht Translator)
00371     $this->_smarty = new Dsao_View_Smarty($this->isXmlHttpRequest());
00372 
00373     // Falls Ajax-Anfrage
00374     if ($this->isXmlHttpRequest())
00375     {
00376       // Falls bei der Anfrage eine Callback-Funktion uebergeben wurde
00377       if ($this->_request->getParam('callbackHandler'))
00378       {
00379         $this->_smarty->getAjaxResponse()->setCallbackHandler
00380           ($this->_request->getParam('callbackHandler'));
00381       }
00382     }
00383   }
00384 
00390   public function isXmlHttpRequest()
00391   {
00392     // Falls Eigenschaft noch nicht initialisiert
00393     if (null === $this->_isXmlHttpRequest)
00394     {
00395       $this->_isXmlHttpRequest = $this->_request->isXmlHttpRequest();
00396     }
00397 
00398     return (bool) $this->_isXmlHttpRequest;
00399   }
00400 
00406   public function postDispatch()
00407   {}
00408 
00412   public function preDispatch()
00413   {}
00414 
00423   public function preRedirect()
00424   {}
00425 
00432   public function setUser(Dsao_User $user)
00433   {
00434     $this->_user = $user;
00435   }
00436 }

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