[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/ -> configure.php (source)

   1  <?php
   2  /* SVN FILE: $Id: configure.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * Short description for file.
   5   *
   6   * Long description for file
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  11   * Copyright 2005-2007, Cake Software Foundation, Inc.
  12   *                                1785 E. Sahara Avenue, Suite 490-204
  13   *                                Las Vegas, Nevada 89104
  14   *
  15   * Licensed under The MIT License
  16   * Redistributions of files must retain the above copyright notice.
  17   *
  18   * @filesource
  19   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  20   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21   * @package            cake
  22   * @subpackage        cake.cake.libs
  23   * @since            CakePHP(tm) v 1.0.0.2363
  24   * @version            $Revision: 4409 $
  25   * @modifiedby        $LastChangedBy: phpnut $
  26   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  27   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  28   */
  29  /**
  30   * Short description for file.
  31   *
  32   * Long description for file
  33   *
  34   * @package        cake
  35   * @subpackage    cake.cake.libs
  36   */
  37  class Configure extends Object {
  38  /**
  39   * Hold array with paths to view files
  40   *
  41   * @var array
  42   * @access public
  43   */
  44      var $viewPaths = array();
  45  /**
  46   * Hold array with paths to controller files
  47   *
  48   * @var array
  49   * @access public
  50   */
  51      var $controllerPaths = array();
  52  /**
  53   * Enter description here...
  54   *
  55   * @var array
  56   * @access public
  57   */
  58      var $modelPaths = array();
  59  /**
  60   * Enter description here...
  61   *
  62   * @var array
  63   * @access public
  64   */
  65      var $helperPaths = array();
  66  /**
  67   * Enter description here...
  68   *
  69   * @var array
  70   * @access public
  71   */
  72      var $componentPaths = array();
  73  /**
  74   * Enter description here...
  75   *
  76   * @var integer
  77   * @access public
  78   */
  79      var $debug = null;
  80  /**
  81   * Return a singleton instance of Configure.
  82   *
  83   * @return Configure instance
  84   * @access public
  85   */
  86      function &getInstance() {
  87          static $instance = array();
  88          if (!$instance) {
  89              $instance[0] =& new Configure;
  90              $instance[0]->__loadBootstrap();
  91          }
  92          return $instance[0];
  93      }
  94  /**
  95   * Used to write a dynamic var in the Configure instance.
  96   *
  97   * Usage
  98   * Configure::write('One.key1', 'value of the Configure::One[key1]');
  99   * Configure::write(array('One.key1' => 'value of the Configure::One[key1]'));
 100   * Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]');
 101   * Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]'));
 102   *
 103   * @param array $config
 104   * @return void
 105   * @access public
 106   */
 107  	function write($config, $value = null){
 108          $_this =& Configure::getInstance();
 109  
 110          if(!is_array($config) && $value !== null) {
 111              $name = $_this->__configVarNames($config);
 112  
 113              if(count($name) > 1){
 114                  $_this->{$name[0]}[$name[1]] = $value;
 115              } else {
 116                  $_this->{$name[0]} = $value;
 117              }
 118          } else {
 119  
 120              foreach($config as $names => $value){
 121                  $name = $_this->__configVarNames($names);
 122                  if(count($name) > 1){
 123                      $_this->{$name[0]}[$name[1]] = $value;
 124                  } else {
 125                      $_this->{$name[0]} = $value;
 126                  }
 127              }
 128          }
 129  
 130          if ($config == 'debug' || (is_array($config) && in_array('debug', $config))) {
 131              if ($_this->debug) {
 132                  error_reporting(E_ALL);
 133  
 134                  if (function_exists('ini_set')) {
 135                      ini_set('display_errors', 1);
 136                  }
 137              } else {
 138                  error_reporting(0);
 139              }
 140          }
 141      }
 142  /**
 143   * Used to read Configure::$var
 144   *
 145   * Usage
 146   * Configure::read('Name'); will return all values for Name
 147   * Configure::read('Name.key'); will return only the value of Configure::Name[key]
 148   *
 149   * @param string $var
 150   * @return string value of Configure::$var
 151   * @access public
 152   */
 153  	function read($var = 'debug'){
 154          $_this =& Configure::getInstance();
 155          if($var === 'debug') {
 156              if(!isset($_this->debug)){
 157                  $_this->debug = DEBUG;
 158              }
 159              return $_this->debug;
 160          }
 161  
 162          $name = $_this->__configVarNames($var);
 163          if(count($name) > 1){
 164              if(isset($_this->{$name[0]}[$name[1]])) {
 165                  return $_this->{$name[0]}[$name[1]];
 166              }
 167              return null;
 168          } else {
 169              if(isset($_this->{$name[0]})) {
 170                  return $_this->{$name[0]};
 171              }
 172              return null;
 173          }
 174      }
 175  /**
 176   * Used to delete a var from the Configure instance.
 177   *
 178   * Usage:
 179   * Configure::delete('Name'); will delete the entire Configure::Name
 180   * Configure::delete('Name.key'); will delete only the Configure::Name[key]
 181   *
 182   * @param string $var the var to be deleted
 183   * @return void
 184   * @access public
 185   */
 186  	function delete($var = null){
 187          $_this =& Configure::getInstance();
 188  
 189          $name = $_this->__configVarNames($var);
 190          if(count($name) > 1){
 191              unset($_this->{$name[0]}[$name[1]]);
 192          } else {
 193              unset($_this->{$name[0]});
 194          }
 195      }
 196  /**
 197   * Will load a file from app/config/configure_file.php
 198   * variables in the files should be formated like:
 199   *  $config['name'] = 'value';
 200   * These will be used to create dynamic Configure vars.
 201   *
 202   * Usage Configure::load('configure_file');
 203   *
 204   * @param string $fileName name of file to load, extension must be .php and only the name should be used, not the extenstion
 205   * @return Configure::write
 206   * @access public
 207   */
 208  	function load($fileName) {
 209          $_this =& Configure::getInstance();
 210  
 211          if(!file_exists(CONFIGS . $fileName . '.php')) {
 212              trigger_error("Configure::load() - $fileName.php not found", E_USER_WARNING);
 213              return false;
 214          }
 215          include(CONFIGS . $fileName . '.php');
 216          if(!isset($config)){
 217              trigger_error("Configure::load() - no variable \$config found in $fileName.php", E_USER_WARNING);
 218              return false;
 219          }
 220          return $_this->write($config);
 221      }
 222  
 223  /**
 224   * Used to determine the current version of CakePHP
 225   *
 226   * Usage Configure::version();
 227   *
 228   * @return string Current version of CakePHP
 229   * @access public
 230   */
 231  	function version() {
 232          $_this =& Configure::getInstance();
 233          if(!isset($_this->Cake['version'])){
 234              require (CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
 235              $_this->write($config);
 236          }
 237          return $_this->Cake['version'];
 238      }
 239  /**
 240   * Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
 241   *
 242   * @param mixed $name
 243   * @return array
 244   * @access private
 245   */
 246  	function __configVarNames($name) {
 247          if (is_string($name)) {
 248              if (strpos($name, ".")) {
 249                  $name = explode(".", $name);
 250              } else {
 251                  $name = array($name);
 252              }
 253          }
 254          return $name;
 255      }
 256  /**
 257   * Sets the var modelPaths
 258   *
 259   * @param array $modelPaths
 260   * @access private
 261   */
 262  	function __buildModelPaths($modelPaths) {
 263          $_this =& Configure::getInstance();
 264          $_this->modelPaths[] = MODELS;
 265          if (isset($modelPaths)) {
 266              foreach($modelPaths as $value) {
 267                  $_this->modelPaths[] = $value;
 268              }
 269          }
 270      }
 271  /**
 272   * Sets the var viewPaths
 273   *
 274   * @param array $viewPaths
 275   * @access private
 276   */
 277  	function __buildViewPaths($viewPaths) {
 278          $_this =& Configure::getInstance();
 279          $_this->viewPaths[] = VIEWS;
 280          $_this->viewPaths[] = VIEWS . 'errors' . DS;
 281          if (isset($viewPaths)) {
 282              foreach($viewPaths as $value) {
 283                  $_this->viewPaths[] = $value;
 284              }
 285          }
 286      }
 287  /**
 288   * Sets the var controllerPaths
 289   *
 290   * @param array $controllerPaths
 291   * @access private
 292   */
 293  	function __buildControllerPaths($controllerPaths) {
 294          $_this =& Configure::getInstance();
 295          $_this->controllerPaths[] = CONTROLLERS;
 296          if (isset($controllerPaths)) {
 297              foreach($controllerPaths as $value) {
 298                  $_this->controllerPaths[] = $value;
 299              }
 300          }
 301      }
 302  /**
 303   * Sets the var helperPaths
 304   *
 305   * @param array $helperPaths
 306   * @access private
 307   */
 308  	function __buildHelperPaths($helperPaths) {
 309          $_this =& Configure::getInstance();
 310          $_this->helperPaths[] = HELPERS;
 311          if (isset($helperPaths)) {
 312              foreach($helperPaths as $value) {
 313                  $_this->helperPaths[] = $value;
 314              }
 315          }
 316      }
 317  /**
 318   * Sets the var componentPaths
 319   *
 320   * @param array $componentPaths
 321   * @access private
 322   */
 323  	function __buildComponentPaths($componentPaths) {
 324          $_this =& Configure::getInstance();
 325          $_this->componentPaths[] = COMPONENTS;
 326          if (isset($componentPaths)) {
 327              foreach($componentPaths as $value) {
 328                  $_this->componentPaths[] = $value;
 329              }
 330          }
 331      }
 332  /**
 333   * Loads the app/config/bootstrap.php
 334   * If the alternative paths are set in this file
 335   * they will be added to the paths vars
 336   *
 337   * @access private
 338   */
 339  	function __loadBootstrap() {
 340          $_this =& Configure::getInstance();
 341          $modelPaths = null;
 342          $viewPaths = null;
 343          $controllerPaths = null;
 344          $helperPaths = null;
 345          $componentPaths = null;
 346          require APP_PATH . 'config' . DS . 'bootstrap.php';
 347          $_this->__buildModelPaths($modelPaths);
 348          $_this->__buildViewPaths($viewPaths);
 349          $_this->__buildControllerPaths($controllerPaths);
 350          $_this->__buildHelperPaths($helperPaths);
 351          $_this->__buildComponentPaths($componentPaths);
 352      }
 353  }
 354  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7