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

Source for file trax.php

Documentation is available at trax.php

  1. <?php
  2. /**
  3.  *  File containing the Trax class for framework configs
  4.  *
  5.  *  (PHP 5)
  6.  *
  7.  *  @package PHPonTrax
  8.  *  @version $Id:$
  9.  *  @copyright (c) 2005 John Peterson
  10.  *
  11.  *   Permission is hereby granted, free of charge, to any person obtaining
  12.  *   a copy of this software and associated documentation files (the
  13.  *   "Software"), to deal in the Software without restriction, including
  14.  *   without limitation the rights to use, copy, modify, merge, publish,
  15.  *   distribute, sublicense, and/or sell copies of the Software, and to
  16.  *   permit persons to whom the Software is furnished to do so, subject to
  17.  *   the following conditions:
  18.  *
  19.  *   The above copyright notice and this permission notice shall be
  20.  *   included in all copies or substantial portions of the Software.
  21.  *
  22.  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23.  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24.  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25.  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26.  *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27.  *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28.  *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29.  */
  30.  
  31. /**
  32.  *  @todo Document this class
  33.  *  @package PHPonTrax
  34.  */
  35. class Trax {
  36.  
  37.     const
  38.         MAJOR 0,
  39.         MINOR 14,
  40.         TINY 0;
  41.     
  42.     public static 
  43.         $models_path null,
  44.         $views_path null,
  45.         $controllers_path null,
  46.         $helpers_path null,
  47.         $layouts_path null,
  48.         $config_path null,
  49.         $environments_path null,
  50.         $lib_path null,
  51.         $app_path null,
  52.         $log_path null,
  53.         $vendor_path null,
  54.         $public_path null,
  55.         $url_prefix null,
  56.         $views_extension 'phtml',
  57.         $path_seperator ":"# default is Unix
  58.         $current_controller_path null,
  59.         $current_controller_name null,
  60.         $current_action_name null,
  61.         $current_controller_object null,
  62.         $version null;
  63.  
  64.     function initialize({
  65.  
  66.         self::$version self::version();
  67.  
  68.         if(substr(PHP_OS03== 'WIN'{
  69.             # Windows
  70.             self::$path_seperator ";";
  71.         }
  72.  
  73.         # Set include paths
  74.         self::$models_path       TRAX_ROOT."/app/models";
  75.         self::$views_path        TRAX_ROOT."/app/views";
  76.         self::$controllers_path  TRAX_ROOT."/app/controllers";
  77.         self::$helpers_path      TRAX_ROOT."/app/helpers";
  78.         self::$layouts_path      TRAX_ROOT."/app/views/layouts";
  79.         self::$config_path       TRAX_ROOT."/config";
  80.         self::$environments_path TRAX_ROOT."/config/environments";
  81.         self::$lib_path          TRAX_ROOT."/lib";
  82.         self::$app_path          TRAX_ROOT."/app";
  83.         self::$log_path          TRAX_ROOT."/log";
  84.         self::$vendor_path       TRAX_ROOT."/vendor";
  85.         self::$public_path       TRAX_ROOT."/public"
  86.  
  87.         # Set which file to log php errors to for this application
  88.         # As well in your application you can do error_log("whatever") and it will go to this log file.
  89.         ini_set("log_errors""On");
  90.         ini_set("error_log"self::$log_path."/".TRAX_ENV.".log");
  91.  
  92.         if(TRAX_ENV == "development"{
  93.             # Display errors to browser if in development mode for debugging
  94.             ini_set("display_errors""On");
  95.         else {
  96.             # Hide errors from browser if not in development mode
  97.             ini_set("display_errors""Off");
  98.         }
  99.  
  100.         # Set the include_path
  101.         ini_set("include_path",
  102.             ".".self::$path_seperator.              # current directory
  103.             TRAX_LIB_ROOT.self::$path_seperator.    # trax libs (vendor/trax or server trax libs)
  104.             PHP_LIB_ROOT.self::$path_seperator.     # php libs dir (ex: /usr/local/lib/php)
  105.             self::$lib_path.self::$path_seperator.  # app specific libs extra libs to include
  106.             ini_get("include_path")                 # tack on the old include_path to the end
  107.         );
  108.  
  109.         # Include Trax library files.
  110.         include_once("session.php");
  111.         include_once("input_filter.php");
  112.         include_once("trax_exceptions.php");
  113.         include_once("inflector.php");
  114.         include_once("active_record.php");
  115.         include_once("action_controller.php");
  116.         include_once("action_view.php");
  117.         include_once("action_mailer.php");
  118.         include_once("dispatcher.php");
  119.         include_once("router.php");
  120.  
  121.         # Make sure database settings are cleared out
  122.         ActiveRecord::$database_settings array();
  123.         if(file_exists(self::$config_path."/database.ini")) {
  124.             # Load databse settings 
  125.             ActiveRecord::$database_settings parse_ini_file(self::$config_path."/database.ini"true);
  126.         }
  127.  
  128.     }
  129.  
  130.     function include_env_config({
  131.         # Include the application environment specific config file
  132.         if(file_exists(self::$environments_path."/".TRAX_ENV.".php")) {
  133.             include_once(self::$environments_path."/".TRAX_ENV.".php");
  134.         }
  135.     }
  136.  
  137.     function version({
  138.         return implode('.'array(self::MAJORself::MINORself::TINY));    
  139.     }
  140. }
  141.  
  142.  
  143. ###################################################################
  144. # Auto include model / controller / other app specific libs files
  145. ###################################################################
  146. function __autoload($class_name{
  147.     $file Inflector::underscore($class_name).".php";
  148.     $file_org $class_name.".php";
  149.  
  150.     if(file_exists(Trax::$models_path."/$file")) {
  151.         # Include model classes
  152.         include_once(Trax::$models_path."/$file");
  153.     elseif(file_exists(Trax::$controllers_path."/$file")) {
  154.         # Include extra controller classes
  155.         include_once(Trax::$controllers_path."/$file");
  156.     elseif(file_exists(Trax::$lib_path."/$file")) {
  157.         # Include users application libs
  158.         include_once(Trax::$lib_path."/$file");
  159.     elseif(file_exists(Trax::$lib_path."/$file_org")) {
  160.         # Include users application libs
  161.         include_once(Trax::$lib_path."/$file_org");
  162.     }
  163. }
  164.  
  165.  
  166. ?>

Documentation generated on Mon, 21 May 2007 22:29:18 -0600 by phpDocumentor 1.3.2