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

@ -462,43 +462,41 @@ class Debugger extends Object {
* @access private * @access private
*/ */
function __output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) { 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);
$files = $_this->trace(array('start' => 2, 'format' => 'points')); $trace = $this->trace(array('start' => 2, 'depth' => '20'));
$listing = $_this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $_this->trace(array('start' => 2, 'depth' => '20'));
$context = array(); $context = array();
foreach ((array)$kontext as $var => $value) { 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: default:
case 'js': 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>]"; $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) { if (Configure::read() > 0) {
debug($out, false, false); debug($out, false, false);
echo '<div id="CakeStackTrace' . count($_this->errors) . '" class="cake-stack-trace" style="display: 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\")"; $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>"; echo "<a href='javascript:void(0);' onclick='{$link}'>Code</a>";
if (!empty($context)) { 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>"; echo " | <a href='javascript:void(0);' onclick='{$link}'>Context</a>";
if (!empty($helpCode)) { 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 implode("\n", $context);
echo "</pre>"; echo "</pre>";
} }
if (!empty($listing)) { 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); pr(implode("\n", $listing) . "\n", false);
echo '</div>'; echo '</div>';
} }
@ -523,7 +521,7 @@ class Debugger extends Object {
echo "Trace:\n" . $trace; echo "Trace:\n" . $trace;
break; break;
case 'log': case 'log':
$_this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace')); $this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'));
break; break;
case false: case false:
$this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'); $this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace');

View file

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

View file

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

View file

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

View file

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

View file

@ -951,12 +951,11 @@ class Validation extends Object {
* @access private * @access private
*/ */
function __reset() { function __reset() {
$_this =& Validation::getInstance(); $this->check = null;
$_this->check = null; $this->regex = null;
$_this->regex = null; $this->country = null;
$_this->country = null; $this->deep = null;
$_this->deep = null; $this->type = null;
$_this->type = null;
} }
} }
?> ?>