setFallbackAutoloader(true); } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'AutoLoader', $e->getMessage(), 'error'); } /* * Check ENVIRONMENT constant from Bootstrap loader */ if (strcasecmp(ENVIRONMENT, "production") === 0) { /** * Register 'is_production' with true. */ Zend_Registry::set('is_production', true); /** * Turn off all error reporting */ @error_reporting(0); } else { /** * Register 'is_production' with false. */ Zend_Registry::set('is_production', false); /** * Report all errors except E_NOTICE */ @error_reporting(E_ALL ^ E_NOTICE); /** * Check the Zend Framework installed to your system with Zend Framework 1.7 or below. */ if (Zend_Version::compareVersion(HMF_USED_ZF) > 0) { Hmf_Errors::invalidZFVersion(); } } try { /** * Process the config varieble and register the 'app_config' and 'app_locale' to Zend_Register in application */ Hmf_Config::process($config); } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'Process configuration', $e->getMessage(), 'error'); } /** * delete config varieble */ unset($config); /** * Load Default Hmf Helpers Functions */ if(Hmf_Config::getConfig('function.helpers.default')) { require_once 'Helpers.php'; } /** * Load Extended Hmf Helpers Functions */ if(Hmf_Config::getConfig('function.helpers.extended')) { $extendedHelperArrayFile = Hmf_Config::getConfig('function.helpers.extended.load'); foreach($extendedHelperArrayFile as $fileName) { if (file_exists(PATH_DIR_APPLICATION_HELPERS . '/'. $fileName . '.php')) { require_once PATH_DIR_APPLICATION_HELPERS . '/'. $fileName . '.php'; } else { Hmf_Errors::missingExtendedHelpers($fileName); } } } /** * Filter data in QueryString */ Hmf_Httppage::FilterQuerystring(); /** * Register acl variable to 'acl' index in Zend_Registry */ Zend_Registry::set('acl', $acl); /** * delete acl varieble */ unset($acl); /* * Register viewsInformations variable to 'app_viewinfo' index in Zend_Registry */ Zend_Registry::set('app_viewinfo', $viewsInformations); /** * delete viewsInformations variable */ unset($viewsInformations); /* * Register rounting variable to 'rounting' index in Zend_Registry */ Zend_Registry::set('rounting', $rounting); /** * delete rounting variable */ unset($rounting); /** * Process the QueryString in $_GET['qs'] for handle to the controller and the action (with parameter) * and register output to 'routing_url' index in Zend_Registry */ Zend_Registry::set('routing_url', new Hmf_Routing($_GET['qs'])); try { /** * Get the data from routing_url index in Zend_Registry and set to routes variable */ $routes = Zend_Registry::get('routing_url')->getRoutes(); if (empty($routes[':controller']) or empty($routes[':action'])) { Hmf_Errors::routing(); } } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'Get Routes data', $e->getMessage(), 'error'); } /** * Preifx name for controller class * @var string */ define('CONTROLLER_PREFIX_NAME', 'controller_'); /** * Regsiter path of controller file to controller_file in Zend_Registry index. */ Zend_Registry::set('controller_file', $routes[':controller'] . '.php'); /** * Regsiter name of controller class to controller_name in Zend_Registry index. */ Zend_Registry::set('controller_name', CONTROLLER_PREFIX_NAME . $routes[':controller']); /** * Regsiter name of class method to action_name in Zend_Registry index. */ Zend_Registry::set('action_name', $routes[':action']); /** * Regsiter args of class method to action_args in Zend_Registry index. */ Zend_Registry::set('action_args', (empty($routes[':args']) ? array() : $routes[':args'])); /** * delete routes variable */ unset($routes); /** * define PATH_DIR_APPLICATION_CONTROLLERS_FILE for store path of application controller file */ define("PATH_DIR_APPLICATION_CONTROLLERS_FILE", PATH_DIR_APPLICATION_CONTROLLERS . '/' . Zend_Registry::get('controller_file')); if (!file_exists(PATH_DIR_APPLICATION_CONTROLLERS_FILE)) { Hmf_Errors::missingControllerFile(Zend_Registry::get('controller_file')); } /** * @see Bootstrap_Controller */ require_once PATH_FILE_APPLICATION_BOOTSTRAP_CONTROLLER; /** * @see Specified with controller class in just-in-time action */ require_once PATH_DIR_APPLICATION_CONTROLLERS_FILE; if (!class_exists(Zend_Registry::get('controller_name'))) { Hmf_Errors::missingControllerClass(Zend_Registry::get('controller_name')); } try { /** * Lnitialize to class variable with ReflectionClass from controller name */ $class = new ReflectionClass(Zend_Registry::get('controller_name')); /** * Begin check valid controller class * - Controller is subclass from Bootstrap_Controller * - Controller has __construct method * - Controller has action method with just-in-time action */ if (!$class->isSubclassOf('Bootstrap_Controller')) { Hmf_Errors::classNotExtends('Bootstrap_Controller', Zend_Registry::get('controller_name')); } if (!$class->hasMethod('__construct')) { Hmf_Errors::missingConstructor(); } if (!$class->hasMethod(Zend_Registry::get('action_name'))) { Hmf_Errors::missingAction(Zend_Registry::get('action_name'), Zend_Registry::get('controller_name')); } /** * End check valid controller class */ /** * Lnitialize to method variable with ReflectionMethod from action name */ $method = new ReflectionMethod(Zend_Registry::get('controller_name'), Zend_Registry::get('action_name')); /** * Check number of argument */ if (($method->getNumberOfRequiredParameters() - count(Zend_Registry::get('action_args'))) > 0) { Hmf_Errors::missingArgs($method->getNumberOfRequiredParameters(), Zend_Registry::get('controller_name'), Zend_Registry::get('action_name')); } /** * Create View instant and register to view in Zend_Registry index. */ Zend_Registry::set('view', new Hmf_View()); /** * Create controller instant from class variable. */ $objController = $class->newInstanceArgs(); /** * Load controller constructor */ $objController->loadFlowControllerConstructor(); /** * Set default content-page with action_name from Zend_Register index to controller ojbect */ $objController->useContentPage('index', Zend_Registry::get('action_name')); /** * Invoke Controller with argument */ $controllerReturnValue = $method->invokeArgs($objController, Zend_Registry::get('action_args')); /** * TODO Check return invoke for Backward compatible with old controller style * and append data to content-page data (it slower than new style) * Remove Backward compatible soon. */ if (!is_null($controllerReturnValue)) { Zend_Registry::get('view')->appendContentPageData('index', $controllerReturnValue); } } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'Controller', $e->getMessage(), 'error'); } try { /** * Render the content-page and master-page and send data to users. */ Zend_Registry::get('view')->render($objController); } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'View Render', $e->getMessage(), 'error'); } try { /** * Store log for debug with memory usages */ @Hmf_Logs::memUsage(Zend_Registry::get('controller_name'), Zend_Registry::get('action_name'), Zend_Registry::get('action_args')); } catch (Exception $e) { /** * Default Error Exception */ Hmf_Errors::showError($e->getCode(), 'Logs Memory Usages', $e->getMessage(), 'error'); }