Changeset 357

Show
Ignore:
Timestamp:
09/14/07 16:24:40 (1 year ago)
Author:
bermiferrer
Message:

MAJOR CHANGE. The way Akelos dispatches requests has changed completely. You are encouraged to update your existing applications public/index.php and config/boot.php to benefit from this changes.
Now Akelos uses a generic Dispatcher that will serve as the base Akelos bootstrapping for executing Akelos in share-nothing environments (the default PHP workflow) and as an Application Server (Like Mongrel cubes using SCGI and http://code.google.com/p/appserver-in-php/).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/framework_setup_controller.php

    r324 r357  
    2424 
    2525include_once(AK_CONFIG_DIR.DS.'boot.php'); 
     26require_once(AK_LIB_DIR.DS.'AkObject.php'); 
     27require_once(AK_LIB_DIR.DS.'AkInflector.php'); 
     28require_once(AK_LIB_DIR.DS.'Ak.php'); 
     29require_once(AK_LIB_DIR.DS.'AkActionController.php'); 
    2630 
    2731$_GET['controller'] = 'framework_setup'; 
  • trunk/app/models/framework_setup.php

    r339 r357  
    241241    function runFrameworkInstaller() 
    242242    { 
     243        static $unique_dsn = array(); 
    243244        require_once(AK_LIB_DIR.DS.'AkInstaller.php'); 
    244245        require_once(AK_APP_DIR.DS.'installers'.DS.'framework_installer.php'); 
    245246 
    246247        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            } 
    250255        } 
    251256 
     
    360365 
    361366            $settings['%locales'] = $this->getLocales(); 
    362              
     367 
    363368            $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// "; 
    364369            $settings['%AK_FRAMEWORK_DIR'] = defined('AK_FRAMEWORK_DIR') ? 
     
    562567        'ftp_host' => $this->getFtpHost(), 
    563568        'ftp_path' => $this->getFtpPath(), 
    564          
     569 
    565570        'random' => Ak::randomString(), 
    566571        ); 
  • trunk/config/boot.php

    r296 r357  
    2222 
    2323require_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'); 
    2624 
    2725?> 
  • trunk/lib/AkActionController.php

    r346 r357  
    88// | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    99// +----------------------------------------------------------------------+ 
     10 
     11if(!class_exists('AkActionController')){ 
     12 
     13require_once(AK_LIB_DIR.DS.'AkObject.php'); 
     14 
     15defined('AK_HIGH_LOAD_MODE') ? null : define('AK_HIGH_LOAD_MODE', false); 
    1016 
    1117/** 
     
    1622 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    1723 */ 
    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     
    2325class AkActionController extends AkObject 
    2426{ 
    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     
    3032    var $_ssl_requirement = false; 
    3133 
     
    3941    * Protected instance variable cache 
    4042    */ 
    41     var $_protected_variables_cache
     43    var $_protected_variables_cache = array()
    4244 
    4345    /** 
     
    4850    *  $this->_asset_host = 'http://assets.example.com'; 
    4951    */ 
    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; 
    8356 
    8457    /** 
     
    141114    var $cookies; 
    142115 
    143     var $_autoIncludePaginator = true; 
    144  
    145116    var $helpers = 'default'; 
    146117 
     
    153124    var $web_service_apis = array(); 
    154125 
    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'); 
    175164            } 
    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    } 
    180224 
    181225    /** 
     
    287331    } 
    288332 
    289     function instantiateIncludedModelClasses($models = null
     333    function instantiateIncludedModelClasses(
    290334    { 
    291335        require_once(AK_LIB_DIR.DS.'AkActiveRecord.php'); 
    292336        require_once(AK_APP_DIR.DS.'shared_model.php'); 
    293337 
    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( 
    295342        Ak::import($this->model), 
    296         Ak::import($this->models))) : $models
     343        Ak::import($this->models)))
    297344 
    298345        foreach ($models as $model){ 
     
    466513    function render($options = null, $status = 200) 
    467514    { 
    468         Ak::profile('Entering into '.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__); 
    469  
    470515        if(empty($options['partial']) && $this->_hasPerformed()){ 
    471516            $this->_doubleRenderError(Ak::t("Can only render or redirect once per action")); 
     
    477522        // Ror Backwards compatibility 
    478523        if(!is_array($options)){ 
    479             Ak::profile('Enterind on render file '.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__); 
    480524            return $this->renderFile(empty($options) ? $this->getDefaultTemplateName() : $options, $status, true); 
    481525        } 
     
    544588            $this->_assertExistanceOfTemplateFile($template_path); 
    545589        } 
    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         
    550593        return $this->renderText($this->Template->renderFile($template_path, $use_full_path, $locals), $status); 
    551594    } 
     
    602645    } 
    603646 
    604     function renderWithoutLayout($template_name, $status = null) 
     647    function renderWithoutLayout($template_name = null, $status = null) 
    605648    { 
    606649        $template_name = empty($template_name) ? $this->getDefaultTemplateName() : $template_name; 
     
    628671    function _addInstanceVariablesToAssigns() 
    629672    { 
    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){ 
    634676            if($attribute[0] != '_'){ 
    635677                $this->_assigns[$attribute] =& $this->$attribute; 
     
    686728                    $this->_doubleRenderError(); 
    687729                } 
    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; 
    691731                $this->_handleFlashAttribute(); 
    692732                $this->Response->redirect($options); 
     
    18321872    } 
    18331873 
     1874     
    18341875    function _callFilters(&$filters, $method = '') 
    18351876    { 
     
    18451886                    $filter_result = $filter->filter($this); 
    18461887                }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); 
    18481889                } 
    18491890 
     
    19551996    } 
    19561997 
    1957  
    1958  
    1959     /** 
    1960      * This methods are used before triggering an Application Controller 
    1961      */ 
    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::toUrl 
    2016             Ak::toUrl($Map,true); 
    2017             $this->Request->checkForRoutedRequests($Map); 
    2018         } 
    2019     } 
    20201998 
    20211999 
     
    25052483    function redirectToLocale($locale) 
    25062484    { 
    2507         if($this->__internationalization_support_enabled){ 
     2485        if($this->Request->__internationalization_support_enabled){ 
    25082486            $lang = isset($this->params['lang']) ? $this->params['lang'] : $locale; 
    25092487 
     
    25502528} 
    25512529 
     2530} 
     2531 
    25522532?> 
  • trunk/lib/AkActionController/AkWebRequest.php

    r350 r357  
    1515 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    1616 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
     17 * @deprecated Please use AkDispatcher on your public/index.php instead 
    1718 */ 
    1819 
  • trunk/lib/AkActionView/helpers/asset_tag_helper.php

    r293 r357  
    223223        $source = !strstr($source,'.') ? "$source.$ext" : $source; 
    224224        $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; 
    226226        $source = substr($source,0,2) == '//' ? substr($source,1) : $source; 
    227227         
  • trunk/lib/AkActionView/helpers/pagination_helper.php

    r285 r357  
    1919 
    2020require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkActionViewHelper.php'); 
    21  
     21require_once(AK_LIB_DIR.DS.'AkActionController'.DS.'AkPaginator.php'); 
     22             
    2223class PaginationHelper extends AkActionViewHelper 
    2324{ 
  • trunk/lib/AkActiveRecord.php

    r350 r357  
    45694569    { 
    45704570        $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) ?  
    45724572        'AkActsAs'.$class_name : 'ActsAs'.$class_name; 
    45734573    } 
     
    45824582                include_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.$class_name.'.php'); 
    45834583            }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'); 
    45854585            } 
    45864586        } 
  • trunk/lib/AkLocaleManager.php

    r285 r357  
    4343    { 
    4444        static $available_locales; 
    45         Ak::profile(__CLASS__.'::'.__FUNCTION__); 
    4645 
    4746        if(empty($available_locales)){ 
     
    6261    function _parseLocaleConfigString($locale_settings) 
    6362    { 
    64         Ak::profile(__CLASS__.'::'.__FUNCTION__); 
    6563        $locale_settings = trim(str_replace(' ','',$locale_settings)); 
    6664        $locale_settings = str_replace(array(';','(',')'), array(',','~','',''),$locale_settings); 
  • trunk/lib/AkObject.php

    r285 r357  
    1717 */ 
    1818 
    19 if(!defined('AK_OBJECT_CLASS_INCLUDED')){ define('AK_OBJECT_CLASS_INCLUDED',true); // Class overriding trick 
     19if(!class_exists('AkObject')){  
    2020 
    2121/** 
     
    148148} 
    149149 
    150 }// End of if(!defined('AK_OBJECT_CLASS_INCLUDED')){ 
    151  
    152150 
    153151function ____ak_shutdown_function($details = false) 
     
    167165} 
    168166 
     167} 
    169168 
    170169?> 
  • trunk/lib/AkRequest.php

    r327 r357  
    88// | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    99// +----------------------------------------------------------------------+ 
     10 
     11if(!class_exists('AkResponse')){ 
    1012 
    1113/** 
     
    1719 */ 
    1820 
    19 if(!defined('AK_REQUEST_CLASS_INCLUDED')){ define('AK_REQUEST_CLASS_INCLUDED',true); // Class overriding trick 
    20  
    21 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
    22  
    2321if(!defined('AK_DEFAULT_CONTROLLER')){ 
    2422    define('AK_DEFAULT_CONTROLLER', 'page'); 
     
    2725    define('AK_DEFAULT_ACTION', 'index'); 
    2826} 
     27 
     28defined('AK_HIGH_LOAD_MODE') ? null : define('AK_HIGH_LOAD_MODE', false); 
     29defined('AK_AUTOMATIC_DB_CONNECTION') ? null : define('AK_AUTOMATIC_DB_CONNECTION', !AK_HIGH_LOAD_MODE); 
     30defined('AK_AUTOMATIC_SESSION_START') ? null : define('AK_AUTOMATIC_SESSION_START', !AK_HIGH_LOAD_MODE); 
    2931 
    3032// IIS does not provide a valid REQUEST_URI so we need to guess it from the script name + query string 
     
    6466 
    6567    var $_init_check = false; 
     68    var $__internationalization_support_enabled = false; 
    6669 
    6770    var $action = AK_DEFAULT_ACTION; 
    6871    var $controller = AK_DEFAULT_CONTROLLER; 
    6972    var $view; 
    70  
    71     /** 
    72     * Holds information about current environment. Initially a reference to $_SERVER 
    73    
    74     * @var array 
    75     */ 
     73     
     74    /** 
     75    * Holds information about current environment. Initially a reference to $_SERVER 
     76   
     77    * @var array 
     78    */ 
    7679    var $env = array(); 
    7780    // }}} 
     
    138141    * @return void  
    139142    */ 
    140  
    141143    function init() 
    142144    { 
     
    586588        if(!empty($params) && is_array($params)){ 
    587589            foreach ($params as $name=>$details){ 
    588                  
     590 
    589591                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                    ){ 
    596598 
    597599                        foreach (array_keys($details['tmp_name']) as $k){ 
     
    634636            } 
    635637        } 
    636          
     638 
    637639        return $result; 
    638640    } 
     
    679681                array_walk($_POST, array('AkRequest', '_fixGpc')); 
    680682                array_walk($_COOKIE, array('AkRequest', '_fixGpc')); 
    681                 //array_walk($_REQUEST, array('AkRequest', '_fixGpc')); 
    682                 //!empty($_FILES) ? array_walk($_FILES, array('AkRequest', '_fixGpc')) : null; 
    683683            } 
    684684            define('AK_GPC_MAGIC_FIXED',true); 
     
    710710        }else { 
    711711            $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            } 
    712810        } 
    713811    } 
     
    722820} 
    723821 
    724 }// End of if(!defined('AK_REQUEST_CLASS_INCLUDED')){ 
    725  
     822 
     823
    726824 
    727825?> 
  • trunk/lib/AkResponse.php

    r285 r357  
    99// +----------------------------------------------------------------------+ 
    1010 
    11 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
     11if(!class_exists('AkResponse')){ 
    1212 
    1313/** 
     
    2424    var $_headers_sent = array(); 
    2525    var $body = ''; 
    26  
     26    var $__Logger; 
     27     
    2728    function set($data, $id = null) 
    2829    { 
     
    6162    function outputResults() 
    6263    { 
    63          Ak::profile('Started sending response'.__CLASS__.'::'.__FUNCTION__.' '.__FILE__.' on line '.__LINE__); 
    6464        $this->sendHeaders(); 
    6565        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; 
    6667            $this->body->stream(); 
    6768        }else{ 
     69            AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending response") : null; 
    6870            echo $this->body; 
    6971        } 
     
    9092         
    9193        if(!empty($this->_headers) && is_array($this->_headers)){ 
     94            $this->addHeader('Connection: close'); 
    9295            foreach ($this->_headers as $k=>$v){ 
    9396                $header = trim((!is_numeric($k) ? $k.': ' : '').$v); 
     
    103106                    $_has_content_type = true; 
    104107                } 
     108                AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending header:  $header") : null; 
    105109                header($header); 
    106110            } 
     
    192196    $null = null; 
    193197    $AkResponse =& Ak::singleton('AkResponse', $null); 
     198    AK_LOG_EVENTS && empty($AkResponse->_Logger) ? ($AkResponse->_Logger =& Ak::getLogger()) : null; 
    194199    return $AkResponse; 
    195200} 
    196201 
     202} 
     203 
    197204?> 
  • trunk/lib/AkRouter.php

    r285 r357  
    99// +----------------------------------------------------------------------+ 
    1010 
    11 ak_compat('http_build_query'); 
    12  
    13 /** 
     11if(!class_exists('AkRouter')){ 
     12 
     13    ak_compat('http_build_query'); 
     14 
     15    /** 
    1416 * Native PHP URL rewriting for the Akelos Framework. 
    1517 *  
     
    2224 
    2325 
    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 
    6139 
    6240 
    6341    /** 
    64     * Routes setting container 
     42    * Native PHP URL rewriting for the Akelos Framework 
    6543    * 
    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> 
    6953    */ 
    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 
    8155    { 
     56        // {{{ properties 
     57 
     58 
     59        // --- Private properties --- // 
     60 
     61 
    8262        /** 
     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            /** 
    8382        * We will try to guess if mod_rewrite is enabled. 
    8483        * Set AK_ENABLE_URL_REWRITE in your config  
    8584        * to avoid the overhead this function causes 
    8685        */ 
    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            } 
    8989        } 
    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