More optimization refactoring.

Fix cache but causing  object_map to be created and deleted on each request.
Replacing function and method calls with better performing code.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7596 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-09-12 05:11:34 +00:00
parent c9c18741fb
commit cb487bd6e6
37 changed files with 183 additions and 182 deletions

View file

@ -40,7 +40,7 @@
* Patch for PHP < 5.0
*/
if (!function_exists('clone')) {
if (version_compare(phpversion(), '5.0') < 0) {
if (version_compare(PHP_VERSION, '5.0') < 0) {
eval ('
function clone($object)
{
@ -399,7 +399,7 @@ if (!function_exists('clone')) {
return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
break;
case 'CGI_MODE':
return (substr(php_sapi_name(), 0, 3) == 'cgi');
return (PHP_SAPI == 'cgi');
break;
case 'HTTP_BASE':
return preg_replace ('/^([^.])*/i', null, env('HTTP_HOST'));
@ -550,17 +550,18 @@ if (!function_exists('clone')) {
/**
* Recursively strips slashes from all values in an array
*
* @param array $value Array of values to strip slashes
* @param array $values Array of values to strip slashes
* @return mixed What is returned from calling stripslashes
*/
function stripslashes_deep($value) {
if (is_array($value)) {
$return = array_map('stripslashes_deep', $value);
return $return;
} else {
$return = stripslashes($value);
return $return ;
function stripslashes_deep($values) {
if (is_array($values)) {
foreach ($values as $key => $value) {
$values[$key] = stripslashes_deep($value);
}
} else {
$values = stripslashes($values);
}
return $values ;
}
/**
* Returns a translated string if one is found, or the submitted message if not found.

View file

@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!defined('PHP5')) {
define ('PHP5', (phpversion() >= 5));
define ('PHP5', (PHP_VERSION >= 5));
}
/**
* Configuration, directory layout and standard libraries

View file

@ -147,7 +147,7 @@ class ShellDispatcher {
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('PHP5', (phpversion() >= 5));
define('PHP5', (PHP_VERSION >= 5));
define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);

View file

@ -228,12 +228,21 @@ class Dispatcher extends Object {
$controller->beforeFilter();
$controller->Component->startup($controller);
$classMethods = array_diff(
array_map('strtolower', get_class_methods($controller)),
array_map('strtolower', get_class_methods('Controller'))
);
$childMethods = get_class_methods($controller);
$parentMethods = get_class_methods('Controller');
if (!in_array(strtolower($params['action']), $classMethods)) {
foreach ($childMethods as $key => $value) {
$childMethods[$key] = strtolower($value);
}
foreach ($parentMethods as $key => $value) {
$parentMethods[$key] = strtolower($value);
}
$classMethods = array_diff($childMethods, $parentMethods);
$classMethods = array_flip($classMethods);
if (!isset($classMethods[strtolower($params['action'])])) {
if ($controller->scaffold !== false) {
App::import('Core', 'Scaffold');
return new Scaffold($controller, $params);
@ -247,7 +256,6 @@ class Dispatcher extends Object {
'base' => $this->base)));
}
$output = $controller->dispatchMethod($params['action'], $params['pass']);
if ($controller->autoRender) {
@ -525,7 +533,7 @@ class Dispatcher extends Object {
$uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri);
}
if (Configure::read('App.server') == 'IIS') {
if (PHP_SAPI == 'isapi') {
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
}

View file

@ -71,7 +71,7 @@ class Cache extends Object {
*/
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Cache();
}
return $instance[0];
@ -291,7 +291,6 @@ class Cache extends Object {
if (empty($settings)) {
return null;
}
extract($settings);
if (!$_this->isInitialized($engine)) {
@ -300,8 +299,8 @@ class Cache extends Object {
if (!$key = $_this->_Engine[$engine]->key($key)) {
return false;
}
$success = $_this->_Engine[$engine]->read($settings['prefix'] . $key);
if ($config !== $_this->__name) {
$settings = $_this->set();
}

View file

@ -91,7 +91,7 @@ class FileEngine extends CacheEngine {
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
if(substr(PHP_OS, 0, 3) == "WIN") {
if (DIRECTORY_SEPARATOR == '\\') {
$this->settings['isWindows'] = true;
}
@ -159,7 +159,7 @@ class FileEngine extends CacheEngine {
* @access public
*/
function read($key) {
if($this->__setKey($key) === false || !$this->__init) {
if($this->__setKey($key) === false || !$this->__init || !$this->__File->exists()) {
return false;
}
if ($this->settings['lock']) {

View file

@ -138,7 +138,8 @@ class ClassRegistry {
} else {
$appModel = 'AppModel';
}
${$class} =& new $appModel(array_merge($settings, array('name' => $class)));
$settings['name'] = $class;
${$class} =& new $appModel($settings);
}
if (!isset(${$class})) {
@ -277,7 +278,7 @@ class ClassRegistry {
$duplicate = false;
if ($_this->isKeySet($alias)) {
$model =& $_this->getObject($alias);
if (is_a($model, $class)) {
if (is_a($model, $class) || $model->alias == $class) {
$duplicate =& $model;
}
unset($model);

View file

@ -135,7 +135,6 @@ class Configure extends Object {
* @access public
*/
function listObjects($type, $path = null, $cache = true) {
$_this =& Configure::getInstance();
$objects = array();
$extension = false;
$name = $type;
@ -146,13 +145,13 @@ class Configure extends Object {
$extension = true;
$name = $type . str_replace(DS, '', $path);
}
$_this =& Configure::getInstance();
if (empty($_this->__objects) && $cache === true) {
$_this->__objects = Cache::read('object_map', '_cake_core_');
}
if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
$Inflector =& Inflector::getInstance();
$types = array(
'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false),
'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'),
@ -187,7 +186,9 @@ class Configure extends Object {
}
if ($type !== 'file') {
$objects = array_map(array(&$Inflector, 'camelize'), $objects);
foreach ($objects as $key => $value) {
$objects[$key] = Inflector::camelize($value);
}
}
if ($cache === true && !empty($objects)) {
$_this->__objects[$name] = $objects;
@ -260,13 +261,13 @@ class Configure extends Object {
case 2:
$_this->{$name[0]}[$name[1]] = $value;
break;
default:
case 1:
$_this->{$name[0]} = $value;
break;
}
}
if (array_key_exists('debug', $config)) {
if (isset($config['debug'])) {
if ($_this->debug) {
error_reporting(E_ALL);
@ -365,7 +366,6 @@ class Configure extends Object {
*/
function load($fileName) {
$found = false;
$_this =& Configure::getInstance();
if (file_exists(CONFIGS . $fileName . '.php')) {
include(CONFIGS . $fileName . '.php');
@ -374,7 +374,7 @@ class Configure extends Object {
include(CACHE . 'persistent' . DS . $fileName . '.php');
$found = true;
} else {
foreach ($_this->corePaths('cake') as $key => $path) {
foreach (Configure::corePaths('cake') as $key => $path) {
if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
include($path . DS . 'config' . DS . $fileName . '.php');
$found = true;
@ -391,7 +391,7 @@ class Configure extends Object {
trigger_error(sprintf(__("Configure::load() - no variable \$config found in %s.php", true), $fileName), E_USER_WARNING);
return false;
}
return $_this->write($config);
return Configure::write($config);
}
/**
* Used to determine the current version of CakePHP
@ -421,7 +421,6 @@ class Configure extends Object {
* @access public
*/
function store($type, $name, $data = array()) {
$_this =& Configure::getInstance();
$write = true;
$content = '';
@ -444,7 +443,7 @@ class Configure extends Object {
if (is_null($type)) {
$write = false;
}
$_this->__writeConfig($content, $name, $write);
Configure::__writeConfig($content, $name, $write);
}
/**
* Returns key => value list of all paths where core libs are found
@ -601,22 +600,10 @@ class Configure extends Object {
* @access private
*/
function __loadBootstrap($boot) {
$_this =& Configure::getInstance(false);
$modelPaths = null;
$behaviorPaths = null;
$controllerPaths = null;
$componentPaths = null;
$viewPaths = null;
$helperPaths = null;
$pluginPaths = null;
$vendorPaths = null;
$modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = null;
if ($boot) {
$_this->write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
if (php_sapi_name() == 'isapi') {
$_this->write('App.server', 'IIS');
}
Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
if (!include(CONFIGS . 'core.php')) {
trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
@ -626,15 +613,14 @@ class Configure extends Object {
trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
}
if ($_this->read('Cache.disable') !== true) {
if (Configure::read('Cache.disable') !== true) {
$cache = Cache::config('default');
if (empty($cache['settings'])) {
trigger_error('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', E_USER_WARNING);
$cache = Cache::config('default', array('engine' => 'File'));
}
$path = null;
$prefix = null;
$path = $prefix = null;
if (!empty($cache['settings']['path'])) {
$path = realpath($cache['settings']['path']);
@ -664,7 +650,7 @@ class Configure extends Object {
}
Cache::config('default');
}
$_this->buildPaths(compact('modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths', 'vendorPaths'));
Configure::buildPaths(compact('modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths', 'vendorPaths'));
}
}
/**
@ -744,8 +730,7 @@ class App extends Object {
* @access public
*/
function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
$plugin = null;
$directory = null;
$plugin = $directory = null;
if (is_array($type)) {
extract($type, EXTR_OVERWRITE);
@ -761,7 +746,6 @@ class App extends Object {
} elseif ($name === null) {
$type = 'File';
}
$_this =& App::getInstance();
if (is_array($name)) {
foreach ($name as $class) {
@ -785,7 +769,7 @@ class App extends Object {
}
}
if (!$_this->import($tempType, $plugin . $class)) {
if (!App::import($tempType, $plugin . $class)) {
return false;
}
}
@ -795,6 +779,7 @@ class App extends Object {
if ($name != null && strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
}
$_this =& App::getInstance();
$_this->return = $return;
if (isset($ext)) {
@ -981,21 +966,17 @@ class App extends Object {
if ($plugin) {
$plugin = Inflector::camelize($plugin);
if (isset($_this->__map['Plugin'][$plugin][$type])) {
if (array_key_exists($name, $_this->__map['Plugin'][$plugin][$type])) {
if (isset($_this->__map['Plugin'][$plugin][$type]) && isset($_this->__map['Plugin'][$plugin][$type][$name])) {
return $_this->__map['Plugin'][$plugin][$type][$name];
}
return false;
}
}
if (isset($_this->__map[$type])) {
if (array_key_exists($name, $_this->__map[$type])) {
if (isset($_this->__map[$type]) && isset($_this->__map[$type][$name])) {
return $_this->__map[$type][$name];
}
return false;
}
}
/**
* Used to overload Objects as needed
*
@ -1029,31 +1010,30 @@ class App extends Object {
}
$path = null;
$load = strtolower($type);
$_this = & App::getInstance();
switch ($load) {
case 'model':
if (!class_exists('Model')) {
$_this->import('Core', 'Model', false, Configure::corePaths('model'));
App::import('Core', 'Model', false, Configure::corePaths('model'));
}
$_this->import($type, 'AppModel', false, Configure::read('modelPaths'));
App::import($type, 'AppModel', false, Configure::read('modelPaths'));
if ($plugin) {
$_this->import($type, $plugin . '.' . $name . 'AppModel', false, array(), $plugin . DS . $plugin . '_app_model.php');
App::import($type, $plugin . '.' . $name . 'AppModel', false, array(), $plugin . DS . $plugin . '_app_model.php');
$path = $plugin . DS . 'models' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'behavior':
$_this->import('Core', 'Behavior', false);
App::import('Core', 'Behavior', false);
if ($plugin) {
$path = $plugin . DS . 'models' . DS . 'behaviors' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'controller':
$_this->import($type, 'AppController', false);
App::import($type, 'AppController', false);
if ($plugin) {
$_this->import($type, $plugin . '.' . $name . 'AppController', false, array(), $plugin . DS . $plugin . '_app_controller.php');
App::import($type, $plugin . '.' . $name . 'AppController', false, array(), $plugin . DS . $plugin . '_app_controller.php');
$path = $plugin . DS . 'controllers' . DS;
}
return array('class' => $type, 'suffix' => $type, 'path' => $path);
@ -1071,7 +1051,7 @@ class App extends Object {
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'helper':
$_this->import($type, 'AppHelper', false);
App::import($type, 'AppHelper', false);
if ($plugin) {
$path = $plugin . DS . 'views' . DS . 'helpers' . DS;
}

View file

@ -640,8 +640,8 @@ class EmailComponent extends Object{
*/
function __strip($value, $message = false) {
$search = array(
'/%0a/i', '/%0d/i', '/Content-Type\:/i', '/charset\=/i', '/mime-version\:/i',
'/multipart\/mixed/i', '/bcc\:.*/i','/to\:.*/i','/cc\:.*/i', '/Content-Transfer-Encoding\:/i',
'/(?:%0a)/i', '/(?:%0d)/i', '/(?:Content-Type\:)/i', '/(?:charset\=)/i', '/(?:mime-version\:)/i',
'/(?:multipart\/mixed)/i', '/(?:bcc\:.*)/i','/(?:to\:.*)/i','/(?:cc\:.*)/i', '/(?:Content-Transfer-Encoding\:)/i',
'/\\r/i', '/\\n/i'
);

View file

@ -382,7 +382,7 @@ class RequestHandlerComponent extends Object {
if (env('HTTP_X_FORWARDED_HOST') != null) {
$sess_host = env('HTTP_X_FORWARDED_HOST');
}
return trim(preg_replace('/:.*/', '', $sess_host));
return trim(preg_replace('/(?:\:.*)/', '', $sess_host));
}
/**
* Gets remote client IP
@ -392,7 +392,7 @@ class RequestHandlerComponent extends Object {
*/
function getClientIP() {
if (env('HTTP_X_FORWARDED_FOR') != null) {
$ipaddr = preg_replace('/,.*/', '', env('HTTP_X_FORWARDED_FOR'));
$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
} else {
if (env('HTTP_CLIENT_IP') != null) {
$ipaddr = env('HTTP_CLIENT_IP');
@ -405,7 +405,7 @@ class RequestHandlerComponent extends Object {
$tmpipaddr = env('HTTP_CLIENTADDRESS');
if (!empty($tmpipaddr)) {
$ipaddr = preg_replace('/,.*/', '', $tmpipaddr);
$ipaddr = preg_replace('/(?:,.*)/', '', $tmpipaddr);
}
}
return trim($ipaddr);
@ -555,7 +555,7 @@ class RequestHandlerComponent extends Object {
if (empty($this->__renderType)) {
$controller->viewPath .= '/' . $type;
} else {
$controller->viewPath = preg_replace("/\/{$type}$/", '/' . $type, $controller->viewPath);
$controller->viewPath = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath);
}
$this->__renderType = $type;
$controller->layoutPath = $type;

View file

@ -267,7 +267,7 @@ class SecurityComponent extends Object {
default:
$digest = null;
if (version_compare(phpversion(), '5.1') != -1) {
if (version_compare(PHP_VERSION, '5.1') != -1) {
$digest = env('PHP_AUTH_DIGEST');
} elseif (function_exists('apache_request_headers')) {
$headers = apache_request_headers();

View file

@ -321,7 +321,7 @@ class Scaffold extends Object {
}
foreach ($this->ScaffoldModel->belongsTo as $assocName => $assocData) {
$varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $assocData['foreignKey'])));
$varName = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assocData['foreignKey'])));
$this->controller->set($varName, $this->ScaffoldModel->{$assocName}->find('list'));
}
foreach ($this->ScaffoldModel->hasAndBelongsToMany as $assocName => $assocData) {

View file

@ -96,7 +96,7 @@ class Debugger extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Debugger();
if (Configure::read() > 0) {
Configure::version(); // Make sure the core config is loaded

View file

@ -211,7 +211,7 @@ class File extends Object {
*/
function prepare($data, $forceWindows = false) {
$lineBreak = "\n";
if (substr(PHP_OS,0,3) == "WIN" || $forceWindows === true) {
if (DIRECTORY_SEPARATOR == '\\' || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
@ -341,7 +341,7 @@ class File extends Object {
if (!$ext) {
$ext = $this->ext();
}
return preg_replace( "/[^\w\.-]+/", "_", basename($name, $ext));
return preg_replace( "/(?:[^\w\.-]+)/", "_", basename($name, $ext));
}
/**
* Get md5 Checksum of file with previous check of Filesize

View file

@ -143,7 +143,7 @@ class Folder extends Object {
* The returned array holds two arrays: one of dirs and one of files.
*
* @param boolean $sort
* @param mixed $exceptions either an array or boolean true will no grab dot files
* @param mixed $exceptions either an array or boolean true will not grab dot files
* @param boolean $fullpath true returns the full path
* @return mixed Contents of current directory as an array, false on failure
* @access public
@ -420,7 +420,7 @@ class Folder extends Object {
while (count($this->__directories)) {
$dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions);
array_push($directories, $dir);
$directories[] = $dir;
}
if ($type === null) {

View file

@ -382,7 +382,7 @@ class I18n extends Object {
}
if (isset($_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/[() {}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]["plural-forms"]);
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]["plural-forms"]);
$_this->__domains[$_this->category][$_this->__lang][$domain]["%plural-c"] = $switch;
unset($_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]);
}

View file

@ -126,7 +126,7 @@ class Inflector extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Inflector();
if (file_exists(CONFIGS.'inflections.php')) {
include(CONFIGS.'inflections.php');
@ -139,7 +139,6 @@ class Inflector extends Object {
}
}
return $instance[0];
}
/**

View file

@ -292,12 +292,12 @@ class BehaviorCollection extends Object {
$this->__mappedMethods[$method] = array($alias, $name);
}
$methods = get_class_methods($this->{$name});
$parentMethods = get_class_methods('ModelBehavior');
$callbacks = array('setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete', 'afterError');
$parentMethods = array_flip(get_class_methods('ModelBehavior'));
$callbacks = array('setup' => true, 'cleanup' => true, 'beforeFind' => true, 'afterFind' => true, 'beforeSave' => true, 'afterSave' => true, 'beforeDelete' => true, 'afterDelete' => true, 'afterError' => true);
foreach ($methods as $m) {
if (!in_array($m, $parentMethods)) {
if ($m[0] != '_' && !array_key_exists($m, $this->__methods) && !in_array($m, $callbacks)) {
if (!isset($parentMethods[$m])) {
if ($m[0] != '_' && !array_key_exists($m, $this->__methods) && !isset($callbacks[$m])) {
$this->__methods[$m] = array($m, $name);
}
}
@ -383,8 +383,13 @@ class BehaviorCollection extends Object {
* @access public
*/
function dispatchMethod(&$model, $method, $params = array(), $strict = false) {
$methods = array_map('strtolower', array_keys($this->__methods));
$found = (in_array(strtolower($method), $methods));
$methods = array_keys($this->__methods);
foreach ($methods as $key => $value) {
$methods[$key] = strtolower($value);
}
$method = strtolower($method);
$check = array_flip($methods);
$found = isset($check[$method]);
$call = null;
if ($strict && !$found) {
@ -392,7 +397,7 @@ class BehaviorCollection extends Object {
return null;
} elseif ($found) {
$methods = array_combine($methods, array_values($this->__methods));
$call = $methods[strtolower($method)];
$call = $methods[$method];
} else {
$count = count($this->__mappedMethods);
$mapped = array_keys($this->__mappedMethods);
@ -405,6 +410,7 @@ class BehaviorCollection extends Object {
}
}
}
if (!empty($call)) {
return $this->{$call[1]}->dispatchMethod($model, $call[0], $params);
}

View file

@ -81,7 +81,7 @@ class ConnectionManager extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new ConnectionManager();
}

View file

@ -464,7 +464,7 @@ class DboSource extends DataSource {
$text = 'query';
}
if (php_sapi_name() != 'cli') {
if (PHP_SAPI != 'cli') {
print ("<table class=\"cake-sql-log\" id=\"cakeSqlLog_" . preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true)) . "\" summary=\"Cake SQL Log\" cellspacing=\"0\" border = \"0\">\n<caption>({$this->configKeyName}) {$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n");
print ("<thead>\n<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>\n</thead>\n<tbody>\n");

View file

@ -262,7 +262,7 @@ class Multibyte extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Multibyte();
}
return $instance[0];
@ -372,7 +372,7 @@ class Multibyte extends Object {
*/
function stristr($haystack, $needle, $part = false) {
$_this =& Multibyte::getInstance();
$php = (phpversion() < 5.3);
$php = (PHP_VERSION < 5.3);
if (($php && $part) || $_this->__checkMultibyte($haystack)) {
$check = $_this->strtoupper($haystack);
@ -706,7 +706,7 @@ class Multibyte extends Object {
*/
function strstr($haystack, $needle, $part = false) {
$_this =& Multibyte::getInstance();
$php = (phpversion() < 5.3);
$php = (PHP_VERSION < 5.3);
if (($php && $part) || $_this->__checkMultibyte($haystack)) {
$check = $_this->utf8($haystack);

View file

@ -172,7 +172,7 @@ class Router extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Router();
$instance[0]->__admin = Configure::read('Routing.admin');
}
@ -581,8 +581,9 @@ class Router extends Object {
}
if ($plugins = Configure::listObjects('plugin')) {
$Inflector =& Inflector::getInstance();
$plugins = array_map(array(&$Inflector, 'underscore'), $plugins);
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}
$match = array('plugin' => implode('|', $plugins));
$_this->connect('/:plugin/:controller/:action/*', array(), $match);
@ -886,7 +887,7 @@ class Router extends Object {
$output = str_replace('//', '/', $base . '/' . $output);
} else {
if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0)) || (substr($url, 0, 1) == '#')) {
if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0)) || (!strncmp($url, '#', 1))) {
return $url;
}
if (empty($url)) {
@ -1184,7 +1185,7 @@ class Router extends Object {
while (strpos($url, '//') !== false) {
$url = str_replace('//', '/', $url);
}
$url = preg_replace('/(\/$)/', '', $url);
$url = preg_replace('/(?:(\/$))/', '', $url);
if (empty($url)) {
return '/';
@ -1224,7 +1225,7 @@ class Router extends Object {
*/
function stripPlugin($base, $plugin) {
if ($plugin != null) {
$base = preg_replace('/' . $plugin . '/', '', $base);
$base = preg_replace('/(?:' . $plugin . ')/', '', $base);
$base = str_replace('//', '', $base);
$pos1 = strrpos($base, '/');
$char = strlen($base) - 1;
@ -1251,12 +1252,12 @@ class Router extends Object {
return $param;
}
$return = preg_replace('/^[\\t ]*(?:-!)+/', '', $param);
$return = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $param);
return $return;
}
foreach ($param as $key => $value) {
if (is_string($value)) {
$return[$key] = preg_replace('/^[\\t ]*(?:-!)+/', '', $value);
$return[$key] = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $value);
} else {
foreach ($value as $array => $string) {
$return[$key][$array] = $_this->stripEscape($string);

View file

@ -814,7 +814,9 @@ class Set extends Object {
if (is_string($list)) {
$list = explode($sep, $list);
if ($trim) {
$list = array_map('trim', $list);
foreach ($list as $key => $value) {
$list[$key] = trim($value);
}
}
if ($assoc) {
return Set::normalize($list);

View file

@ -43,7 +43,7 @@ class String extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new String();
}
return $instance[0];

View file

@ -110,7 +110,7 @@ class Validation extends Object {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new Validation();
}
return $instance[0];

View file

@ -193,7 +193,9 @@ class Helper extends Overloadable {
if (!empty($this->themeWeb)) {
$os = env('OS');
if (!empty($os) && strpos($os, 'Windows') !== false) {
if (strpos(WWW_ROOT . $this->themeWeb . $file, '\\') !== false) {
$path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $file);
}
} else {
$path = WWW_ROOT . $this->themeWeb . $file;
}
@ -201,8 +203,11 @@ class Helper extends Overloadable {
$webPath = "{$this->webroot}" . $this->themeWeb . $file;
}
}
if (strpos($webPath, '//') !== false) {
return str_replace('//', '/', $webPath);
}
return $webPath;
}
/**
* Used to remove harmful tags from content

View file

@ -1365,7 +1365,7 @@ class XmlManager {
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new XmlManager();
}
return $instance[0];

View file

@ -99,7 +99,7 @@ class CacheTest extends CakeTestCase {
'duration' => 3600,
'probability' => 100,
'engine' => 'File',
'isWindows' => (substr(PHP_OS, 0, 3) == "WIN")
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($expected, Cache::settings('File'));
}
@ -120,7 +120,7 @@ class CacheTest extends CakeTestCase {
'prefix'=> 'cake_',
'lock' => false,
'serialize'=> true,
'isWindows' => (substr(PHP_OS, 0, 3) == "WIN")
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($settings, $expecting);
}

View file

@ -70,7 +70,7 @@ class CodeCoverageManagerTest extends CakeTestCase {
* @return void
*/
function testNoTestCaseSupplied() {
if (php_sapi_name() != 'cli') {
if (PHP_SAPI != 'cli') {
unset($_GET['group']);
CodeCoverageManager::start(substr(md5(microtime()), 0, 5), new CakeHtmlReporter());
CodeCoverageManager::report(false);

View file

@ -922,7 +922,7 @@ DIGEST;
$expected = array('username' => $user, 'password' => $pw);
$this->assertIdentical($result, $expected);
if (version_compare(phpversion(), '5.1') != -1) {
if (version_compare(PHP_VERSION, '5.1') != -1) {
$_SERVER['PHP_AUTH_DIGEST'] = $digest = <<<DIGEST
Digest username="Mufasa",
realm="testrealm@host.com",

View file

@ -155,7 +155,7 @@ class TestErrorHandlerTest extends CakeTestCase {
* @return void
*/
function skip() {
$this->skipif ((php_sapi_name() == 'cli'), 'TestErrorHandlerTest cannot be run from console');
$this->skipif ((PHP_SAPI == 'cli'), 'TestErrorHandlerTest cannot be run from console');
}
/**
* testError method

View file

@ -1529,5 +1529,4 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
}
?>

View file

@ -187,7 +187,7 @@ class SetTest extends CakeTestCase {
$r = Set::merge('foo', 'bar');
$this->assertIdentical($r, array('foo', 'bar'));
if (substr(phpversion(), 0, 1) >= 5) {
if (substr(PHP_VERSION, 0, 1) >= 5) {
$r = eval('class StaticSetCaller{static function merge($a, $b){return Set::merge($a, $b);}} return StaticSetCaller::merge("foo", "bar");');
$this->assertIdentical($r, array('foo', 'bar'));
}

View file

@ -30,8 +30,8 @@
define('ST_FAILDETAIL_SEPARATOR', "->");
}
if (version_compare(phpversion(), '4.4.4', '<=') ||
php_sapi_name() == 'cgi') {
if (version_compare(PHP_VERSION, '4.4.4', '<=') ||
PHP_SAPI == 'cgi') {
define('STDOUT', fopen('php://stdout', 'w'));
define('STDERR', fopen('php://stderr', 'w'));
register_shutdown_function(create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));

View file

@ -79,7 +79,7 @@ class CodeCoverageManager {
*/
function &getInstance() {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
if (!$instance) {
$instance[0] =& new CodeCoverageManager();
}
return $instance[0];