| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActionController 13 * @subpackage Base 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 * @deprecated Please use AkDispatcher on your public/index.php instead 18 */ 19 20 defined('AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE') ? null : 21 define('AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE', true); 22 23 defined('AK_WEB_REQUEST_START_SESSION_ON_INSTANTIATE') ? null : 24 define('AK_WEB_REQUEST_START_SESSION_ON_INSTANTIATE', true); 25 26 defined('AK_WEB_REQUEST_ENABLE_INTERNATIONALIZATION_SUPPORT_ON_INSTANTIATE') ? null : 27 define('AK_WEB_REQUEST_ENABLE_INTERNATIONALIZATION_SUPPORT_ON_INSTANTIATE', true); 28 29 /** 30 * Http Web Browser requests are handled by this class 31 */ 32 class AkWebRequest extends AkActionController 33 { 34 var $__ParentController; 35 var $AppController; 36 37 function init(&$ParentController) 38 { 39 $this->__ParentController =& $ParentController; 40 41 $this->__ParentController->_ssl_requirement ? $this->__ParentController->beforeFilter('_ensureProperProtocol') : false; 42 43 if($this->__ParentController->_autoIncludePaginator){ 44 require_once (AK_LIB_DIR.DS.'AkActionController'.DS.'AkPaginator.php'); 45 } 46 47 if(AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE){ 48 $this->__ParentController->__connectToDatabase(); 49 } 50 51 if(AK_WEB_REQUEST_START_SESSION_ON_INSTANTIATE){ 52 $this->__ParentController->__startSession(); 53 } 54 55 require_once (AK_LIB_DIR.DS.'AkRequest.php'); 56 $this->__ParentController->Request =& AkRequest(); 57 58 if(AK_WEB_REQUEST_ENABLE_INTERNATIONALIZATION_SUPPORT_ON_INSTANTIATE && AK_AVAILABLE_LOCALES != 'en'){ 59 $this->__ParentController->__enableInternationalizationSupport(); 60 } 61 62 $this->__ParentController->__mapRoutes(); 63 64 } 65 66 67 function handle() 68 { 69 $this->__ParentController->params = $this->__ParentController->Request->getParams(); 70 71 $this->_file_name = AkInflector::underscore($this->__ParentController->params['controller']).'_controller.php'; 72 $this->_class_name = AkInflector::camelize($this->__ParentController->params['controller']).'Controller'; 73 74 $this->_includeController(); 75 76 Ak::t('Akelos'); // We need to get locales ready 77 78 $class_name = $this->_class_name; 79 $this->AppController =& new $class_name(array('controller'=>true)); 80 81 if(!empty($this->AppController)){ 82 $this->AppController->beforeFilter('instantiateHelpers'); 83 } 84 85 // Mixing bootstrap controller attributes with this controller attributes 86 foreach (array_keys(get_class_vars('AkActionController')) as $varname){ 87 if(empty($this->AppController->$varname)){ 88 $this->AppController->$varname =& $this->__ParentController->$varname; 89 } 90 } 91 92 empty($this->__ParentController->params) ? 93 ($this->__ParentController->params = $this->__ParentController->Request->getParams()) : null; 94 95 $action_name = $this->_getActionName(); 96 97 $this->_before($this->AppController); 98 99 $this->AppController->performActionWithFilters($action_name); 100 101 $this->_after($this->AppController); 102 103 $this->AppController->Response->outputResults(); 104 105 } 106 107 108 function _before(&$Controller) 109 { 110 empty($Controller->model) ? ($Controller->model = $Controller->params['controller']) : null; 111 empty($Controller->models) ? ($Controller->models = array()) : null; 112 empty($Controller->_assigns) ? ($Controller->_assigns = array()) : null; 113 empty($Controller->_default_render_status_code) ? ($Controller->_default_render_status_code = 200) : null; 114 $Controller->_enableLayoutOnRender = 115 !isset($Controller->_enableLayoutOnRender) ? true : $Controller->_enableLayoutOnRender; 116 117 empty($Controller->cookies) && isset($_COOKIE) ? ($Controller->cookies =& $_COOKIE) : null; 118 119 if(empty($Controller->Response)){ 120 require_once (AK_LIB_DIR.DS.'AkResponse.php'); 121 $Controller->Response =& AkResponse(); 122 } 123 124 if(empty($Controller->Template)){ 125 require_once (AK_LIB_DIR.DS.'AkActionView.php'); 126 require_once (AK_LIB_DIR.DS.'AkActionView'.DS.'AkPhpTemplateHandler.php'); 127 $Controller->Template =& new AkActionView(AK_APP_DIR.DS.'views'.DS.$Controller->Request->getController(), 128 $Controller->Request->getParameters(),$Controller->Request->getController()); 129 130 $Controller->Template->_controllerInstance =& $Controller; 131 $Controller->Template->_registerTemplateHandler('tpl','AkPhpTemplateHandler'); 132 } 133 134 $Controller->passed_args = !isset($Controller->Request->pass)? array() : $Controller->Request->pass; 135 136 Ak::loadPlugins(); 137 138 $Controller->instantiateIncludedModelClasses(); 139 140 if(isset($Controller->api)){ 141 require_once (AK_LIB_DIR.DS.'AkActionWebService.php'); 142 $Controller->aroundFilter(new AkActionWebService($Controller)); 143 } 144 } 145 146 function _after(&$Controller) 147 { 148 $Controller->_handleFlashAttribute(); 149 if (!$Controller->_hasPerformed()){ 150 $Controller->_enableLayoutOnRender ? $Controller->renderWithLayout() : $Controller->renderWithoutLayout(); 151 } 152 if(!AK_DESKTOP && defined('AK_ENABLE_STRICT_XHTML_VALIDATION') && AK_ENABLE_STRICT_XHTML_VALIDATION || !empty($Controller->validate_output)){ 153 $Controller->_validateGeneratedXhtml(); 154 } 155 } 156 157 158 159 function _includeController() 160 { 161 $controller_path = AK_CONTROLLERS_DIR.DS.$this->_file_name; 162 if(!file_exists($controller_path)){ 163 $this->_raiseError( 164 Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for '. 165 'the controller %controller_class_name', 166 array('%controller_file_name'=>$this->_file_name, 167 '%controller_class_name'=>$this->_class_name))); 168 } 169 require_once(AK_APP_DIR.DS.'application_controller.php'); 170 require_once($controller_path); 171 if(!class_exists($this->_class_name)){ 172 $this->_raiseError(Ak::t('Controller <i>%controller_name</i> does not exist', 173 array('%controller_name' => $this->_class_name))); 174 } 175 } 176 177 function _getActionName() 178 { 179 $this->AppController->_action_name = 180 empty($this->AppController->_action_name) ? 181 (AkInflector::underscore($this->AppController->params['action'])) : 182 $this->AppController->_action_name; 183 184 if ($this->AppController->_action_name[0] == '_' || 185 !method_exists($this->AppController, $this->AppController->_action_name)){ 186 $this->_raiseError(Ak::t('Action <i>%action</i> does not exist for controller <i>%controller_name</i>', 187 array('%controller_name'=>$this->_class_name,'%action'=>$this->AppController->_action_name))); 188 } 189 return $this->AppController->_action_name; 190 } 191 192 function _raiseError($error) 193 { 194 if(AK_LOG_EVENTS){ 195 empty($this->_Logger) && ($this->_Logger =& Ak::getLogger()); 196 $this->_Logger->error($error); 197 } 198 if(AK_ENVIRONMENT == 'development'){ 199 header('HTTP/1.1 404 Not Found'); 200 trigger_error($error, E_USER_ERROR); 201 }elseif(@include(AK_PUBLIC_DIR.DS.'404.php')){ 202 exit; 203 }else{ 204 header('HTTP/1.1 404 Not Found'); 205 die('404 Not Found'); 206 } 207 } 208 209 } 210 211 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |