DotKernel
[ class tree: DotKernel ] [ index: DotKernel ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php 
  2. /**
  3.  * DotBoost Technologies Inc.
  4.  * DotKernel Application Framework
  5.  *
  6.  * @category   DotKernel
  7.  * @package    DotKernel
  8.  * @copyright  Copyright (c) 2009 DotBoost  Technologies (http://www.dotboost.com)
  9.  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10.  * @version    $Id: index.php 151 2010-06-14 13:54:43Z teo $
  11.  */
  12.  
  13.  /**
  14.  * Main public executable wrapper.
  15.  * Setup environment, setup index controllers , and  load module to run
  16.  * @author     DotKernel Team <team@dotkernel.com>
  17.  */
  18.  
  19. // Start counting the time needed to display all content, from the very beginning
  20. $startTime microtime();
  21.  
  22. // Define application environment
  23. defined('APPLICATION_ENV'|| 
  24.     define('APPLICATION_ENV'(getenv('APPLICATION_ENV'getenv('APPLICATION_ENV''production'));
  25.  
  26. //Set error reporting
  27. if(APPLICATION_ENV != 'production'error_reporting(-1);
  28.  
  29. //Set include  path to library directory
  30.     implode(PATH_SEPARATORarray(realpath(dirname(__FILE__).'/library')get_include_path())));
  31.  
  32. // Define PATH's (absolute paths)  to configuration, controllers, DotKernel, templates  directories
  33. defined('CONFIGURATION_PATH'|| define('CONFIGURATION_PATH'realpath(dirname(__FILE__).'/configs'));
  34. defined('CONTROLLERS_PATH'|| define('CONTROLLERS_PATH'realpath(dirname(__FILE__).'/controllers'));
  35. defined('DOTKERNEL_PATH'|| define('DOTKERNEL_PATH'realpath(dirname(__FILE__).'/DotKernel'));
  36. defined('TEMPLATES_PATH'|| define('TEMPLATES_PATH'realpath(dirname(__FILE__).'/templates'));
  37.  
  38. // Define DIRECTORIES  ( relative paths)
  39. defined('TEMPLATES_DIR'|| define('TEMPLATES_DIR''/templates');
  40. defined('IMAGES_DIR'|| define('IMAGES_DIR''/images');
  41.  
  42. // Load Zend Framework
  43. require_once 'Zend/Loader/Autoloader.php';
  44. $zend_loader Zend_Loader_Autoloader::getInstance();
  45.  
  46. //includes all classes in library folder. That class names must start with Dot_
  47. $zend_loader->registerNamespace('Dot_');
  48.  
  49. // Create registry object, as read-only object to store there config, settings, and database
  50. $registry new Zend_Registry(array()ArrayObject::ARRAY_AS_PROPS);
  51. Zend_Registry::setInstance($registry);
  52.  
  53. //Load configuration settings from application.ini file and store it in registry
  54. $config new Zend_Config_Ini(CONFIGURATION_PATH.'/application.ini'APPLICATION_ENV);
  55. $registry->configuration $config;
  56.  
  57. //Load resource(modules, controllers, actions) settings from resource.ini file and store it in registry
  58. $resource new Zend_Config_Xml(CONFIGURATION_PATH.'/resource.xml');
  59. $registry->resource $resource;
  60.  
  61. // Create  connection to database, as singleton , and store it in registry
  62. $db Zend_Db::factory('Pdo_Mysql'$config->database->params->toArray());
  63. $registry->database $db;
  64.  
  65. //Load specific configuration settings from database, and store it in registry
  66. $settings Dot_Settings::getSettings();
  67. $registry->settings $settings;
  68.  
  69. //Set PHP configuration settings from application.ini file
  70. Dot_Settings::setPhpSettings($config->phpSettings->toArray());
  71.  
  72. // Start Index Controller
  73. $requestRaw explode('/'
  74.                       trim(substr($_SERVER['REQUEST_URI']
  75.                       strlen(dirname($_SERVER['PHP_SELF'])))'/'));
  76.  
  77. // We are in frontend or in other module ? Prebuilt modules: frontend, admin, rss
  78. $requestModule 'frontend';
  79. if (in_array($requestRaw['0']$config->resources->modules->toArray()))
  80. {
  81.     $requestModule basename(stripslashes($requestRaw['0']));
  82. }
  83. // if  we are NOT in frontend  module
  84. if ($requestModule != 'frontend')
  85.     array_shift($requestRaw);
  86.     
  87. // set Controller and Action value, default Index
  88. $requestController 'Index';
  89. if (isset($requestRaw['0']&& $requestRaw['0'!= '')
  90. {
  91.     $requestController ucfirst(basename(stripslashes($requestRaw['0'])));
  92. }
  93.  
  94. // set Action value, default nothing
  95. $requestAction '';
  96. if (isset($requestRaw['1']&& $requestRaw['1'!= '')
  97. {
  98.     $requestAction basename(stripslashes($requestRaw['1']));
  99. }
  100.  
  101. // we have extra variables, so we load all in the global array $request
  102. $request array();
  103. while (list($key$valeach($requestRaw))
  104. {
  105.     $request[$valcurrent($requestRaw);
  106.     next($requestRaw);
  107. }
  108.  
  109. // remove first element of the request array, is module and action in it
  110. array_shift($request);
  111.  
  112. //memory request into param variable and load them into registry
  113. $param array();
  114. $param['module'$requestModule;
  115. $param['controller'$requestController;
  116. $param['action'$requestAction;
  117. $param array_merge($param$request);
  118. $registry->param $param;
  119.  
  120. // Start dotKernel object
  121. $dotKernel new Dot_Kernel();
  122.  
  123. //Initialize the session
  124. Dot_Sessions::start($requestModule);
  125. $session Zend_Registry::get('session');
  126.  
  127. /**
  128. *  From this point , the control is taken by the Front Controller
  129. *  call the Front Controller specific file, but check first if exists
  130. */
  131.  
  132. $frontControllerPath CONTROLLERS_PATH.'/'.$requestModule.'/'.'IndexController.php';
  133. !file_exists($frontControllerPath?  $dotKernel->pageNotFound(:  require($frontControllerPath);

Documentation generated on Wed, 21 Jul 2010 07:34:40 +0000 by phpDocumentor 1.4.3