Changeset 357
- Timestamp:
- 09/14/07 16:24:40 (1 year ago)
- Files:
-
- trunk/app/controllers/framework_setup_controller.php (modified) (1 diff)
- trunk/app/models/framework_setup.php (modified) (3 diffs)
- trunk/config/boot.php (modified) (1 diff)
- trunk/lib/AkActionController.php (modified) (18 diffs)
- trunk/lib/AkActionController/AkWebRequest.php (modified) (1 diff)
- trunk/lib/AkActionView/helpers/asset_tag_helper.php (modified) (1 diff)
- trunk/lib/AkActionView/helpers/pagination_helper.php (modified) (1 diff)
- trunk/lib/AkActiveRecord.php (modified) (2 diffs)
- trunk/lib/AkDispatcher.php (added)
- trunk/lib/AkLocaleManager.php (modified) (2 diffs)
- trunk/lib/AkObject.php (modified) (3 diffs)
- trunk/lib/AkRequest.php (modified) (10 diffs)
- trunk/lib/AkResponse.php (modified) (6 diffs)
- trunk/lib/AkRouter.php (modified) (2 diffs)
- trunk/lib/constants.php (modified) (1 diff)
- trunk/public/index.php (modified) (2 diffs)
- trunk/test/fixtures/public/index.php (modified) (1 diff)
- trunk/test/unit/lib/AkActionView/helpers/asset_tag_helper.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/framework_setup_controller.php
r324 r357 24 24 25 25 include_once(AK_CONFIG_DIR.DS.'boot.php'); 26 require_once(AK_LIB_DIR.DS.'AkObject.php'); 27 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 28 require_once(AK_LIB_DIR.DS.'Ak.php'); 29 require_once(AK_LIB_DIR.DS.'AkActionController.php'); 26 30 27 31 $_GET['controller'] = 'framework_setup'; trunk/app/models/framework_setup.php
r339 r357 241 241 function runFrameworkInstaller() 242 242 { 243 static $unique_dsn = array(); 243 244 require_once(AK_LIB_DIR.DS.'AkInstaller.php'); 244 245 require_once(AK_APP_DIR.DS.'installers'.DS.'framework_installer.php'); 245 246 246 247 foreach (array('production', 'development') as $mode){ 247 $db_conn =& Ak::db($this->_getDsn($mode), $mode); 248 $installer =& new FrameworkInstaller($db_conn); 249 $installer->install(null, array('mode' => $mode)); 248 $dsn = $this->_getDsn($mode); 249 if(!isset($unique_dsn[$dsn])){ 250 $db_conn =& Ak::db($dsn, $mode); 251 $installer =& new FrameworkInstaller($db_conn); 252 $installer->install(null, array('mode' => $mode)); 253 $unique_dsn[$dsn] = true; 254 } 250 255 } 251 256 … … 360 365 361 366 $settings['%locales'] = $this->getLocales(); 362 367 363 368 $settings['%AK_URL_REWRITING'] = $this->isUrlRewriteEnabled() ? '' : "// The web configuration wizard could not detect if you have mod_rewrite enabled. \n// If that is the case, you should uncomment the next line line for better performance. \n// "; 364 369 $settings['%AK_FRAMEWORK_DIR'] = defined('AK_FRAMEWORK_DIR') ? … … 562 567 'ftp_host' => $this->getFtpHost(), 563 568 'ftp_path' => $this->getFtpPath(), 564 569 565 570 'random' => Ak::randomString(), 566 571 ); trunk/config/boot.php
r296 r357 22 22 23 23 require_once(AK_LIB_DIR.DS.'constants.php'); 24 require_once(AK_LIB_DIR.DS.'Ak.php');25 require_once(AK_LIB_DIR.DS.'AkActionController.php');26 24 27 25 ?> trunk/lib/AkActionController.php
r346 r357 8 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 9 // +----------------------------------------------------------------------+ 10 11 if(!class_exists('AkActionController')){ 12 13 require_once(AK_LIB_DIR.DS.'AkObject.php'); 14 15 defined('AK_HIGH_LOAD_MODE') ? null : define('AK_HIGH_LOAD_MODE', false); 10 16 11 17 /** … … 16 22 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 23 */ 18 19 require_once(AK_LIB_DIR.DS.'Ak.php'); 20 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 21 require_once(AK_LIB_DIR.DS.'AkObject.php'); 22 24 23 25 class AkActionController extends AkObject 24 26 { 25 var $_ _database_connection_available = false;26 var $_ _session_handler = AK_SESSION_HANDLER;27 var $_ _session_available = false;28 var $ __internationalization_support_enabled= false;29 27 var $_high_load_mode = AK_HIGH_LOAD_MODE; 28 var $_enable_plugins = true; 29 var $_auto_instantiate_models = true; 30 var $validate_output = false; 31 30 32 var $_ssl_requirement = false; 31 33 … … 39 41 * Protected instance variable cache 40 42 */ 41 var $_protected_variables_cache ;43 var $_protected_variables_cache = array(); 42 44 43 45 /** … … 48 50 * $this->_asset_host = 'http://assets.example.com'; 49 51 */ 50 var $_asset_host = ''; 51 52 /** 53 * All Requests are considered local by default, so everyone will be exposed 54 * to detailed debugging screens on errors. 55 * When the application is ready to go public, this should be set to false, 56 * and the protected method <tt>isLocalRequest()</tt> 57 * should instead be implemented in the controller to determine when debugging 58 * screens should be shown. 59 */ 60 var $_consider_all_requests_local = true; 61 62 /** 63 * Enable or disable the collection of failure information for RoutingErrors. 64 * This information can be extremely useful when tweaking custom routes, but is 65 * pointless once routes have been tested and verified. 66 */ 67 var $_debug_routes = true; 68 69 /** 70 * Template root determines the base from which template references will be made. 71 * So a call to $this->render("test/template"); 72 * will be converted to "$this->_template_root/test/template.tpl.php". 73 */ 74 var $_template_root; 75 76 /** 77 * The logger is used for generating information on the action run-time 78 * (including benchmarking) if available. 79 * Can be set to null for no logging. Compatible with Log4r loggers. 80 * @todo add Log calls 81 */ 82 var $Logger; 52 var $asset_host = AK_ASSET_HOST; 53 54 55 var $_Logger; 83 56 84 57 /** … … 141 114 var $cookies; 142 115 143 var $_autoIncludePaginator = true;144 145 116 var $helpers = 'default'; 146 117 … … 153 124 var $web_service_apis = array(); 154 125 155 function handleRequest($options = array()) 156 { 157 $default_options = array( 158 'request_type'=>AK_ACTION_CONTROLLER_DEFAULT_REQUEST_TYPE, 159 'controller'=>false, 160 'action'=>AK_ACTION_CONTROLLER_DEFAULT_ACTION 161 ); 162 163 $options = array_merge($default_options, $options); 164 165 if ($options['controller'] === false) { 166 $request_type = 'Ak'.AkInflector::camelize($options['request_type']); 167 if(file_exists(AK_LIB_DIR.DS.'AkActionController'.DS.$request_type.'.php')){ 168 require_once(AK_LIB_DIR.DS.'AkActionController'.DS.$request_type.'.php'); 169 if(class_exists($request_type)){ 170 $$request_type =& new $request_type(); 171 $$request_type->init($this); 172 $$request_type->handle(); 173 return ; 174 } 126 /** 127 * Old fashioned way of dispatching requests. Please use AkDispatcher or roll your own. 128 * 129 * @deprecated 130 */ 131 function handleRequest() 132 { 133 AK_LOG_EVENTS && empty($this->_Logger) ? ($this->_Logger =& Ak::getLogger()) : null; 134 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->warning('Using deprecated request dispatcher AkActionController::handleRequest. Use to AkDispatcher + AkDispatcher::dispatch instead.') : null; 135 require_once(AK_LIB_DIR.DS.'AkDispatcher.php'); 136 $Dispatcher =& new AkDispatcher(); 137 $Dispatcher->dispatch(); 138 } 139 140 function process(&$Request, &$Response) 141 { 142 AK_LOG_EVENTS && empty($this->_Logger) ? ($this->_Logger =& Ak::getLogger()) : null; 143 144 $this->Request =& $Request; 145 $this->Response =& $Response; 146 $this->params =& $this->Request->getParams(); 147 $this->_action_name = $this->Request->getAction(); 148 149 if(!method_exists($this, $this->_action_name)){ 150 trigger_error(Ak::t('Controller <i>%controller_name</i> can\'t handle action %action_name', 151 array( 152 '%controller_name' => $this->getControllerName(), 153 '%action_name' => $this->_action_name, 154 )), E_USER_ERROR); 155 } 156 157 Ak::t('Akelos'); // We need to get locales ready 158 159 if($this->_high_load_mode !== true){ 160 161 // Before filters 162 if(!empty($this->helpers)){ 163 $this->beforeFilter('instantiateHelpers'); 175 164 } 176 trigger_error(Ak::t('There is no support for %request_type requests',array('%request_type'=>$request_type))); 177 } 178 } 179 165 if(!empty($this->_enable_plugins)){ 166 $this->beforeFilter('loadPlugins'); 167 } 168 if(!empty($this->_auto_instantiate_models)){ 169 $this->beforeFilter('instantiateIncludedModelClasses'); 170 } 171 }else{ 172 $this->_enableLayoutOnRender = false; 173 } 174 175 $this->beforeFilter('_ensureProperProtocol'); 176 177 // After filters 178 $this->afterFilter('_handleFlashAttribute'); 179 180 if(!empty($this->validate_output)){ 181 $this->beforeFilter('_validateGeneratedXhtml'); 182 183 } 184 185 $this->_loadActionView(); 186 187 if(isset($this->api)){ 188 require_once(AK_LIB_DIR.DS.'AkActionWebService.php'); 189 $this->aroundFilter(new AkActionWebService($this)); 190 } 191 192 $this->performActionWithFilters($this->_action_name); 193 194 if (!$this->_hasPerformed()){ 195 $this->_enableLayoutOnRender ? $this->renderWithLayout() : $this->renderWithoutLayout(); 196 } 197 198 $this->Response->outputResults(); 199 } 200 201 function _loadActionView() 202 { 203 empty($this->_assigns) ? ($this->_assigns = array()) : null; 204 empty($this->_default_render_status_code) ? ($this->_default_render_status_code = 200) : null; 205 $this->_enableLayoutOnRender = !isset($this->_enableLayoutOnRender) ? true : $this->_enableLayoutOnRender; 206 $this->passed_args = !isset($this->Request->pass)? array() : $this->Request->pass; 207 empty($this->cookies) && isset($_COOKIE) ? ($this->cookies =& $_COOKIE) : null; 208 209 if(empty($this->Template)){ 210 require_once(AK_LIB_DIR.DS.'AkActionView.php'); 211 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkPhpTemplateHandler.php'); 212 $this->Template =& new AkActionView(AK_APP_DIR.DS.'views'.DS.$this->Request->getController(), 213 $this->Request->getParameters(),$this->Request->getController()); 214 215 $this->Template->_controllerInstance =& $this; 216 $this->Template->_registerTemplateHandler('tpl','AkPhpTemplateHandler'); 217 } 218 } 219 220 function loadPlugins() 221 { 222 Ak::loadPlugins(); 223 } 180 224 181 225 /** … … 287 331 } 288 332 289 function instantiateIncludedModelClasses( $models = null)333 function instantiateIncludedModelClasses() 290 334 { 291 335 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php'); 292 336 require_once(AK_APP_DIR.DS.'shared_model.php'); 293 337 294 $models = empty($models) ? array_unique(array_merge( 338 empty($this->model) ? ($this->model = $this->params['controller']) : null; 339 empty($this->models) ? ($this->models = array()) : null; 340 341 $models =array_unique(array_merge( 295 342 Ak::import($this->model), 296 Ak::import($this->models))) : $models;343 Ak::import($this->models))); 297 344 298 345 foreach ($models as $model){ … … 466 513 function render($options = null, $status = 200) 467 514 { 468 Ak::profile('Entering into '.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__);469 470 515 if(empty($options['partial']) && $this->_hasPerformed()){ 471 516 $this->_doubleRenderError(Ak::t("Can only render or redirect once per action")); … … 477 522 // Ror Backwards compatibility 478 523 if(!is_array($options)){ 479 Ak::profile('Enterind on render file '.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__);480 524 return $this->renderFile(empty($options) ? $this->getDefaultTemplateName() : $options, $status, true); 481 525 } … … 544 588 $this->_assertExistanceOfTemplateFile($template_path); 545 589 } 546 if (!empty($this->Logger)) { 547 $this->Logger->info("Rendering $template_path" . (!empty($status) ? " ($status)" : '')); 548 } 549 590 591 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Rendering $this->full_template_path" . (!empty($status) ? " ($status)":'')) : null; 592 550 593 return $this->renderText($this->Template->renderFile($template_path, $use_full_path, $locals), $status); 551 594 } … … 602 645 } 603 646 604 function renderWithoutLayout($template_name , $status = null)647 function renderWithoutLayout($template_name = null, $status = null) 605 648 { 606 649 $template_name = empty($template_name) ? $this->getDefaultTemplateName() : $template_name; … … 628 671 function _addInstanceVariablesToAssigns() 629 672 { 630 static $_protected_variables_cache = array(); 631 $_protected_variables_cache = array_merge($_protected_variables_cache, $this->_getProtectedInstanceVariables()); 632 633 foreach (array_diff(array_keys(get_object_vars($this)), $_protected_variables_cache) as $attribute){ 673 $this->_protected_variables_cache = array_merge($this->_protected_variables_cache, $this->_getProtectedInstanceVariables()); 674 675 foreach (array_diff(array_keys(get_object_vars($this)), $this->_protected_variables_cache) as $attribute){ 634 676 if($attribute[0] != '_'){ 635 677 $this->_assigns[$attribute] =& $this->$attribute; … … 686 728 $this->_doubleRenderError(); 687 729 } 688 if(!empty($this->Logger)){ 689 $this->Logger->info('Redirected to '.$options); 690 } 730 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message('Redirected to '.$options) : null; 691 731 $this->_handleFlashAttribute(); 692 732 $this->Response->redirect($options); … … 1832 1872 } 1833 1873 1874 1834 1875 function _callFilters(&$filters, $method = '') 1835 1876 { … … 1845 1886 $filter_result = $filter->filter($this); 1846 1887 }else{ 1847 trigger_error(Ak::t(' Filters need to be a method name, or class implementing a static filter method'), E_USER_WARNING);1888 trigger_error(Ak::t('Invalid filter %filter. Filters need to be a method name or a class implementing a static filter method', array('%filter'=>$filter)), E_USER_WARNING); 1848 1889 } 1849 1890 … … 1955 1996 } 1956 1997 1957 1958 1959 /**1960 * This methods are used before triggering an Application Controller1961 */1962 function __connectToDatabase()1963 {1964 global $dsn;1965 if(!empty($dsn)){1966 Ak::db($dsn);1967 $this->__database_connection_available = AK_DATABASE_CONNECTION_AVAILABLE;1968 }1969 }1970 1971 function __startSession()1972 {1973 if($this->__session_available === false){1974 if($this->__session_handler == 1 && $this->__database_connection_available){1975 require_once(AK_LIB_DIR.DS.'AkDbSession.php');1976 1977 $AkDbSession = new AkDbSession();1978 $AkDbSession->session_life = AK_SESSION_EXPIRE;1979 session_set_save_handler (1980 array(&$AkDbSession, '_open'),1981 array(&$AkDbSession, '_close'),1982 array(&$AkDbSession, '_read'),1983 array(&$AkDbSession, '_write'),1984 array(&$AkDbSession, '_destroy'),1985 array(&$AkDbSession, '_gc')1986 );1987 }1988 @session_start();1989 }1990 $this->__session_available = isset($_SESSION);1991 1992 if($this->__session_available){1993 $this->session =& $_SESSION;1994 }1995 }1996 1997 function __enableInternationalizationSupport()1998 {1999 require_once(AK_LIB_DIR.DS.'AkLocaleManager.php');2000 2001 $LocaleManager = new AkLocaleManager();2002 2003 $LocaleManager->init();2004 $LocaleManager->initApplicationInternationalization($this->Request);2005 2006 $this->__internationalization_support_enabled = true;2007 }2008 2009 function __mapRoutes()2010 {2011 require_once(AK_LIB_DIR.DS.'AkRouter.php');2012 if(is_file(AK_ROUTES_MAPPING_FILE)){2013 $Map =& AkRouter();2014 include(AK_ROUTES_MAPPING_FILE);2015 // Set this routes for being used via Ak::toUrl2016 Ak::toUrl($Map,true);2017 $this->Request->checkForRoutedRequests($Map);2018 }2019 }2020 1998 2021 1999 … … 2505 2483 function redirectToLocale($locale) 2506 2484 { 2507 if($this-> __internationalization_support_enabled){2485 if($this->Request->__internationalization_support_enabled){ 2508 2486 $lang = isset($this->params['lang']) ? $this->params['lang'] : $locale; 2509 2487 … … 2550 2528 } 2551 2529 2530 } 2531 2552 2532 ?> trunk/lib/AkActionController/AkWebRequest.php
r350 r357 15 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 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 17 18 */ 18 19 trunk/lib/AkActionView/helpers/asset_tag_helper.php
r293 r357 223 223 $source = !strstr($source,'.') ? "$source.$ext" : $source; 224 224 $source = !preg_match('/^[-a-z]+:\/\//',$source) ? AK_ASSET_URL_PREFIX.$source : $source; 225 $source = strstr($source,':') ? $source : AK_ASSET_HOST.$source;225 $source = strstr($source,':') ? $source : $this->_controller->asset_host.$source; 226 226 $source = substr($source,0,2) == '//' ? substr($source,1) : $source; 227 227 trunk/lib/AkActionView/helpers/pagination_helper.php
r285 r357 19 19 20 20 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkActionViewHelper.php'); 21 21 require_once(AK_LIB_DIR.DS.'AkActionController'.DS.'AkPaginator.php'); 22 22 23 class PaginationHelper extends AkActionViewHelper 23 24 { trunk/lib/AkActiveRecord.php
r350 r357 4569 4569 { 4570 4570 $class_name = AkInflector::camelize($behaviour); 4571 return !file_exists(AK_APP_BEHAVIOURS_DIR.DS.'ActsAs'.$class_name.'.php') && !class_exists('ActsAs'.$class_name) ?4571 return file_exists(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkActsAs'.$class_name.'.php') && !class_exists('ActsAs'.$class_name) ? 4572 4572 'AkActsAs'.$class_name : 'ActsAs'.$class_name; 4573 4573 } … … 4582 4582 include_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.$class_name.'.php'); 4583 4583 }else{ 4584 include_once(AK_APP_ BEHAVIOURS_DIR.DS.$class_name.'.php');4584 include_once(AK_APP_PLUGINS_DIR.DS.AkInflector::underscore($class_name).DS.'lib'.DS.$class_name.'.php'); 4585 4585 } 4586 4586 } trunk/lib/AkLocaleManager.php
r285 r357 43 43 { 44 44 static $available_locales; 45 Ak::profile(__CLASS__.'::'.__FUNCTION__);46 45 47 46 if(empty($available_locales)){ … … 62 61 function _parseLocaleConfigString($locale_settings) 63 62 { 64 Ak::profile(__CLASS__.'::'.__FUNCTION__);65 63 $locale_settings = trim(str_replace(' ','',$locale_settings)); 66 64 $locale_settings = str_replace(array(';','(',')'), array(',','~','',''),$locale_settings); trunk/lib/AkObject.php
r285 r357 17 17 */ 18 18 19 if(! defined('AK_OBJECT_CLASS_INCLUDED')){ define('AK_OBJECT_CLASS_INCLUDED',true); // Class overriding trick19 if(!class_exists('AkObject')){ 20 20 21 21 /** … … 148 148 } 149 149 150 }// End of if(!defined('AK_OBJECT_CLASS_INCLUDED')){151 152 150 153 151 function ____ak_shutdown_function($details = false) … … 167 165 } 168 166 167 } 169 168 170 169 ?> trunk/lib/AkRequest.php
r327 r357 8 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 9 // +----------------------------------------------------------------------+ 10 11 if(!class_exists('AkResponse')){ 10 12 11 13 /** … … 17 19 */ 18 20 19 if(!defined('AK_REQUEST_CLASS_INCLUDED')){ define('AK_REQUEST_CLASS_INCLUDED',true); // Class overriding trick20 21 require_once(AK_LIB_DIR.DS.'AkObject.php');22 23 21 if(!defined('AK_DEFAULT_CONTROLLER')){ 24 22 define('AK_DEFAULT_CONTROLLER', 'page'); … … 27 25 define('AK_DEFAULT_ACTION', 'index'); 28 26 } 27 28 defined('AK_HIGH_LOAD_MODE') ? null : define('AK_HIGH_LOAD_MODE', false); 29 defined('AK_AUTOMATIC_DB_CONNECTION') ? null : define('AK_AUTOMATIC_DB_CONNECTION', !AK_HIGH_LOAD_MODE); 30 defined('AK_AUTOMATIC_SESSION_START') ? null : define('AK_AUTOMATIC_SESSION_START', !AK_HIGH_LOAD_MODE); 29 31 30 32 // IIS does not provide a valid REQUEST_URI so we need to guess it from the script name + query string … … 64 66 65 67 var $_init_check = false; 68 var $__internationalization_support_enabled = false; 66 69 67 70 var $action = AK_DEFAULT_ACTION; 68 71 var $controller = AK_DEFAULT_CONTROLLER; 69 72 var $view; 70 71 /** 72 * Holds information about current environment. Initially a reference to $_SERVER73 *74 * @var array75 */73 74 /** 75 * Holds information about current environment. Initially a reference to $_SERVER 76 * 77 * @var array 78 */ 76 79 var $env = array(); 77 80 // }}} … … 138 141 * @return void 139 142 */ 140 141 143 function init() 142 144 { … … 586 588 if(!empty($params) && is_array($params)){ 587 589 foreach ($params as $name=>$details){ 588 590 589 591 if(is_array($details) && !empty($details['name']) && !empty($details['tmp_name']) && !empty($details['size'])){ 590 591 if( is_array($details['tmp_name']) && 592 (593 count($details['tmp_name']) == 1 &&594 !is_array(array_shift(array_values($details['tmp_name']))))595 ){592 593 if( is_array($details['tmp_name']) && 594 ( 595 count($details['tmp_name']) == 1 && 596 !is_array(array_shift(array_values($details['tmp_name'])))) 597 ){ 596 598 597 599 foreach (array_keys($details['tmp_name']) as $k){ … … 634 636 } 635 637 } 636 638 637 639 return $result; 638 640 } … … 679 681 array_walk($_POST, array('AkRequest', '_fixGpc')); 680 682 array_walk($_COOKIE, array('AkRequest', '_fixGpc')); 681 //array_walk($_REQUEST, array('AkRequest', '_fixGpc'));682 //!empty($_FILES) ? array_walk($_FILES, array('AkRequest', '_fixGpc')) : null;683 683 } 684 684 define('AK_GPC_MAGIC_FIXED',true); … … 710 710 }else { 711 711 $item = urldecode($item); 712 } 713 } 714 715 716 // {{{ recognize() 717 718 /** 719 * Recognizes a Request and returns the responsible controller instance 720 * 721 * @return AkActionController 722 */ 723 function &recognize($Map = null) 724 { 725 $this->_connectToDatabase(); 726 $this->_startSession(); 727 $this->_enableInternationalizationSupport(); 728 $this->_mapRoutes($Map); 729 730 $params =& $this->getParams(); 731 $controller_file_name = AkInflector::underscore($params['controller']).'_controller.php'; 732 $controller_class_name = AkInflector::camelize($params['controller']).'Controller'; 733 $controller_path = AK_CONTROLLERS_DIR.DS.$controller_file_name; 734 include_once(AK_APP_DIR.DS.'application_controller.php'); 735 if(@!include_once($controller_path)){ 736 trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for '. 737 'the controller %controller_class_name', 738 array('%controller_file_name'=> $controller_file_name, 739 '%controller_class_name' => $controller_class_name)), E_USER_ERROR); 740 } 741 if(!class_exists($controller_class_name)){ 742 trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist', 743 array('%controller_name' => $controller_class_name)), E_USER_ERROR); 744 } 745 $Controller =& new $controller_class_name(array('controller'=>true)); 746 isset($_SESSION) ? $Controller->session = $_SESSION : null; 747 return $Controller; 748 749 } 750 751 // }}} 752 753 function _enableInternationalizationSupport() 754 { 755 if(AK_AVAILABLE_LOCALES != 'en'){ 756 require_once(AK_LIB_DIR.DS.'AkLocaleManager.php'); 757 758 $LocaleManager = new AkLocaleManager(); 759 $LocaleManager->init(); 760 $LocaleManager->initApplicationInternationalization($this); 761 $this->__internationalization_support_enabled = true; 762 } 763 } 764 765 function _mapRoutes($Map = null) 766 { 767 require_once(AK_LIB_DIR.DS.'AkRouter.php'); 768 if(is_file(AK_ROUTES_MAPPING_FILE)){ 769 if(empty($Map)){ 770 $Map =& AkRouter(); 771 } 772 include(AK_ROUTES_MAPPING_FILE); 773 // Set this routes for being used via Ak::toUrl 774 Ak::toUrl($Map,true); 775 $this->checkForRoutedRequests($Map); 776 } 777 } 778 779 780 function _connectToDatabase() 781 { 782 global $dsn; 783 if(AK_AUTOMATIC_DB_CONNECTION){ 784 if(!empty($dsn)){ 785 Ak::db($dsn); 786 } 787 } 788 } 789 790 function _startSession() 791 { 792 if(AK_AUTOMATIC_SESSION_START){ 793 if(!isset($_SESSION)){ 794 if(AK_SESSION_HANDLER == 1 && defined('AK_DATABASE_CONNECTION_AVAILABLE') && AK_DATABASE_CONNECTION_AVAILABLE){ 795 require_once(AK_LIB_DIR.DS.'AkDbSession.php'); 796 797 $AkDbSession = new AkDbSession(); 798 $AkDbSession->session_life = AK_SESSION_EXPIRE; 799 session_set_save_handler ( 800 array(&$AkDbSession, '_open'), 801 array(&$AkDbSession, '_close'), 802 array(&$AkDbSession, '_read'), 803 array(&$AkDbSession, '_write'), 804 array(&$AkDbSession, '_destroy'), 805 array(&$AkDbSession, '_gc') 806 ); 807 } 808 @session_start(); 809 } 712 810 } 713 811 } … … 722 820 } 723 821 724 }// End of if(!defined('AK_REQUEST_CLASS_INCLUDED')){ 725 822 823 } 726 824 727 825 ?> trunk/lib/AkResponse.php
r285 r357 9 9 // +----------------------------------------------------------------------+ 10 10 11 require_once(AK_LIB_DIR.DS.'AkObject.php'); 11 if(!class_exists('AkResponse')){ 12 12 13 13 /** … … 24 24 var $_headers_sent = array(); 25 25 var $body = ''; 26 26 var $__Logger; 27 27 28 function set($data, $id = null) 28 29 { … … 61 62 function outputResults() 62 63 { 63 Ak::profile('Started sending response'.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__);64 64 $this->sendHeaders(); 65 65 if(is_object($this->body) && method_exists($this->body,'stream')){ 66 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending response as stream") : null; 66 67 $this->body->stream(); 67 68 }else{ 69 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending response") : null; 68 70 echo $this->body; 69 71 } … … 90 92 91 93 if(!empty($this->_headers) && is_array($this->_headers)){ 94 $this->addHeader('Connection: close'); 92 95 foreach ($this->_headers as $k=>$v){ 93 96 $header = trim((!is_numeric($k) ? $k.': ' : '').$v); … … 103 106 $_has_content_type = true; 104 107 } 108 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending header: $header") : null; 105 109 header($header); 106 110 } … … 192 196 $null = null; 193 197 $AkResponse =& Ak::singleton('AkResponse', $null); 198 AK_LOG_EVENTS && empty($AkResponse->_Logger) ? ($AkResponse->_Logger =& Ak::getLogger()) : null; 194 199 return $AkResponse; 195 200 } 196 201 202 } 203 197 204 ?> trunk/lib/AkRouter.php
r285 r357 9 9 // +----------------------------------------------------------------------+ 10 10 11 ak_compat('http_build_query'); 12 13 /** 11 if(!class_exists('AkRouter')){ 12 13 ak_compat('http_build_query'); 14 15 /** 14 16 * Native PHP URL rewriting for the Akelos Framework. 15 17 * … … 22 24 23 25 24 // ---- Required Files ---- // 25 require_once(AK_LIB_DIR.DS.'AkObject.php'); 26 27 if(!defined('OPTIONAL')){ 28 define('OPTIONAL', false); 29 } 30 31 if(!defined('COMPULSORY')){ 32 define('COMPULSORY', true); 33 } 34 35 if(!defined('COMPULSORY_REGEX')){ 36 define('COMPULSORY_REGEX', '([^\/]+){1}'); 37 } 38 39 40 41 42 /** 43 * Native PHP URL rewriting for the Akelos Framework 44 * 45 * This class implements PHP based URL rewriting for the Akelos Framework, thus shifting the responsibility of URL parsing from the webserver to the Akelos Framework itself. This has been a requested feature for two primary reasons. 46 * 47 * - Not all webservers support rewriting. By moving this code to the core, the framework is able to function out of the box on almost all webservers. 48 * 49 * - A rewriting implementation in the Akelos Framework can also be used to generate custom URLs by linking it to the standard URL helpers such as url_for, link_to, and redirect_to. 50 * 51 * @author Bermi Ferrer <bermi a.t akelos d.t c.om> 52 * @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org 53 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 54 */ 55 class AkRouter extends AkObject 56 { 57 // {{{ properties 58 59 60 // --- Private properties --- // 26 if(!defined('OPTIONAL')){ 27 define('OPTIONAL', false); 28 } 29 30 if(!defined('COMPULSORY')){ 31 define('COMPULSORY', true); 32 } 33 34 if(!defined('COMPULSORY_REGEX')){ 35 define('COMPULSORY_REGEX', '([^\/]+){1}'); 36 } 37 38 61 39 62 40 63 41 /** 64 * Routes setting container42 * Native PHP URL rewriting for the Akelos Framework 65 43 * 66 * @see getRoutes 67 * @access private 68 * @var array $_loaded_routes 44 * This class implements PHP based URL rewriting for the Akelos Framework, thus shifting the responsibility of URL parsing from the webserver to the Akelos Framework itself. This has been a requested feature for two primary reasons. 45 * 46 * - Not all webservers support rewriting. By moving this code to the core, the framework is able to function out of the box on almost all webservers. 47 * 48 * - A rewriting implementation in the Akelos Framework can also be used to generate custom URLs by linking it to the standard URL helpers such as url_for, link_to, and redirect_to. 49 * 50 * @author Bermi Ferrer <bermi a.t akelos d.t c.om> 51 * @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org 52 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 69 53 */ 70 var $_loaded_routes = array(); 71 72 // }}} 73 74 75 // ------ CLASS METHODS ------ // 76 77 78 // ---- Constructor ---- // 79 80 function __construct() 54 class AkRouter extends AkObject 81 55 { 56 // {{{ properties 57 58 59 // --- Private properties --- // 60 61 82 62 /** 63 * Routes setting container 64 * 65 * @see getRoutes 66 * @access private 67 * @var array $_loaded_routes 68 */ 69 var $_loaded_routes = array(); 70 71 // }}} 72 73 74 // ------ CLASS METHODS ------ // 75 76 77 // ---- Constructor ---- // 78 79 function __construct() 80 { 81 /** 83 82 * We will try to guess if mod_rewrite is enabled. 84 83 * Set AK_ENABLE_URL_REWRITE in your config 85 84 * to avoid the overhead this function causes 86 85 */ 87 if(!defined('AK_ENABLE_URL_REWRITE') || (defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE !== false)){ 88 $this->_loadUrlRewriteSettings(); 86 if(!defined('AK_ENABLE_URL_REWRITE') || (defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE !== false)){ 87 $this->_loadUrlRewriteSettings(); 88 } 89 89 } 90 } 91 92 93 // ---- Getters ---- // 94 95 96 // {{{ getRoutes() 97 98 /** 99 * $this->_loaded_routes getter 100 * 101 * Use this method to get $this->_loaded_routes value 102 * 103 * @access public 104 * @return array Returns Loaded Routes array. 90 91 92 // ---- Getters ---- // 93 94 95 // {{{ getRoutes() 96 97 /** 98 * $this->_loaded_routes getter 99 * 100 * Use this method to get $this->_loaded_routes value 101 * 102 * @access public 103 * @return array Returns Loaded Routes array. 104 */ 105 function getRoutes() 106 { &nb
