mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding new methods to Configure and moving all core messages using DEBUG to use Configure::read()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4069 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b72ab690d4
commit
9ca5e14891
11 changed files with 172 additions and 24 deletions
|
@ -80,7 +80,7 @@
|
|||
$Dispatcher=new Dispatcher();
|
||||
$Dispatcher->dispatch($url);
|
||||
}
|
||||
if (DEBUG) {
|
||||
if (Configure::read() > 0) {
|
||||
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
|
||||
}
|
||||
?>
|
|
@ -566,7 +566,7 @@
|
|||
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way.
|
||||
*/
|
||||
function debug($var = false, $showHtml = false) {
|
||||
if (DEBUG) {
|
||||
if (Configure::read() > 0) {
|
||||
print "\n<pre class=\"cake_debug\">\n";
|
||||
ob_start();
|
||||
print_r($var);
|
||||
|
@ -749,7 +749,7 @@
|
|||
* @param array $var
|
||||
*/
|
||||
function pr($var) {
|
||||
if (DEBUG > 0) {
|
||||
if (Configure::read() > 0) {
|
||||
echo "<pre>";
|
||||
print_r($var);
|
||||
echo "</pre>";
|
||||
|
|
|
@ -93,15 +93,7 @@ if (!defined('PHP5')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
} else {
|
||||
error_reporting(0);
|
||||
}
|
||||
Configure::write('debug', DEBUG);
|
||||
|
||||
require CAKE . 'dispatcher.php';
|
||||
|
||||
|
|
|
@ -91,6 +91,162 @@ class Configure extends Object {
|
|||
}
|
||||
return $instance[0];
|
||||
}
|
||||
/**
|
||||
* Used to write a dynamic var in the Configure instance.
|
||||
*
|
||||
* Usage
|
||||
* Configure::write('One.key1', 'value of the Configure::One[key1]');
|
||||
* Configure::write(array('One.key1' => 'value of the Configure::One[key1]'));
|
||||
* Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]');
|
||||
* Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]'));
|
||||
*
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function write($config, $value = null){
|
||||
$_this =& Configure::getInstance();
|
||||
|
||||
if(!is_array($config) && $value !== null) {
|
||||
$name = $_this->__configVarNames($config);
|
||||
|
||||
if(count($name) > 1){
|
||||
$_this->{$name[0]}[$name[1]] = $value;
|
||||
} else {
|
||||
$_this->{$name[0]} = $value;
|
||||
}
|
||||
} else {
|
||||
|
||||
foreach($config as $names => $value){
|
||||
$name = $_this->__configVarNames($names);
|
||||
if(count($name) > 1){
|
||||
$_this->{$name[0]}[$name[1]] = $value;
|
||||
} else {
|
||||
$_this->{$name[0]} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($config == 'debug' || (is_array($config) && in_array('debug', $config))) {
|
||||
if ($_this->debug) {
|
||||
error_reporting(E_ALL);
|
||||
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
} else {
|
||||
error_reporting(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used to read Configure::$var
|
||||
*
|
||||
* Usage
|
||||
* Configure::read('Name'); will return all values for Name
|
||||
* Configure::read('Name.key'); will return only the value of Configure::Name[key]
|
||||
*
|
||||
* @param string $var
|
||||
* @return string value of Configure::$var
|
||||
* @access public
|
||||
*/
|
||||
function read($var = 'debug'){
|
||||
$_this =& Configure::getInstance();
|
||||
if($var === 'debug') {
|
||||
if(!isset($_this->debug)){
|
||||
$_this->debug = DEBUG;
|
||||
}
|
||||
return $_this->debug;
|
||||
}
|
||||
|
||||
$name = $_this->__configVarNames($var);
|
||||
if(count($name) > 1){
|
||||
return $_this->{$name[0]}[$name[1]];
|
||||
} else {
|
||||
return $_this->{$name[0]};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used to delete a var from the Configure instance.
|
||||
*
|
||||
* Usage:
|
||||
* Configure::delete('Name'); will delete the entire Configure::Name
|
||||
* Configure::delete('Name.key'); will delete only the Configure::Name[key]
|
||||
*
|
||||
* @param string $var the var to be deleted
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function delete($var = null){
|
||||
$_this =& Configure::getInstance();
|
||||
|
||||
$name = $_this->__configVarNames($var);
|
||||
if(count($name) > 1){
|
||||
unset($_this->{$name[0]}[$name[1]]);
|
||||
} else {
|
||||
unset($_this->{$name[0]});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Will load a file from app/config/configure_file.php
|
||||
* variables in the files should be formated like:
|
||||
* $config['name'] = 'value';
|
||||
* These will be used to create dynamic Configure vars.
|
||||
*
|
||||
* Usage Configure::load('configure_file');
|
||||
*
|
||||
* @param string $fileName name of file to load, extension must be .php and only the name should be used, not the extenstion
|
||||
* @return Configure::write
|
||||
* @access public
|
||||
*/
|
||||
function load($fileName) {
|
||||
$_this =& Configure::getInstance();
|
||||
|
||||
if(config($fileName) === false) {
|
||||
trigger_error("Configure::load() - $fileName.php not found", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
if(!isset($config)){
|
||||
trigger_error("Configure::load() - no variable \$config found in $fileName.php", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
return $_this->write($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine the current version of CakePHP
|
||||
*
|
||||
* Usage Configure::version();
|
||||
*
|
||||
* @return string Current version of CakePHP
|
||||
* @access public
|
||||
*/
|
||||
function version() {
|
||||
$_this =& Configure::getInstance();
|
||||
if(!isset($_this->Cake['version'])){
|
||||
require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
|
||||
$_this->write($config);
|
||||
}
|
||||
return $_this->Cake['version'];
|
||||
}
|
||||
/**
|
||||
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
function __configVarNames($name) {
|
||||
if (is_string($name)) {
|
||||
if (strpos($name, ".")) {
|
||||
$name = explode(".", $name);
|
||||
} else {
|
||||
$name = array($name);
|
||||
}
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
/**
|
||||
* Sets the var modelPaths
|
||||
*
|
||||
|
|
|
@ -76,7 +76,7 @@ class ErrorHandler extends Object{
|
|||
$this->controller =& new Controller();
|
||||
$this->controller->cacheAction = false;
|
||||
}
|
||||
if (DEBUG > 0 || $method == 'error') {
|
||||
if (Configure::read() > 0 || $method == 'error') {
|
||||
call_user_func_array(array(&$this, $method), $messages);
|
||||
} else {
|
||||
call_user_func_array(array(&$this, 'error404'), $messages);
|
||||
|
|
|
@ -62,7 +62,7 @@ class DboPear extends DboSource{
|
|||
$this->config =$config;
|
||||
$dsn =$config['driver'] . '://' . $config['login'] . ':' . $config['password'] . '@'
|
||||
. $config['host'] . '/' . $config['database'];
|
||||
$options=array('debug' => DEBUG - 1,
|
||||
$options=array('debug' => Configure::read() - 1,
|
||||
'portability' => DB_PORTABILITY_ALL,);
|
||||
|
||||
$this->_pear =&DB::connect($dsn, $options);
|
||||
|
|
|
@ -81,8 +81,8 @@ class DboSource extends DataSource {
|
|||
* Constructor
|
||||
*/
|
||||
function __construct($config = null, $autoConnect = true) {
|
||||
$this->debug = DEBUG > 0;
|
||||
$this->fullDebug = DEBUG > 1;
|
||||
$this->debug = Configure::read() > 0;
|
||||
$this->fullDebug = Configure::read() > 1;
|
||||
parent::__construct($config);
|
||||
|
||||
if ($autoConnect) {
|
||||
|
@ -135,7 +135,7 @@ class DboSource extends DataSource {
|
|||
return $this->__sources;
|
||||
}
|
||||
|
||||
if (DEBUG > 0) {
|
||||
if (Configure::read() > 0) {
|
||||
$expires = "+30 seconds";
|
||||
} else {
|
||||
$expires = "+999 days";
|
||||
|
@ -670,7 +670,7 @@ class DboSource extends DataSource {
|
|||
if ($query) {
|
||||
|
||||
if (!isset($resultSet) || !is_array($resultSet)) {
|
||||
if (DEBUG) {
|
||||
if (Configure::read() > 0) {
|
||||
e('<div style = "font: Verdana bold 12px; color: #FF0000">SQL Error in model ' . $model->name . ': ');
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
e($this->error);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<head>
|
||||
<title><?php echo $page_title?></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<?php if(DEBUG == 0) { ?>
|
||||
<?php if(Configure::read() == 0) { ?>
|
||||
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
|
||||
<?php } ?>
|
||||
<style><!--
|
||||
|
|
|
@ -382,7 +382,7 @@ class View extends Object {
|
|||
function renderLayout($content_for_layout) {
|
||||
$layout_fn = $this->_getLayoutFileName();
|
||||
|
||||
if (DEBUG > 2 && $this->controller != null) {
|
||||
if (Configure::read() > 2 && $this->controller != null) {
|
||||
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->controller), false);
|
||||
} else {
|
||||
$debug = '';
|
||||
|
@ -685,7 +685,7 @@ class View extends Object {
|
|||
|
||||
ob_start();
|
||||
|
||||
if (DEBUG) {
|
||||
if (Configure::read() > 0) {
|
||||
include ($___viewFn);
|
||||
} else {
|
||||
@include ($___viewFn);
|
||||
|
@ -797,7 +797,7 @@ class View extends Object {
|
|||
ob_start();
|
||||
include ($filename);
|
||||
|
||||
if (DEBUG && $this->layout != 'xml') {
|
||||
if (Configure::read() > 0 && $this->layout != 'xml') {
|
||||
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<head>
|
||||
<title><?php echo $page_title?></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<?php if(DEBUG == 0) { ?>
|
||||
<?php if(Configure::read() == 0) { ?>
|
||||
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
|
||||
<?php } ?>
|
||||
<style><!--
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
$Dispatcher=new Dispatcher();
|
||||
$Dispatcher->dispatch($url);
|
||||
}
|
||||
if (DEBUG) {
|
||||
if (Configure::read()) {
|
||||
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue