Adding more optimizations for the static classes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7736 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-10-12 03:52:24 +00:00
parent 3c50e54213
commit 47f78d13a0
6 changed files with 63 additions and 77 deletions

View file

@ -108,7 +108,7 @@ class Debugger extends Object {
}
/**
* Formats and outputs the passed var
*
*
* @param $var mixed the variable to dump
* @return void
* @see exportVar
@ -121,7 +121,7 @@ class Debugger extends Object {
}
/**
* Neatly logs a given var
*
*
* @param $var mixed Variable or content to log
* @param $level int type of log to use. Defaults to LOG_DEBUG
* @return void
@ -462,43 +462,41 @@ class Debugger extends Object {
* @access private
*/
function __output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) {
$_this = Debugger::getInstance();
$files = $_this->trace(array('start' => 2, 'format' => 'points'));
$listing = $_this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $_this->trace(array('start' => 2, 'depth' => '20'));
$files = $this->trace(array('start' => 2, 'format' => 'points'));
$listing = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $this->trace(array('start' => 2, 'depth' => '20'));
$context = array();
foreach ((array)$kontext as $var => $value) {
$context[] = "\${$var}\t=\t" . $_this->exportVar($value, 1);
$context[] = "\${$var}\t=\t" . $this->exportVar($value, 1);
}
switch ($_this->__outputFormat) {
switch ($this->__outputFormat) {
default:
case 'js':
$link = "document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
$link = "document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
$out = "<a href='javascript:void(0);' onclick='{$link}'><b>{$error}</b> ({$code})</a>: {$description} [<b>{$file}</b>, line <b>{$line}</b>]";
if (Configure::read() > 0) {
debug($out, false, false);
echo '<div id="CakeStackTrace' . count($_this->errors) . '" class="cake-stack-trace" style="display: none;">';
$link = "document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
echo '<div id="CakeStackTrace' . count($this->errors) . '" class="cake-stack-trace" style="display: none;">';
$link = "document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
echo "<a href='javascript:void(0);' onclick='{$link}'>Code</a>";
if (!empty($context)) {
$link = "document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
$link = "document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
echo " | <a href='javascript:void(0);' onclick='{$link}'>Context</a>";
if (!empty($helpCode)) {
echo " | <a href='{$_this->helpPath}{$helpCode}' target='_blank'>Help</a>";
echo " | <a href='{$this->helpPath}{$helpCode}' target='_blank'>Help</a>";
}
echo "<pre id=\"CakeErrorContext" . count($_this->errors) . "\" class=\"cake-context\" style=\"display: none;\">";
echo "<pre id=\"CakeErrorContext" . count($this->errors) . "\" class=\"cake-context\" style=\"display: none;\">";
echo implode("\n", $context);
echo "</pre>";
}
if (!empty($listing)) {
echo "<div id=\"CakeErrorCode" . count($_this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">";
echo "<div id=\"CakeErrorCode" . count($this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">";
pr(implode("\n", $listing) . "\n", false);
echo '</div>';
}
@ -523,7 +521,7 @@ class Debugger extends Object {
echo "Trace:\n" . $trace;
break;
case 'log':
$_this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'));
$this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'));
break;
case false:
$this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace');

View file

@ -431,9 +431,8 @@ class I18n extends Object {
* @access private
*/
function __destruct() {
$_this =& I18n::getInstance();
if ($_this->__cache) {
Cache::write($_this->domain, array_filter($_this->__domains), '_cake_core_');
if ($this->__cache) {
Cache::write($this->domain, array_filter($this->__domains), '_cake_core_');
}
}
}

View file

@ -145,10 +145,9 @@ class Inflector extends Object {
* Initializes plural inflection rules
*
* @return void
* @access protected
* @access private
*/
function __initPluralRules() {
$_this =& Inflector::getInstance();
$corePluralRules = array(
'/(s)tatus$/i' => '\1\2tatuses',
'/(quiz)$/i' => '\1zes',
@ -217,12 +216,12 @@ class Inflector extends Object {
'turf' => 'turfs');
$pluralRules = Set::pushDiff($_this->__pluralRules, $corePluralRules);
$uninflected = Set::pushDiff($_this->__uninflectedPlural, $coreUninflectedPlural);
$irregular = Set::pushDiff($_this->__irregularPlural, $coreIrregularPlural);
$pluralRules = Set::pushDiff($this->__pluralRules, $corePluralRules);
$uninflected = Set::pushDiff($this->__uninflectedPlural, $coreUninflectedPlural);
$irregular = Set::pushDiff($this->__irregularPlural, $coreIrregularPlural);
$_this->pluralRules = array('pluralRules' => $pluralRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$_this->pluralized = array();
$this->pluralRules = array('pluralRules' => $pluralRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$this->pluralized = array();
}
/**
* Return $word in plural form.
@ -276,8 +275,6 @@ class Inflector extends Object {
* @access protected
*/
function __initSingularRules() {
$_this =& Inflector::getInstance();
$coreSingularRules = array(
'/(s)tatuses$/i' => '\1\2tatus',
'/^(.*)(menu)s$/i' => '\1\2',
@ -355,12 +352,12 @@ class Inflector extends Object {
'trilbys' => 'trilby',
'turfs' => 'turf');
$singularRules = Set::pushDiff($_this->__singularRules, $coreSingularRules);
$uninflected = Set::pushDiff($_this->__uninflectedSingular, $coreUninflectedSingular);
$irregular = Set::pushDiff($_this->__irregularSingular, $coreIrregularSingular);
$singularRules = Set::pushDiff($this->__singularRules, $coreSingularRules);
$uninflected = Set::pushDiff($this->__uninflectedSingular, $coreUninflectedSingular);
$irregular = Set::pushDiff($this->__irregularSingular, $coreIrregularSingular);
$_this->singularRules = array('singularRules' => $singularRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$_this->singularized = array();
$this->singularRules = array('singularRules' => $singularRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$this->singularized = array();
}
/**
* Return $word in singular form.

View file

@ -237,8 +237,6 @@ class ConnectionManager extends Object {
* @access private
*/
function __getDriver($config) {
$_this =& ConnectionManager::getInstance();
if (!isset($config['datasource'])) {
$config['datasource'] = 'dbo';
}
@ -246,7 +244,7 @@ class ConnectionManager extends Object {
if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
$filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
$classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
$parent = $_this->__getDriver(array('datasource' => $config['datasource']));
$parent = $this->__getDriver(array('datasource' => $config['datasource']));
} else {
$filename = $config['datasource'] . '_source';
$classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));

View file

@ -33,7 +33,6 @@
if (!class_exists('Object')) {
App::import('Core', 'Object');
}
/**
* Parses the request URL into controller, action, and parameters.
*
@ -422,10 +421,10 @@ class Router extends Object {
foreach ($_this->routes as $i => $route) {
if (count($route) === 3) {
$route = $_this->compile($i);
$route = $_this->__compile($i);
}
if (($r = $_this->matchRoute($route, $url)) !== false) {
if (($r = $_this->__matchRoute($route, $url)) !== false) {
$_this->__currentRoute[] = $route;
list($route, $regexp, $names, $defaults, $params) = $route;
$argOptions = array();
@ -494,17 +493,16 @@ class Router extends Object {
* @return mixed Boolean false on failure, otherwise array
* @access public
*/
function matchRoute($route, $url) {
function __matchRoute($route, $url) {
list($route, $regexp, $names, $defaults) = $route;
if (!preg_match($regexp, $url, $r)) {
return false;
} else {
$_this =& Router::getInstance();
foreach ($defaults as $key => $val) {
if ($key{0} === '[' && preg_match('/^\[(\w+)\]$/', $key, $header)) {
if (isset($_this->__headerMap[$header[1]])) {
$header = $_this->__headerMap[$header[1]];
if (isset($this->__headerMap[$header[1]])) {
$header = $this->__headerMap[$header[1]];
} else {
$header = 'http_' . $header[1];
}
@ -531,9 +529,9 @@ class Router extends Object {
*
* @param integer $i
* @return array Returns an array containing the compiled route
* @access public
* @access private
*/
function compile($i) {
function __compile($i) {
$route = $this->routes[$i];
if (!list($pattern, $names) = $this->writeRoute($route[0], $route[1], $route[2])) {
@ -556,16 +554,15 @@ class Router extends Object {
*/
function __parseExtension($url) {
$ext = null;
$_this =& Router::getInstance();
if ($_this->__parseExtensions) {
if ($this->__parseExtensions) {
if (preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) === 1) {
$match = substr($match[0], 1);
if (empty($_this->__validExtensions)) {
if (empty($this->__validExtensions)) {
$url = substr($url, 0, strpos($url, '.' . $match));
$ext = $match;
} else {
foreach ($_this->__validExtensions as $name) {
foreach ($this->__validExtensions as $name) {
if (strcasecmp($name, $match) === 0) {
$url = substr($url, 0, strpos($url, '.' . $name));
$ext = $match;
@ -582,18 +579,17 @@ class Router extends Object {
/**
* Connects the default, built-in routes, including admin routes, and (deprecated) web services
* routes.
*
*
* @return void
* @access private
*/
function __connectDefaultRoutes() {
$_this =& Router::getInstance();
if ($_this->__defaultsMapped) {
if ($this->__defaultsMapped) {
return;
}
if ($_this->__admin) {
$params = array('prefix' => $_this->__admin, $_this->__admin => true);
if ($this->__admin) {
$params = array('prefix' => $this->__admin, $this->__admin => true);
}
if ($plugins = Configure::listObjects('plugin')) {
@ -602,25 +598,25 @@ class Router extends Object {
}
$match = array('plugin' => implode('|', $plugins));
$_this->connect('/:plugin/:controller/:action/*', array(), $match);
$this->connect('/:plugin/:controller/:action/*', array(), $match);
if ($_this->__admin) {
$_this->connect("/{$_this->__admin}/:plugin/:controller", $params, $match);
$_this->connect("/{$_this->__admin}/:plugin/:controller/:action/*", $params, $match);
if ($this->__admin) {
$this->connect("/{$this->__admin}/:plugin/:controller", $params, $match);
$this->connect("/{$this->__admin}/:plugin/:controller/:action/*", $params, $match);
}
}
if ($_this->__admin) {
$_this->connect("/{$_this->__admin}/:controller", $params);
$_this->connect("/{$_this->__admin}/:controller/:action/*", $params);
if ($this->__admin) {
$this->connect("/{$this->__admin}/:controller", $params);
$this->connect("/{$this->__admin}/:controller/:action/*", $params);
}
$_this->connect('/:controller', array('action' => 'index'));
$_this->connect('/:controller/:action/*');
$this->connect('/:controller', array('action' => 'index'));
$this->connect('/:controller/:action/*');
if ($_this->named['rules'] === false) {
$_this->connectNamed(true);
if ($this->named['rules'] === false) {
$this->connectNamed(true);
}
$_this->__defaultsMapped = true;
$this->__defaultsMapped = true;
}
/**
* Takes parameter and path information back from the Dispatcher
@ -825,7 +821,7 @@ class Router extends Object {
foreach ($_this->routes as $i => $route) {
if (count($route) === 3) {
$route = $_this->compile($i);
$route = $_this->__compile($i);
}
$originalUrl = $url;
@ -1060,10 +1056,9 @@ class Router extends Object {
$count = count($params['named']);
$keys = array_keys($params['named']);
$named = array();
$_this =& Router::getInstance();
for ($i = 0; $i < $count; $i++) {
$named[] = $keys[$i] . $_this->named['separator'] . $params['named'][$keys[$i]];
$named[] = $keys[$i] . $this->named['separator'] . $params['named'][$keys[$i]];
}
$params['named'] = join('/', $named);
}

View file

@ -946,17 +946,16 @@ class Validation extends Object {
}
/**
* Reset internal variables for another validation run.
*
*
* @return void
* @access private
*/
function __reset() {
$_this =& Validation::getInstance();
$_this->check = null;
$_this->regex = null;
$_this->country = null;
$_this->deep = null;
$_this->type = null;
$this->check = null;
$this->regex = null;
$this->country = null;
$this->deep = null;
$this->type = null;
}
}
?>