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 * Patch for PHP < 5.0
*/ */
if (!function_exists('clone')) { if (!function_exists('clone')) {
if (version_compare(phpversion(), '5.0') < 0) { if (version_compare(PHP_VERSION, '5.0') < 0) {
eval (' eval ('
function clone($object) function clone($object)
{ {
@ -399,7 +399,7 @@ if (!function_exists('clone')) {
return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME')); return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
break; break;
case 'CGI_MODE': case 'CGI_MODE':
return (substr(php_sapi_name(), 0, 3) == 'cgi'); return (PHP_SAPI == 'cgi');
break; break;
case 'HTTP_BASE': case 'HTTP_BASE':
return preg_replace ('/^([^.])*/i', null, env('HTTP_HOST')); return preg_replace ('/^([^.])*/i', null, env('HTTP_HOST'));
@ -517,7 +517,7 @@ if (!function_exists('clone')) {
} }
} }
return true; return true;
} else { } else {
$cache = array( $cache = array(
CACHE . $type . DS . '*' . $params . $ext, CACHE . $type . DS . '*' . $params . $ext,
CACHE . $type . DS . '*' . $params . '_*' . $ext CACHE . $type . DS . '*' . $params . '_*' . $ext
@ -550,17 +550,18 @@ if (!function_exists('clone')) {
/** /**
* Recursively strips slashes from all values in an array * 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 * @return mixed What is returned from calling stripslashes
*/ */
function stripslashes_deep($value) { function stripslashes_deep($values) {
if (is_array($value)) { if (is_array($values)) {
$return = array_map('stripslashes_deep', $value); foreach ($values as $key => $value) {
return $return; $values[$key] = stripslashes_deep($value);
}
} else { } else {
$return = stripslashes($value); $values = stripslashes($values);
return $return ;
} }
return $values ;
} }
/** /**
* Returns a translated string if one is found, or the submitted message if not found. * 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 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if (!defined('PHP5')) { if (!defined('PHP5')) {
define ('PHP5', (phpversion() >= 5)); define ('PHP5', (PHP_VERSION >= 5));
} }
/** /**
* Configuration, directory layout and standard libraries * Configuration, directory layout and standard libraries

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -267,7 +267,7 @@ class SecurityComponent extends Object {
default: default:
$digest = null; $digest = null;
if (version_compare(phpversion(), '5.1') != -1) { if (version_compare(PHP_VERSION, '5.1') != -1) {
$digest = env('PHP_AUTH_DIGEST'); $digest = env('PHP_AUTH_DIGEST');
} elseif (function_exists('apache_request_headers')) { } elseif (function_exists('apache_request_headers')) {
$headers = apache_request_headers(); $headers = apache_request_headers();
@ -602,7 +602,7 @@ class SecurityComponent extends Object {
$values = array_values($value); $values = array_values($value);
$k = array_keys($value); $k = array_keys($value);
$count = count($k); $count = count($k);
if ($count > 0 && is_numeric($k[0])) { if ($count > 0 && is_numeric($k[0])) {
for ($i = 0; $count > $i; $i++) { for ($i = 0; $count > $i; $i++) {
foreach ($values[$i] as $key2 => $value1) { foreach ($values[$i] as $key2 => $value1) {

View file

@ -137,13 +137,13 @@ class Scaffold extends Object {
*/ */
function __construct(&$controller, $params) { function __construct(&$controller, $params) {
$this->controller =& $controller; $this->controller =& $controller;
$count = count($this->__passedVars); $count = count($this->__passedVars);
for ($j = 0; $j < $count; $j++) { for ($j = 0; $j < $count; $j++) {
$var = $this->__passedVars[$j]; $var = $this->__passedVars[$j];
$this->{$var} = $controller->{$var}; $this->{$var} = $controller->{$var};
} }
$this->redirect = array('action'=> 'index'); $this->redirect = array('action'=> 'index');
if (!in_array('Form', $this->controller->helpers)) { if (!in_array('Form', $this->controller->helpers)) {
@ -239,7 +239,7 @@ class Scaffold extends Object {
function __scaffoldIndex($params) { function __scaffoldIndex($params) {
if ($this->controller->_beforeScaffold('index')) { if ($this->controller->_beforeScaffold('index')) {
$this->ScaffoldModel->recursive = 0; $this->ScaffoldModel->recursive = 0;
$this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate()); $this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate());
$this->controller->render($this->action, $this->layout); $this->controller->render($this->action, $this->layout);
$this->_output(); $this->_output();
} elseif ($this->controller->_scaffoldError('index') === false) { } elseif ($this->controller->_scaffoldError('index') === false) {
@ -321,7 +321,7 @@ class Scaffold extends Object {
} }
foreach ($this->ScaffoldModel->belongsTo as $assocName => $assocData) { 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')); $this->controller->set($varName, $this->ScaffoldModel->{$assocName}->find('list'));
} }
foreach ($this->ScaffoldModel->hasAndBelongsToMany as $assocName => $assocData) { foreach ($this->ScaffoldModel->hasAndBelongsToMany as $assocName => $assocData) {
@ -503,7 +503,7 @@ class ScaffoldView extends ThemeView {
$names[] = $this->viewPath . DS . $subDir . $scaffoldAction; $names[] = $this->viewPath . DS . $subDir . $scaffoldAction;
$names[] = 'scaffolds' . DS . $subDir . $name; $names[] = 'scaffolds' . DS . $subDir . $name;
$admin = Configure::read('Routing.admin'); $admin = Configure::read('Routing.admin');
if (!empty($admin) && strpos($name, $admin.'_') !== false) { if (!empty($admin) && strpos($name, $admin.'_') !== false) {
$names[] = 'scaffolds' . DS . $subDir . substr($name, strlen($admin) +1); $names[] = 'scaffolds' . DS . $subDir . substr($name, strlen($admin) +1);

View file

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

View file

@ -211,7 +211,7 @@ class File extends Object {
*/ */
function prepare($data, $forceWindows = false) { function prepare($data, $forceWindows = false) {
$lineBreak = "\n"; $lineBreak = "\n";
if (substr(PHP_OS,0,3) == "WIN" || $forceWindows === true) { if (DIRECTORY_SEPARATOR == '\\' || $forceWindows === true) {
$lineBreak = "\r\n"; $lineBreak = "\r\n";
} }
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak)); return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
@ -341,7 +341,7 @@ class File extends Object {
if (!$ext) { if (!$ext) {
$ext = $this->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 * 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. * The returned array holds two arrays: one of dirs and one of files.
* *
* @param boolean $sort * @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 * @param boolean $fullpath true returns the full path
* @return mixed Contents of current directory as an array, false on failure * @return mixed Contents of current directory as an array, false on failure
* @access public * @access public
@ -420,7 +420,7 @@ class Folder extends Object {
while (count($this->__directories)) { while (count($this->__directories)) {
$dir = array_pop($this->__directories); $dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions); $this->__tree($dir, $exceptions);
array_push($directories, $dir); $directories[] = $dir;
} }
if ($type === null) { 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"])) { 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; $_this->__domains[$_this->category][$_this->__lang][$domain]["%plural-c"] = $switch;
unset($_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]); unset($_this->__domains[$_this->category][$_this->__lang][$domain]["%po-header"]);
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -43,7 +43,7 @@ class String extends Object {
function &getInstance() { function &getInstance() {
static $instance = array(); static $instance = array();
if (!isset($instance[0]) || !$instance[0]) { if (!$instance) {
$instance[0] =& new String(); $instance[0] =& new String();
} }
return $instance[0]; return $instance[0];
@ -156,10 +156,10 @@ class String extends Object {
} else { } else {
$buffer .= $data{$tmpOffset}; $buffer .= $data{$tmpOffset};
} }
if ($leftBound != $rightBound) { if ($leftBound != $rightBound) {
if ($data{$tmpOffset} == $leftBound) { if ($data{$tmpOffset} == $leftBound) {
$depth++; $depth++;
} }
if ($data{$tmpOffset} == $rightBound) { if ($data{$tmpOffset} == $rightBound) {
$depth--; $depth--;
} }
@ -240,14 +240,14 @@ class String extends Object {
} else { } else {
$hashKeys = array_map('md5', array_keys($data)); $hashKeys = array_map('md5', array_keys($data));
$tempData = array_combine(array_keys($data), array_values($hashKeys)); $tempData = array_combine(array_keys($data), array_values($hashKeys));
foreach ($tempData as $key => $hashVal) { foreach ($tempData as $key => $hashVal) {
$key = sprintf($format, preg_quote($key, '/')); $key = sprintf($format, preg_quote($key, '/'));
$str = preg_replace($key, $hashVal, $str); $str = preg_replace($key, $hashVal, $str);
} }
$dataReplacements = array_combine($hashKeys, array_values($data)); $dataReplacements = array_combine($hashKeys, array_values($data));
foreach ($dataReplacements as $tmpHash => $data) { foreach ($dataReplacements as $tmpHash => $data) {
$str = str_replace($tmpHash, $data, $str); $str = str_replace($tmpHash, $data, $str);
} }
} }
if (!isset($options['format']) && isset($options['before'])) { if (!isset($options['format']) && isset($options['before'])) {
@ -263,8 +263,8 @@ class String extends Object {
* text but html is also available. The goal of this function is to replace all whitespace and uneeded markup around placeholders * text but html is also available. The goal of this function is to replace all whitespace and uneeded markup around placeholders
* that did not get replaced by Set::insert. * that did not get replaced by Set::insert.
* *
* @param string $str * @param string $str
* @param string $options * @param string $options
* @return void * @return void
* @access public * @access public
*/ */

View file

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

View file

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

View file

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

View file

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

View file

@ -46,7 +46,7 @@ class CodeCoverageManagerTest extends CakeTestCase {
function startCase() { function startCase() {
$this->_get = $_GET; $this->_get = $_GET;
} }
/** /**
* End Case - restore GET vars. * End Case - restore GET vars.
* *
@ -70,7 +70,7 @@ class CodeCoverageManagerTest extends CakeTestCase {
* @return void * @return void
*/ */
function testNoTestCaseSupplied() { function testNoTestCaseSupplied() {
if (php_sapi_name() != 'cli') { if (PHP_SAPI != 'cli') {
unset($_GET['group']); unset($_GET['group']);
CodeCoverageManager::start(substr(md5(microtime()), 0, 5), new CakeHtmlReporter()); CodeCoverageManager::start(substr(md5(microtime()), 0, 5), new CakeHtmlReporter());
CodeCoverageManager::report(false); CodeCoverageManager::report(false);
@ -632,7 +632,7 @@ HTML;
} }
/** /**
* testCalculateCodeCoverage method * testCalculateCodeCoverage method
* *
* @access public * @access public
* @return void * @return void
*/ */

View file

@ -495,9 +495,9 @@ DIGEST;
} }
/** /**
* testValidatePostCheckbox method * testValidatePostCheckbox method
* *
* First block tests un-checked checkbox * First block tests un-checked checkbox
* Second block tests checked checkbox * Second block tests checked checkbox
* *
* @access public * @access public
* @return void * @return void
@ -528,8 +528,8 @@ DIGEST;
unset($data['_Model']); unset($data['_Model']);
$data['Model']['valid'] = '0'; $data['Model']['valid'] = '0';
$this->assertEqual($this->Controller->data, $data); $this->assertEqual($this->Controller->data, $data);
$this->Controller->data = array(); $this->Controller->data = array();
$this->Controller->Security->startup($this->Controller); $this->Controller->Security->startup($this->Controller);
$key = $this->Controller->params['_Token']['key']; $key = $this->Controller->params['_Token']['key'];
@ -721,7 +721,7 @@ DIGEST;
$this->assertTrue($this->Controller->data == $data); $this->assertTrue($this->Controller->data == $data);
} }
/** /**
* testValidateHasManyRecordsPass method * testValidateHasManyRecordsPass method
* *
@ -748,7 +748,7 @@ DIGEST;
'first_name' => 'Frodo', 'first_name' => 'Frodo',
'last_name' => 'Baggins', 'last_name' => 'Baggins',
'address' => '50 Bag end way', 'address' => '50 Bag end way',
'city' => 'the shire', 'city' => 'the shire',
'phone' => 'N/A', 'phone' => 'N/A',
'primary' => '1', 'primary' => '1',
), ),
@ -785,7 +785,7 @@ DIGEST;
$result = $this->Controller->Security->validatePost($this->Controller); $result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result); $this->assertTrue($result);
unset($data['_Address']); unset($data['_Address']);
$data['Address'][0]['id'] = '123'; $data['Address'][0]['id'] = '123';
$data['Address'][1]['id'] = '124'; $data['Address'][1]['id'] = '124';
@ -819,7 +819,7 @@ DIGEST;
'first_name' => 'Frodo', 'first_name' => 'Frodo',
'last_name' => 'Baggins', 'last_name' => 'Baggins',
'address' => '50 Bag end way', 'address' => '50 Bag end way',
'city' => 'the shire', 'city' => 'the shire',
'phone' => 'N/A', 'phone' => 'N/A',
'primary' => '1', 'primary' => '1',
), ),
@ -922,7 +922,7 @@ DIGEST;
$expected = array('username' => $user, 'password' => $pw); $expected = array('username' => $user, 'password' => $pw);
$this->assertIdentical($result, $expected); $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 $_SERVER['PHP_AUTH_DIGEST'] = $digest = <<<DIGEST
Digest username="Mufasa", Digest username="Mufasa",
realm="testrealm@host.com", realm="testrealm@host.com",

View file

@ -155,7 +155,7 @@ class TestErrorHandlerTest extends CakeTestCase {
* @return void * @return void
*/ */
function skip() { 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 * testError method

View file

@ -37,14 +37,14 @@ App::import('Core', 'File');
class FileTest extends CakeTestCase { class FileTest extends CakeTestCase {
/** /**
* File property * File property
* *
* @var mixed null * @var mixed null
* @access public * @access public
*/ */
var $File = null; var $File = null;
/** /**
* testBasic method * testBasic method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -102,7 +102,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testRead method * testRead method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -124,7 +124,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testOffset method * testOffset method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -156,7 +156,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testOpen method * testOpen method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -180,7 +180,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testClose method * testClose method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -197,7 +197,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testCreate method * testCreate method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -208,7 +208,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testOpeningNonExistantFileCreatesIt method * testOpeningNonExistantFileCreatesIt method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -221,7 +221,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testPrepare method * testPrepare method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -235,7 +235,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testReadable method * testReadable method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -248,7 +248,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testWritable method * testWritable method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -261,7 +261,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testExecutable method * testExecutable method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -274,7 +274,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testLastAccess method * testLastAccess method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -288,7 +288,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testLastChange method * testLastChange method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -304,7 +304,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testWrite method * testWrite method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -334,7 +334,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testAppend method * testAppend method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -362,7 +362,7 @@ class FileTest extends CakeTestCase {
} }
/** /**
* testDelete method * testDelete method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -386,8 +386,8 @@ class FileTest extends CakeTestCase {
} }
/** /**
* getTmpFile method * getTmpFile method
* *
* @param bool $paintSkip * @param bool $paintSkip
* @access protected * @access protected
* @return void * @return void
*/ */

View file

@ -172,7 +172,7 @@ class FolderTest extends CakeTestCase {
$filePath = $new . DS . 'test1.php'; $filePath = $new . DS . 'test1.php';
$File =& new File($filePath); $File =& new File($filePath);
$this->assertTrue($File->create()); $this->assertTrue($File->create());
$copy = TMP . 'test_folder_copy'; $copy = TMP . 'test_folder_copy';
$this->assertTrue($Folder->chmod($new, 0777, true)); $this->assertTrue($Folder->chmod($new, 0777, true));
$this->assertEqual($File->perms(), '0777'); $this->assertEqual($File->perms(), '0777');
@ -486,7 +486,7 @@ class FolderTest extends CakeTestCase {
$folder->cd(TMP); $folder->cd(TMP);
$folder->delete($folder->pwd().'config_non_existant'); $folder->delete($folder->pwd().'config_non_existant');
} }
/** /**
* testDelete method * testDelete method
* *
@ -498,22 +498,22 @@ class FolderTest extends CakeTestCase {
$Folder =& new Folder($path, true); $Folder =& new Folder($path, true);
touch(TMP.'folder_delete_test' . DS . 'file1'); touch(TMP.'folder_delete_test' . DS . 'file1');
touch(TMP.'folder_delete_test' . DS . 'file2'); touch(TMP.'folder_delete_test' . DS . 'file2');
$return = $Folder->delete(); $return = $Folder->delete();
$this->assertTrue($return); $this->assertTrue($return);
$messages = $Folder->messages(); $messages = $Folder->messages();
$errors = $Folder->errors(); $errors = $Folder->errors();
$this->assertEqual($errors, array()); $this->assertEqual($errors, array());
$expected = array( $expected = array(
$path . ' created', $path . ' created',
$path . DS . 'file1 removed', $path . DS . 'file1 removed',
$path . DS . 'file2 removed', $path . DS . 'file2 removed',
$path . ' removed' $path . ' removed'
); );
$this->assertEqual($expected, $messages); $this->assertEqual($expected, $messages);
} }
} }
?> ?>

View file

@ -775,12 +775,12 @@ class RouterTest extends CakeTestCase {
Router::connect('/', array('plugin' => 'pages', 'controller' => 'pages', 'action' => 'display')); Router::connect('/', array('plugin' => 'pages', 'controller' => 'pages', 'action' => 'display'));
$result = Router::parse('/'); $result = Router::parse('/');
$expected = array('pass' => array(), 'named' => array(), 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages'); $expected = array('pass' => array(), 'named' => array(), 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages');
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = Router::parse('/posts/edit/0'); $result = Router::parse('/posts/edit/0');
$expected = array('pass' => array(0), 'named' => array(), 'controller' => 'posts', 'action' => 'edit', 'plugin' => null); $expected = array('pass' => array(0), 'named' => array(), 'controller' => 'posts', 'action' => 'edit', 'plugin' => null);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
Router::reload(); Router::reload();
Router::connect('/posts/:id::url_title', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+')); Router::connect('/posts/:id::url_title', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+'));
$result = Router::parse('/posts/5:sample-post-title'); $result = Router::parse('/posts/5:sample-post-title');
@ -1529,5 +1529,4 @@ class RouterTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
} }
?> ?>

View file

@ -187,7 +187,7 @@ class SetTest extends CakeTestCase {
$r = Set::merge('foo', 'bar'); $r = Set::merge('foo', 'bar');
$this->assertIdentical($r, array('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");'); $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')); $this->assertIdentical($r, array('foo', 'bar'));
} }

View file

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

View file

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