Merge branch 'master' into 2.4

Conflicts:
	lib/Cake/Log/Engine/FileLog.php
	lib/Cake/Utility/Validation.php
	lib/Cake/View/Helper/HtmlHelper.php
This commit is contained in:
mark_story 2013-02-24 20:24:26 -05:00
commit d1c88ebf8a
110 changed files with 665 additions and 372 deletions

View file

@ -32,7 +32,7 @@ endif;
?> ?>
<p id="url-rewriting-warning" style="background-color:#e32; color:#fff;"> <p id="url-rewriting-warning" style="background-color:#e32; color:#fff;">
<?php echo __d('cake_dev', 'URL rewriting is not properly configured on your server.'); ?> <?php echo __d('cake_dev', 'URL rewriting is not properly configured on your server.'); ?>
1) <a target="_blank" href="http://book.cakephp.org/2.0/en/installation/advanced-installation.html#apache-and-mod-rewrite-and-htaccess" style="color:#fff;">Help me configure it</a> 1) <a target="_blank" href="http://book.cakephp.org/2.0/en/installation/url-rewriting.html" style="color:#fff;">Help me configure it</a>
2) <a target="_blank" href="http://book.cakephp.org/2.0/en/development/configuration.html#cakephp-core-configuration" style="color:#fff;">I don't / can't use URL rewriting</a> 2) <a target="_blank" href="http://book.cakephp.org/2.0/en/development/configuration.html#cakephp-core-configuration" style="color:#fff;">I don't / can't use URL rewriting</a>
</p> </p>
<p> <p>

View file

@ -88,11 +88,11 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path')); ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
} }
if (!include('Cake' . DS . 'bootstrap.php')) { if (!include ('Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} else { } else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) { if (!include (CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} }

View file

@ -77,11 +77,11 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path')); ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
} }
if (!include('Cake' . DS . 'bootstrap.php')) { if (!include ('Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} else { } else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) { if (!include (CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} }

View file

@ -106,10 +106,10 @@ class MemcacheEngine extends CacheEngine {
* @return array Array containing host, port * @return array Array containing host, port
*/ */
protected function _parseServerString($server) { protected function _parseServerString($server) {
if ($server[0] == 'u') { if ($server[0] === 'u') {
return array($server, 0); return array($server, 0);
} }
if (substr($server, 0, 1) == '[') { if (substr($server, 0, 1) === '[') {
$position = strpos($server, ']:'); $position = strpos($server, ']:');
if ($position !== false) { if ($position !== false) {
$position++; $position++;

View file

@ -160,7 +160,7 @@ class IniReader implements ConfigReaderInterface {
$result = array(); $result = array();
foreach ($data as $k => $value) { foreach ($data as $k => $value) {
$isSection = false; $isSection = false;
if ($k[0] != '[') { if ($k[0] !== '[') {
$result[] = "[$k]"; $result[] = "[$k]";
$isSection = true; $isSection = true;
} }

View file

@ -122,14 +122,14 @@ class AclShell extends AppShell {
$class = ucfirst($this->args[0]); $class = ucfirst($this->args[0]);
$parent = $this->parseIdentifier($this->args[1]); $parent = $this->parseIdentifier($this->args[1]);
if (!empty($parent) && $parent != '/' && $parent != 'root') { if (!empty($parent) && $parent !== '/' && $parent !== 'root') {
$parent = $this->_getNodeId($class, $parent); $parent = $this->_getNodeId($class, $parent);
} else { } else {
$parent = null; $parent = null;
} }
$data = $this->parseIdentifier($this->args[2]); $data = $this->parseIdentifier($this->args[2]);
if (is_string($data) && $data != '/') { if (is_string($data) && $data !== '/') {
$data = array('alias' => $data); $data = array('alias' => $data);
} elseif (is_string($data)) { } elseif (is_string($data)) {
$this->error(__d('cake_console', '/ can not be used as an alias!') . __d('cake_console', " / is the root, please supply a sub alias")); $this->error(__d('cake_console', '/ can not be used as an alias!') . __d('cake_console', " / is the root, please supply a sub alias"));
@ -604,7 +604,7 @@ class AclShell extends AppShell {
} }
$vars = array(); $vars = array();
$class = ucwords($type); $class = ucwords($type);
$vars['secondary_id'] = (strtolower($class) == 'aro') ? 'foreign_key' : 'object_id'; $vars['secondary_id'] = (strtolower($class) === 'aro') ? 'foreign_key' : 'object_id';
$vars['data_name'] = $type; $vars['data_name'] = $type;
$vars['table_name'] = $type . 's'; $vars['table_name'] = $type . 's';
$vars['class'] = $class; $vars['class'] = $class;

View file

@ -66,7 +66,7 @@ class ControllerTask extends BakeTask {
if (!isset($this->connection)) { if (!isset($this->connection)) {
$this->connection = 'default'; $this->connection = 'default';
} }
if (strtolower($this->args[0]) == 'all') { if (strtolower($this->args[0]) === 'all') {
return $this->all(); return $this->all();
} }
@ -162,13 +162,13 @@ class ControllerTask extends BakeTask {
} }
$doItInteractive = $this->in(implode("\n", $question), array('y', 'n'), 'y'); $doItInteractive = $this->in(implode("\n", $question), array('y', 'n'), 'y');
if (strtolower($doItInteractive) == 'y') { if (strtolower($doItInteractive) === 'y') {
$this->interactive = true; $this->interactive = true;
$useDynamicScaffold = $this->in( $useDynamicScaffold = $this->in(
__d('cake_console', "Would you like to use dynamic scaffolding?"), array('y', 'n'), 'n' __d('cake_console', "Would you like to use dynamic scaffolding?"), array('y', 'n'), 'n'
); );
if (strtolower($useDynamicScaffold) == 'y') { if (strtolower($useDynamicScaffold) === 'y') {
$wannaBakeCrud = 'n'; $wannaBakeCrud = 'n';
$actions = 'scaffold'; $actions = 'scaffold';
} else { } else {
@ -185,12 +185,12 @@ class ControllerTask extends BakeTask {
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods(); list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
} }
if (strtolower($wannaBakeCrud) == 'y') { if (strtolower($wannaBakeCrud) === 'y') {
$actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y'); $actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) === 'y');
} }
if (strtolower($wannaBakeAdminCrud) == 'y') { if (strtolower($wannaBakeAdminCrud) === 'y') {
$admin = $this->Project->getPrefix(); $admin = $this->Project->getPrefix();
$actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y'); $actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) === 'y');
} }
$baked = false; $baked = false;
@ -198,7 +198,7 @@ class ControllerTask extends BakeTask {
$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components); $this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y'); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) === 'y') {
$baked = $this->bake($controllerName, $actions, $helpers, $components); $baked = $this->bake($controllerName, $actions, $helpers, $components);
if ($baked && $this->_checkUnitTest()) { if ($baked && $this->_checkUnitTest()) {
$this->bakeTest($controllerName); $this->bakeTest($controllerName);
@ -229,7 +229,7 @@ class ControllerTask extends BakeTask {
$this->hr(); $this->hr();
$this->out(__d('cake_console', "Controller Name:\n\t%s", $controllerName)); $this->out(__d('cake_console', "Controller Name:\n\t%s", $controllerName));
if (strtolower($useDynamicScaffold) == 'y') { if (strtolower($useDynamicScaffold) === 'y') {
$this->out("public \$scaffold;"); $this->out("public \$scaffold;");
} }
@ -386,7 +386,7 @@ class ControllerTask extends BakeTask {
protected function _doPropertyChoices($prompt, $example) { protected function _doPropertyChoices($prompt, $example) {
$proceed = $this->in($prompt, array('y','n'), 'n'); $proceed = $this->in($prompt, array('y','n'), 'n');
$property = array(); $property = array();
if (strtolower($proceed) == 'y') { if (strtolower($proceed) === 'y') {
$propertyList = $this->in($example); $propertyList = $this->in($example);
$propertyListTrimmed = str_replace(' ', '', $propertyList); $propertyListTrimmed = str_replace(' ', '', $propertyList);
$property = explode(',', $propertyListTrimmed); $property = explode(',', $propertyListTrimmed);

View file

@ -110,7 +110,7 @@ class DbConfigTask extends AppShell {
$datasource = $this->in(__d('cake_console', 'Datasource:'), array('Mysql', 'Postgres', 'Sqlite', 'Sqlserver'), 'Mysql'); $datasource = $this->in(__d('cake_console', 'Datasource:'), array('Mysql', 'Postgres', 'Sqlite', 'Sqlserver'), 'Mysql');
$persistent = $this->in(__d('cake_console', 'Persistent Connection?'), array('y', 'n'), 'n'); $persistent = $this->in(__d('cake_console', 'Persistent Connection?'), array('y', 'n'), 'n');
if (strtolower($persistent) == 'n') { if (strtolower($persistent) === 'n') {
$persistent = 'false'; $persistent = 'false';
} else { } else {
$persistent = 'true'; $persistent = 'true';
@ -126,7 +126,7 @@ class DbConfigTask extends AppShell {
$port = $this->in(__d('cake_console', 'Port?'), null, 'n'); $port = $this->in(__d('cake_console', 'Port?'), null, 'n');
} }
if (strtolower($port) == 'n') { if (strtolower($port) === 'n') {
$port = null; $port = null;
} }
@ -142,7 +142,7 @@ class DbConfigTask extends AppShell {
if (!$password) { if (!$password) {
$blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n'); $blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n');
if ($blank == 'y') { if ($blank === 'y') {
$blankPassword = true; $blankPassword = true;
} }
} }
@ -157,7 +157,7 @@ class DbConfigTask extends AppShell {
while (!$prefix) { while (!$prefix) {
$prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n'); $prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n');
} }
if (strtolower($prefix) == 'n') { if (strtolower($prefix) === 'n') {
$prefix = null; $prefix = null;
} }
@ -165,17 +165,17 @@ class DbConfigTask extends AppShell {
while (!$encoding) { while (!$encoding) {
$encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n'); $encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n');
} }
if (strtolower($encoding) == 'n') { if (strtolower($encoding) === 'n') {
$encoding = null; $encoding = null;
} }
$schema = ''; $schema = '';
if ($datasource == 'postgres') { if ($datasource === 'postgres') {
while (!$schema) { while (!$schema) {
$schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n'); $schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n');
} }
} }
if (strtolower($schema) == 'n') { if (strtolower($schema) === 'n') {
$schema = null; $schema = null;
} }
@ -188,7 +188,7 @@ class DbConfigTask extends AppShell {
$dbConfigs[] = $config; $dbConfigs[] = $config;
$doneYet = $this->in(__d('cake_console', 'Do you wish to add another database configuration?'), null, 'n'); $doneYet = $this->in(__d('cake_console', 'Do you wish to add another database configuration?'), null, 'n');
if (strtolower($doneYet == 'n')) { if (strtolower($doneYet === 'n')) {
$done = true; $done = true;
} }
} }
@ -239,7 +239,7 @@ class DbConfigTask extends AppShell {
$this->hr(); $this->hr();
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y'); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) === 'y') {
return $config; return $config;
} }
return false; return false;

View file

@ -388,14 +388,14 @@ class ExtractTask extends AppShell {
} }
list($type, $string, $line) = $countToken; list($type, $string, $line) = $countToken;
if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis == '(')) { if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis === '(')) {
$position = $count; $position = $count;
$depth = 0; $depth = 0;
while (!$depth) { while (!$depth) {
if ($this->_tokens[$position] == '(') { if ($this->_tokens[$position] === '(') {
$depth++; $depth++;
} elseif ($this->_tokens[$position] == ')') { } elseif ($this->_tokens[$position] === ')') {
$depth--; $depth--;
} }
$position++; $position++;
@ -537,7 +537,7 @@ class ExtractTask extends AppShell {
} }
$this->_store($domain, $header, $sentence); $this->_store($domain, $header, $sentence);
if ($domain != 'default' && $this->_merge) { if ($domain !== 'default' && $this->_merge) {
$this->_store('default', $header, $sentence); $this->_store('default', $header, $sentence);
} }
} }
@ -640,11 +640,11 @@ class ExtractTask extends AppShell {
protected function _getStrings(&$position, $target) { protected function _getStrings(&$position, $target) {
$strings = array(); $strings = array();
$count = count($strings); $count = count($strings);
while ($count < $target && ($this->_tokens[$position] == ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { while ($count < $target && ($this->_tokens[$position] === ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
$count = count($strings); $count = count($strings);
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] == '.') { if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] === '.') {
$string = ''; $string = '';
while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] == '.') { while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] === '.') {
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$string .= $this->_formatString($this->_tokens[$position][1]); $string .= $this->_formatString($this->_tokens[$position][1]);
} }
@ -668,7 +668,7 @@ class ExtractTask extends AppShell {
protected function _formatString($string) { protected function _formatString($string) {
$quote = substr($string, 0, 1); $quote = substr($string, 0, 1);
$string = substr($string, 1, -1); $string = substr($string, 1, -1);
if ($quote == '"') { if ($quote === '"') {
$string = stripcslashes($string); $string = stripcslashes($string);
} else { } else {
$string = strtr($string, array("\\'" => "'", "\\\\" => "\\")); $string = strtr($string, array("\\'" => "'", "\\\\" => "\\"));
@ -697,11 +697,11 @@ class ExtractTask extends AppShell {
$this->out($this->_tokens[$count][1], false); $this->out($this->_tokens[$count][1], false);
} else { } else {
$this->out($this->_tokens[$count], false); $this->out($this->_tokens[$count], false);
if ($this->_tokens[$count] == '(') { if ($this->_tokens[$count] === '(') {
$parenthesis++; $parenthesis++;
} }
if ($this->_tokens[$count] == ')') { if ($this->_tokens[$count] === ')') {
$parenthesis--; $parenthesis--;
} }
} }

View file

@ -107,7 +107,7 @@ class FixtureTask extends BakeTask {
if (!isset($this->connection)) { if (!isset($this->connection)) {
$this->connection = 'default'; $this->connection = 'default';
} }
if (strtolower($this->args[0]) == 'all') { if (strtolower($this->args[0]) === 'all') {
return $this->all(); return $this->all();
} }
$model = $this->_modelName($this->args[0]); $model = $this->_modelName($this->args[0]);
@ -159,17 +159,17 @@ class FixtureTask extends BakeTask {
public function importOptions($modelName) { public function importOptions($modelName) {
$options = array(); $options = array();
$doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n'); $doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
if ($doSchema == 'y') { if ($doSchema === 'y') {
$options['schema'] = $modelName; $options['schema'] = $modelName;
} }
$doRecords = $this->in(__d('cake_console', 'Would you like to use record importing for this fixture?'), array('y', 'n'), 'n'); $doRecords = $this->in(__d('cake_console', 'Would you like to use record importing for this fixture?'), array('y', 'n'), 'n');
if ($doRecords == 'y') { if ($doRecords === 'y') {
$options['records'] = true; $options['records'] = true;
} }
if ($doRecords == 'n') { if ($doRecords === 'n') {
$prompt = __d('cake_console', "Would you like to build this fixture with data from %s's table?", $modelName); $prompt = __d('cake_console', "Would you like to build this fixture with data from %s's table?", $modelName);
$fromTable = $this->in($prompt, array('y', 'n'), 'n'); $fromTable = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($fromTable) == 'y') { if (strtolower($fromTable) === 'y') {
$options['fromTable'] = true; $options['fromTable'] = true;
} }
} }
@ -203,7 +203,7 @@ class FixtureTask extends BakeTask {
if (isset($importOptions['records'])) { if (isset($importOptions['records'])) {
$importBits[] = "'records' => true"; $importBits[] = "'records' => true";
} }
if ($this->connection != 'default') { if ($this->connection !== 'default') {
$importBits[] .= "'connection' => '{$this->connection}'"; $importBits[] .= "'connection' => '{$this->connection}'";
} }
if (!empty($importBits)) { if (!empty($importBits)) {
@ -307,7 +307,7 @@ class FixtureTask extends BakeTask {
case 'string': case 'string':
case 'binary': case 'binary':
$isPrimaryUuid = ( $isPrimaryUuid = (
isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' && isset($fieldInfo['key']) && strtolower($fieldInfo['key']) === 'primary' &&
isset($fieldInfo['length']) && $fieldInfo['length'] == 36 isset($fieldInfo['length']) && $fieldInfo['length'] == 36
); );
if ($isPrimaryUuid) { if ($isPrimaryUuid) {

View file

@ -98,7 +98,7 @@ class ModelTask extends BakeTask {
if (!isset($this->connection)) { if (!isset($this->connection)) {
$this->connection = 'default'; $this->connection = 'default';
} }
if (strtolower($this->args[0]) == 'all') { if (strtolower($this->args[0]) === 'all') {
return $this->all(); return $this->all();
} }
$model = $this->_modelName($this->args[0]); $model = $this->_modelName($this->args[0]);
@ -150,7 +150,7 @@ class ModelTask extends BakeTask {
$object = new Model(array('name' => $className, 'table' => $table, 'ds' => $this->connection)); $object = new Model(array('name' => $className, 'table' => $table, 'ds' => $this->connection));
$fields = $object->schema(true); $fields = $object->schema(true);
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
if (isset($field['key']) && $field['key'] == 'primary') { if (isset($field['key']) && $field['key'] === 'primary') {
$object->primaryKey = $name; $object->primaryKey = $name;
break; break;
} }
@ -209,7 +209,7 @@ class ModelTask extends BakeTask {
if (!in_array($useTable, $this->_tables)) { if (!in_array($useTable, $this->_tables)) {
$prompt = __d('cake_console', "The table %s doesn't exist or could not be automatically detected\ncontinue anyway?", $useTable); $prompt = __d('cake_console', "The table %s doesn't exist or could not be automatically detected\ncontinue anyway?", $useTable);
$continue = $this->in($prompt, array('y', 'n')); $continue = $this->in($prompt, array('y', 'n'));
if (strtolower($continue) == 'n') { if (strtolower($continue) === 'n') {
return false; return false;
} }
} }
@ -235,13 +235,13 @@ class ModelTask extends BakeTask {
$prompt = __d('cake_console', "Would you like to supply validation criteria \nfor the fields in your model?"); $prompt = __d('cake_console', "Would you like to supply validation criteria \nfor the fields in your model?");
$wannaDoValidation = $this->in($prompt, array('y','n'), 'y'); $wannaDoValidation = $this->in($prompt, array('y','n'), 'y');
if (array_search($useTable, $this->_tables) !== false && strtolower($wannaDoValidation) == 'y') { if (array_search($useTable, $this->_tables) !== false && strtolower($wannaDoValidation) === 'y') {
$validate = $this->doValidation($tempModel); $validate = $this->doValidation($tempModel);
} }
$prompt = __d('cake_console', "Would you like to define model associations\n(hasMany, hasOne, belongsTo, etc.)?"); $prompt = __d('cake_console', "Would you like to define model associations\n(hasMany, hasOne, belongsTo, etc.)?");
$wannaDoAssoc = $this->in($prompt, array('y','n'), 'y'); $wannaDoAssoc = $this->in($prompt, array('y','n'), 'y');
if (strtolower($wannaDoAssoc) == 'y') { if (strtolower($wannaDoAssoc) === 'y') {
$associations = $this->doAssociations($tempModel); $associations = $this->doAssociations($tempModel);
} }
} }
@ -258,7 +258,7 @@ class ModelTask extends BakeTask {
if ($fullTableName !== Inflector::tableize($currentModelName)) { if ($fullTableName !== Inflector::tableize($currentModelName)) {
$this->out(__d('cake_console', 'DB Table: %s', $fullTableName)); $this->out(__d('cake_console', 'DB Table: %s', $fullTableName));
} }
if ($primaryKey != 'id') { if ($primaryKey !== 'id') {
$this->out(__d('cake_console', 'Primary Key: %s', $primaryKey)); $this->out(__d('cake_console', 'Primary Key: %s', $primaryKey));
} }
if (!empty($validate)) { if (!empty($validate)) {
@ -275,7 +275,7 @@ class ModelTask extends BakeTask {
$this->hr(); $this->hr();
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y'); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) === 'y') {
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField'); $vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
$vars['useDbConfig'] = $this->connection; $vars['useDbConfig'] = $this->connection;
if ($this->bake($currentModelName, $vars)) { if ($this->bake($currentModelName, $vars)) {
@ -315,7 +315,7 @@ class ModelTask extends BakeTask {
public function findPrimaryKey($fields) { public function findPrimaryKey($fields) {
$name = 'id'; $name = 'id';
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
if (isset($field['key']) && $field['key'] == 'primary') { if (isset($field['key']) && $field['key'] === 'primary') {
break; break;
} }
} }
@ -332,7 +332,7 @@ class ModelTask extends BakeTask {
$fieldNames = array_keys($fields); $fieldNames = array_keys($fields);
$prompt = __d('cake_console', "A displayField could not be automatically detected\nwould you like to choose one?"); $prompt = __d('cake_console', "A displayField could not be automatically detected\nwould you like to choose one?");
$continue = $this->in($prompt, array('y', 'n')); $continue = $this->in($prompt, array('y', 'n'));
if (strtolower($continue) == 'n') { if (strtolower($continue) === 'n') {
return false; return false;
} }
$prompt = __d('cake_console', 'Choose a field from the options above:'); $prompt = __d('cake_console', 'Choose a field from the options above:');
@ -379,7 +379,7 @@ class ModelTask extends BakeTask {
sort($options); sort($options);
$default = 1; $default = 1;
foreach ($options as $option) { foreach ($options as $option) {
if ($option{0} != '_') { if ($option{0} !== '_') {
$choices[$default] = strtolower($option); $choices[$default] = strtolower($option);
$default++; $default++;
} }
@ -402,7 +402,7 @@ class ModelTask extends BakeTask {
$validate = $alreadyChosen = array(); $validate = $alreadyChosen = array();
$anotherValidator = 'y'; $anotherValidator = 'y';
while ($anotherValidator == 'y') { while ($anotherValidator === 'y') {
if ($this->interactive) { if ($this->interactive) {
$this->out(); $this->out();
$this->out(__d('cake_console', 'Field: <info>%s</info>', $fieldName)); $this->out(__d('cake_console', 'Field: <info>%s</info>', $fieldName));
@ -428,25 +428,25 @@ class ModelTask extends BakeTask {
$methods = array_flip($this->_validations); $methods = array_flip($this->_validations);
$guess = $defaultChoice; $guess = $defaultChoice;
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) { if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
if ($fieldName == 'email') { if ($fieldName === 'email') {
$guess = $methods['email']; $guess = $methods['email'];
} elseif ($metaData['type'] == 'string' && $metaData['length'] == 36) { } elseif ($metaData['type'] === 'string' && $metaData['length'] == 36) {
$guess = $methods['uuid']; $guess = $methods['uuid'];
} elseif ($metaData['type'] == 'string') { } elseif ($metaData['type'] === 'string') {
$guess = $methods['notempty']; $guess = $methods['notempty'];
} elseif ($metaData['type'] == 'text') { } elseif ($metaData['type'] === 'text') {
$guess = $methods['notempty']; $guess = $methods['notempty'];
} elseif ($metaData['type'] == 'integer') { } elseif ($metaData['type'] === 'integer') {
$guess = $methods['numeric']; $guess = $methods['numeric'];
} elseif ($metaData['type'] == 'boolean') { } elseif ($metaData['type'] === 'boolean') {
$guess = $methods['boolean']; $guess = $methods['boolean'];
} elseif ($metaData['type'] == 'date') { } elseif ($metaData['type'] === 'date') {
$guess = $methods['date']; $guess = $methods['date'];
} elseif ($metaData['type'] == 'time') { } elseif ($metaData['type'] === 'time') {
$guess = $methods['time']; $guess = $methods['time'];
} elseif ($metaData['type'] == 'datetime') { } elseif ($metaData['type'] === 'datetime') {
$guess = $methods['datetime']; $guess = $methods['datetime'];
} elseif ($metaData['type'] == 'inet') { } elseif ($metaData['type'] === 'inet') {
$guess = $methods['ip']; $guess = $methods['ip'];
} }
} }
@ -549,14 +549,14 @@ class ModelTask extends BakeTask {
$fieldNames = array_keys($model->schema(true)); $fieldNames = array_keys($model->schema(true));
foreach ($fieldNames as $fieldName) { foreach ($fieldNames as $fieldName) {
$offset = strpos($fieldName, '_id'); $offset = strpos($fieldName, '_id');
if ($fieldName != $model->primaryKey && $fieldName != 'parent_id' && $offset !== false) { if ($fieldName != $model->primaryKey && $fieldName !== 'parent_id' && $offset !== false) {
$tmpModelName = $this->_modelNameFromKey($fieldName); $tmpModelName = $this->_modelNameFromKey($fieldName);
$associations['belongsTo'][] = array( $associations['belongsTo'][] = array(
'alias' => $tmpModelName, 'alias' => $tmpModelName,
'className' => $tmpModelName, 'className' => $tmpModelName,
'foreignKey' => $fieldName, 'foreignKey' => $fieldName,
); );
} elseif ($fieldName == 'parent_id') { } elseif ($fieldName === 'parent_id') {
$associations['belongsTo'][] = array( $associations['belongsTo'][] = array(
'alias' => 'Parent' . $model->name, 'alias' => 'Parent' . $model->name,
'className' => $model->name, 'className' => $model->name,
@ -593,7 +593,7 @@ class ModelTask extends BakeTask {
'className' => $tempOtherModel->name, 'className' => $tempOtherModel->name,
'foreignKey' => $fieldName 'foreignKey' => $fieldName
); );
} elseif ($otherTable == $model->table && $fieldName == 'parent_id') { } elseif ($otherTable == $model->table && $fieldName === 'parent_id') {
$assoc = array( $assoc = array(
'alias' => 'Child' . $model->name, 'alias' => 'Child' . $model->name,
'className' => $model->name, 'className' => $model->name,
@ -659,7 +659,7 @@ class ModelTask extends BakeTask {
if ('n' == strtolower($response)) { if ('n' == strtolower($response)) {
unset($associations[$type][$i]); unset($associations[$type][$i]);
} elseif ($type == 'hasMany') { } elseif ($type === 'hasMany') {
unset($associations['hasOne'][$i]); unset($associations['hasOne'][$i]);
} }
} }
@ -755,7 +755,7 @@ class ModelTask extends BakeTask {
$tempOtherModel = new Model(array('table' => $otherTable, 'ds' => $this->connection)); $tempOtherModel = new Model(array('table' => $otherTable, 'ds' => $this->connection));
$modelFieldsTemp = $tempOtherModel->schema(true); $modelFieldsTemp = $tempOtherModel->schema(true);
foreach ($modelFieldsTemp as $fieldName => $field) { foreach ($modelFieldsTemp as $fieldName => $field) {
if ($field['type'] == 'integer' || $field['type'] == 'string') { if ($field['type'] === 'integer' || $field['type'] === 'string') {
$possible[$otherTable][] = $fieldName; $possible[$otherTable][] = $fieldName;
} }
} }
@ -877,7 +877,7 @@ class ModelTask extends BakeTask {
$this->out(__d('cake_console', "Given your model named '%s',\nCake would expect a database table named '%s'", $modelName, $fullTableName)); $this->out(__d('cake_console', "Given your model named '%s',\nCake would expect a database table named '%s'", $modelName, $fullTableName));
$tableIsGood = $this->in(__d('cake_console', 'Do you want to use this table?'), array('y', 'n'), 'y'); $tableIsGood = $this->in(__d('cake_console', 'Do you want to use this table?'), array('y', 'n'), 'y');
} }
if (strtolower($tableIsGood) == 'n') { if (strtolower($tableIsGood) === 'n') {
$useTable = $this->in(__d('cake_console', 'What is the name of the table?')); $useTable = $this->in(__d('cake_console', 'What is the name of the table?'));
} }
} }

View file

@ -107,7 +107,7 @@ class PluginTask extends AppShell {
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y'); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) === 'y') {
$Folder = new Folder($this->path . $plugin); $Folder = new Folder($this->path . $plugin);
$directories = array( $directories = array(
'Config' . DS . 'Schema', 'Config' . DS . 'Schema',

View file

@ -198,7 +198,7 @@ class TestTask extends BakeTask {
} }
$keys[] = 'q'; $keys[] = 'q';
$selection = $this->in(__d('cake_console', 'Enter the type of object to bake a test for or (q)uit'), $keys, 'q'); $selection = $this->in(__d('cake_console', 'Enter the type of object to bake a test for or (q)uit'), $keys, 'q');
if ($selection == 'q') { if ($selection === 'q') {
return $this->_stop(); return $this->_stop();
} }
$types = array_keys($this->classTypes); $types = array_keys($this->classTypes);
@ -281,7 +281,7 @@ class TestTask extends BakeTask {
ClassRegistry::flush(); ClassRegistry::flush();
App::import($type, $class); App::import($type, $class);
$class = $this->getRealClassName($type, $class); $class = $this->getRealClassName($type, $class);
if (strtolower($type) == 'model') { if (strtolower($type) === 'model') {
$instance = ClassRegistry::init($class); $instance = ClassRegistry::init($class);
} else { } else {
$instance = new $class(); $instance = new $class();
@ -298,7 +298,7 @@ class TestTask extends BakeTask {
* @return string Real classname * @return string Real classname
*/ */
public function getRealClassName($type, $class) { public function getRealClassName($type, $class) {
if (strtolower($type) == 'model' || empty($this->classTypes[$type])) { if (strtolower($type) === 'model' || empty($this->classTypes[$type])) {
return $class; return $class;
} }
@ -358,7 +358,7 @@ class TestTask extends BakeTask {
$thisMethods = array_diff($classMethods, $parentMethods); $thisMethods = array_diff($classMethods, $parentMethods);
$out = array(); $out = array();
foreach ($thisMethods as $method) { foreach ($thisMethods as $method) {
if (substr($method, 0, 1) != '_' && $method != strtolower($className)) { if (substr($method, 0, 1) !== '_' && $method != strtolower($className)) {
$out[] = $method; $out[] = $method;
} }
} }
@ -397,7 +397,7 @@ class TestTask extends BakeTask {
if (!isset($this->_fixtures[$className])) { if (!isset($this->_fixtures[$className])) {
$this->_processModel($subject->{$alias}); $this->_processModel($subject->{$alias});
} }
if ($type == 'hasAndBelongsToMany') { if ($type === 'hasAndBelongsToMany') {
if (!empty($subject->hasAndBelongsToMany[$alias]['with'])) { if (!empty($subject->hasAndBelongsToMany[$alias]['with'])) {
list(, $joinModel) = pluginSplit($subject->hasAndBelongsToMany[$alias]['with']); list(, $joinModel) = pluginSplit($subject->hasAndBelongsToMany[$alias]['with']);
} else { } else {
@ -454,7 +454,7 @@ class TestTask extends BakeTask {
public function getUserFixtures() { public function getUserFixtures() {
$proceed = $this->in(__d('cake_console', 'Bake could not detect fixtures, would you like to add some?'), array('y', 'n'), 'n'); $proceed = $this->in(__d('cake_console', 'Bake could not detect fixtures, would you like to add some?'), array('y', 'n'), 'n');
$fixtures = array(); $fixtures = array();
if (strtolower($proceed) == 'y') { if (strtolower($proceed) === 'y') {
$fixtureList = $this->in(__d('cake_console', "Please provide a comma separated list of the fixtures names you'd like to use.\nExample: 'app.comment, app.post, plugin.forums.post'")); $fixtureList = $this->in(__d('cake_console', "Please provide a comma separated list of the fixtures names you'd like to use.\nExample: 'app.comment, app.post, plugin.forums.post'"));
$fixtureListTrimmed = str_replace(' ', '', $fixtureList); $fixtureListTrimmed = str_replace(' ', '', $fixtureList);
$fixtures = explode(',', $fixtureListTrimmed); $fixtures = explode(',', $fixtureListTrimmed);
@ -472,7 +472,7 @@ class TestTask extends BakeTask {
*/ */
public function hasMockClass($type) { public function hasMockClass($type) {
$type = strtolower($type); $type = strtolower($type);
return $type == 'controller'; return $type === 'controller';
} }
/** /**
@ -486,17 +486,17 @@ class TestTask extends BakeTask {
public function generateConstructor($type, $fullClassName, $plugin) { public function generateConstructor($type, $fullClassName, $plugin) {
$type = strtolower($type); $type = strtolower($type);
$pre = $construct = $post = ''; $pre = $construct = $post = '';
if ($type == 'model') { if ($type === 'model') {
$construct = "ClassRegistry::init('{$plugin}$fullClassName');\n"; $construct = "ClassRegistry::init('{$plugin}$fullClassName');\n";
} }
if ($type == 'behavior') { if ($type === 'behavior') {
$construct = "new $fullClassName();\n"; $construct = "new $fullClassName();\n";
} }
if ($type == 'helper') { if ($type === 'helper') {
$pre = "\$View = new View();\n"; $pre = "\$View = new View();\n";
$construct = "new {$fullClassName}(\$View);\n"; $construct = "new {$fullClassName}(\$View);\n";
} }
if ($type == 'component') { if ($type === 'component') {
$pre = "\$Collection = new ComponentCollection();\n"; $pre = "\$Collection = new ComponentCollection();\n";
$construct = "new {$fullClassName}(\$Collection);\n"; $construct = "new {$fullClassName}(\$Collection);\n";
} }
@ -514,11 +514,11 @@ class TestTask extends BakeTask {
public function generateUses($type, $realType, $className) { public function generateUses($type, $realType, $className) {
$uses = array(); $uses = array();
$type = strtolower($type); $type = strtolower($type);
if ($type == 'component') { if ($type === 'component') {
$uses[] = array('ComponentCollection', 'Controller'); $uses[] = array('ComponentCollection', 'Controller');
$uses[] = array('Component', 'Controller'); $uses[] = array('Component', 'Controller');
} }
if ($type == 'helper') { if ($type === 'helper') {
$uses[] = array('View', 'View'); $uses[] = array('View', 'View');
$uses[] = array('Helper', 'View'); $uses[] = array('Helper', 'View');
} }

View file

@ -100,7 +100,7 @@ class ViewTask extends BakeTask {
$this->controllerName = $this->_controllerName($this->args[0]); $this->controllerName = $this->_controllerName($this->args[0]);
$this->Project->interactive = false; $this->Project->interactive = false;
if (strtolower($this->args[0]) == 'all') { if (strtolower($this->args[0]) === 'all') {
return $this->all(); return $this->all();
} }
@ -211,7 +211,7 @@ class ViewTask extends BakeTask {
$prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName); $prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName);
$interactive = $this->in($prompt, array('y', 'n'), 'n'); $interactive = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($interactive) == 'n') { if (strtolower($interactive) === 'n') {
$this->interactive = false; $this->interactive = false;
} }
@ -220,13 +220,13 @@ class ViewTask extends BakeTask {
$wannaDoAdmin = $this->in(__d('cake_console', "Would you like to create the views for admin routing?"), array('y', 'n'), 'n'); $wannaDoAdmin = $this->in(__d('cake_console', "Would you like to create the views for admin routing?"), array('y', 'n'), 'n');
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') { if (strtolower($wannaDoScaffold) === 'y' || strtolower($wannaDoAdmin) === 'y') {
$vars = $this->_loadController(); $vars = $this->_loadController();
if (strtolower($wannaDoScaffold) == 'y') { if (strtolower($wannaDoScaffold) === 'y') {
$actions = $this->scaffoldActions; $actions = $this->scaffoldActions;
$this->bakeActions($actions, $vars); $this->bakeActions($actions, $vars);
} }
if (strtolower($wannaDoAdmin) == 'y') { if (strtolower($wannaDoAdmin) === 'y') {
$admin = $this->Project->getPrefix(); $admin = $this->Project->getPrefix();
$regularActions = $this->scaffoldActions; $regularActions = $this->scaffoldActions;
$adminActions = array(); $adminActions = array();
@ -332,7 +332,7 @@ class ViewTask extends BakeTask {
$this->out(__d('cake_console', 'Path: %s', $this->getPath() . $this->controllerName . DS . Inflector::underscore($action) . ".ctp")); $this->out(__d('cake_console', 'Path: %s', $this->getPath() . $this->controllerName . DS . Inflector::underscore($action) . ".ctp"));
$this->hr(); $this->hr();
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y'); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) === 'y') {
$this->bake($action, ' '); $this->bake($action, ' ');
$this->_stop(); $this->_stop();
} else { } else {

View file

@ -326,7 +326,7 @@ class TestShell extends Shell {
break; break;
} }
if ($choice == 'q') { if ($choice === 'q') {
break; break;
} }
} }

View file

@ -67,11 +67,11 @@ class TestsuiteShell extends TestShell {
$category = $this->args[0]; $category = $this->args[0];
if ($category == 'core') { if ($category === 'core') {
$params['core'] = true; $params['core'] = true;
} elseif ($category == 'app') { } elseif ($category === 'app') {
$params['app'] = true; $params['app'] = true;
} elseif ($category != 'core') { } elseif ($category !== 'core') {
$params['plugin'] = $category; $params['plugin'] = $category;
} }

View file

@ -470,9 +470,9 @@ class ConsoleOptionParser {
$params = $args = array(); $params = $args = array();
$this->_tokens = $argv; $this->_tokens = $argv;
while (($token = array_shift($this->_tokens)) !== null) { while (($token = array_shift($this->_tokens)) !== null) {
if (substr($token, 0, 2) == '--') { if (substr($token, 0, 2) === '--') {
$params = $this->_parseLongOption($token, $params); $params = $this->_parseLongOption($token, $params);
} elseif (substr($token, 0, 1) == '-') { } elseif (substr($token, 0, 1) === '-') {
$params = $this->_parseShortOption($token, $params); $params = $this->_parseShortOption($token, $params);
} else { } else {
$args = $this->_parseArg($token, $args); $args = $this->_parseArg($token, $args);
@ -521,9 +521,9 @@ class ConsoleOptionParser {
return $subparser->help(null, $format, $width); return $subparser->help(null, $format, $width);
} }
$formatter = new HelpFormatter($this); $formatter = new HelpFormatter($this);
if ($format == 'text' || $format === true) { if ($format === 'text' || $format === true) {
return $formatter->text($width); return $formatter->text($width);
} elseif ($format == 'xml') { } elseif ($format === 'xml') {
return $formatter->xml(); return $formatter->xml();
} }
} }

View file

@ -153,7 +153,7 @@ class ConsoleOutput {
public function __construct($stream = 'php://stdout') { public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w'); $this->_output = fopen($stream, 'w');
if (DS == '\\' && !(bool)env('ANSICON')) { if (DS === '\\' && !(bool)env('ANSICON')) {
$this->_outputAs = self::PLAIN; $this->_outputAs = self::PLAIN;
} }
} }

View file

@ -290,7 +290,7 @@ class Shell extends Object {
if (!$method->isPublic() || substr($name, 0, 1) === '_') { if (!$method->isPublic() || substr($name, 0, 1) === '_') {
return false; return false;
} }
if ($method->getDeclaringClass()->name == 'Shell') { if ($method->getDeclaringClass()->name === 'Shell') {
return false; return false;
} }
return true; return true;
@ -403,7 +403,7 @@ class Shell extends Object {
*/ */
protected function _displayHelp($command) { protected function _displayHelp($command) {
$format = 'text'; $format = 'text';
if (!empty($this->args[0]) && $this->args[0] == 'xml') { if (!empty($this->args[0]) && $this->args[0] === 'xml') {
$format = 'xml'; $format = 'xml';
$this->stdout->outputAs(ConsoleOutput::RAW); $this->stdout->outputAs(ConsoleOutput::RAW);
} else { } else {
@ -654,10 +654,10 @@ class Shell extends Object {
$this->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path)); $this->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path));
$key = $this->in(__d('cake_console', 'Do you want to overwrite?'), array('y', 'n', 'q'), 'n'); $key = $this->in(__d('cake_console', 'Do you want to overwrite?'), array('y', 'n', 'q'), 'n');
if (strtolower($key) == 'q') { if (strtolower($key) === 'q') {
$this->out(__d('cake_console', '<error>Quitting</error>.'), 2); $this->out(__d('cake_console', '<error>Quitting</error>.'), 2);
$this->_stop(); $this->_stop();
} elseif (strtolower($key) != 'y') { } elseif (strtolower($key) !== 'y') {
$this->out(__d('cake_console', 'Skip `%s`', $path), 2); $this->out(__d('cake_console', 'Skip `%s`', $path), 2);
return false; return false;
} }
@ -695,7 +695,7 @@ class Shell extends Object {
$prompt = __d('cake_console', 'PHPUnit is not installed. Do you want to bake unit test files anyway?'); $prompt = __d('cake_console', 'PHPUnit is not installed. Do you want to bake unit test files anyway?');
$unitTest = $this->in($prompt, array('y', 'n'), 'y'); $unitTest = $this->in($prompt, array('y', 'n'), 'y');
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes'; $result = strtolower($unitTest) === 'y' || strtolower($unitTest) === 'yes';
if ($result) { if ($result) {
$this->out(); $this->out();

View file

@ -201,7 +201,7 @@ class ShellDispatcher {
} }
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell')); $methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
$added = in_array($command, $methods); $added = in_array($command, $methods);
$private = $command[0] == '_' && method_exists($Shell, $command); $private = $command[0] === '_' && method_exists($Shell, $command);
if (!$private) { if (!$private) {
if ($added) { if ($added) {
@ -288,7 +288,7 @@ class ShellDispatcher {
} }
} }
if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) { if ($params['app'][0] === '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
$params['root'] = dirname($params['app']); $params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) { } elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']); $params['root'] .= '/' . dirname($params['app']);

View file

@ -38,7 +38,7 @@ foreach (array('hasOne', 'belongsTo', 'hasMany', 'hasAndBelongsToMany') as $asso
*/ */
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel { class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
<?php if ($useDbConfig != 'default'): ?> <?php if ($useDbConfig !== 'default'): ?>
/** /**
* Use database config * Use database config
* *

View file

@ -29,7 +29,7 @@ if (function_exists('ini_set')) {
ini_set('include_path', $root . PATH_SEPARATOR . __CAKE_PATH__ . PATH_SEPARATOR . ini_get('include_path')); ini_set('include_path', $root . PATH_SEPARATOR . __CAKE_PATH__ . PATH_SEPARATOR . ini_get('include_path'));
} }
if (!include($dispatcher)) { if (!include ($dispatcher)) {
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR); trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
} }
unset($paths, $path, $dispatcher, $root, $ds); unset($paths, $path, $dispatcher, $root, $ds);

View file

@ -32,7 +32,7 @@ endif;
?> ?>
<p id="url-rewriting-warning" style="background-color:#e32; color:#fff;"> <p id="url-rewriting-warning" style="background-color:#e32; color:#fff;">
<?php echo __d('cake_dev', 'URL rewriting is not properly configured on your server.'); ?> <?php echo __d('cake_dev', 'URL rewriting is not properly configured on your server.'); ?>
1) <a target="_blank" href="http://book.cakephp.org/2.0/en/installation/advanced-installation.html#apache-and-mod-rewrite-and-htaccess" style="color:#fff;">Help me configure it</a> 1) <a target="_blank" href="http://book.cakephp.org/2.0/en/installation/url-rewriting.html" style="color:#fff;">Help me configure it</a>
2) <a target="_blank" href="http://book.cakephp.org/2.0/en/development/configuration.html#cakephp-core-configuration" style="color:#fff;">I don't / can't use URL rewriting</a> 2) <a target="_blank" href="http://book.cakephp.org/2.0/en/development/configuration.html#cakephp-core-configuration" style="color:#fff;">I don't / can't use URL rewriting</a>
</p> </p>
<p> <p>

View file

@ -77,7 +77,7 @@ if (!defined('WWW_ROOT')) {
} }
// for built-in server // for built-in server
if (php_sapi_name() == 'cli-server') { if (php_sapi_name() === 'cli-server') {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['REQUEST_URI'])) { if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['REQUEST_URI'])) {
return false; return false;
} }
@ -88,11 +88,11 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path')); ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
} }
if (!include('Cake' . DS . 'bootstrap.php')) { if (!include ('Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} else { } else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) { if (!include (CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} }

View file

@ -77,11 +77,11 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path')); ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
} }
if (!include('Cake' . DS . 'bootstrap.php')) { if (!include ('Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} else { } else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) { if (!include (CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true; $failed = true;
} }
} }

View file

@ -151,7 +151,7 @@ abstract class BaseAuthenticate {
* @param CakeRequest $request Request object. * @param CakeRequest $request Request object.
* @return mixed Either false or an array of user information * @return mixed Either false or an array of user information
*/ */
public function getUser($request) { public function getUser(CakeRequest $request) {
return false; return false;
} }

View file

@ -109,7 +109,7 @@ abstract class BaseAuthorize {
* @param string $path * @param string $path
* @return string the action path for the given request. * @return string the action path for the given request.
*/ */
public function action($request, $path = '/:plugin/:controller/:action') { public function action(CakeRequest $request, $path = '/:plugin/:controller/:action') {
$plugin = empty($request['plugin']) ? null : Inflector::camelize($request['plugin']) . '/'; $plugin = empty($request['plugin']) ? null : Inflector::camelize($request['plugin']) . '/';
$path = str_replace( $path = str_replace(
array(':controller', ':action', ':plugin/'), array(':controller', ':action', ':plugin/'),

View file

@ -107,7 +107,7 @@ class BasicAuthenticate extends BaseAuthenticate {
* @param CakeRequest $request Request object. * @param CakeRequest $request Request object.
* @return mixed Either false or an array of user information * @return mixed Either false or an array of user information
*/ */
public function getUser($request) { public function getUser(CakeRequest $request) {
$username = env('PHP_AUTH_USER'); $username = env('PHP_AUTH_USER');
$pass = env('PHP_AUTH_PW'); $pass = env('PHP_AUTH_PW');

View file

@ -23,7 +23,7 @@ App::uses('BaseAuthorize', 'Controller/Component/Auth');
* {{{ * {{{
* public function isAuthorized($user) { * public function isAuthorized($user) {
* if (!empty($this->request->params['admin'])) { * if (!empty($this->request->params['admin'])) {
* return $user['role'] == 'admin'; * return $user['role'] === 'admin';
* } * }
* return !empty($user); * return !empty($user);
* } * }

View file

@ -134,7 +134,7 @@ class DigestAuthenticate extends BaseAuthenticate {
* @param CakeRequest $request Request object. * @param CakeRequest $request Request object.
* @return mixed Either false or an array of user information * @return mixed Either false or an array of user information
*/ */
public function getUser($request) { public function getUser(CakeRequest $request) {
$digest = $this->_getDigest(); $digest = $this->_getDigest();
if (empty($digest)) { if (empty($digest)) {
return false; return false;
@ -188,7 +188,7 @@ class DigestAuthenticate extends BaseAuthenticate {
$digest = env('PHP_AUTH_DIGEST'); $digest = env('PHP_AUTH_DIGEST');
if (empty($digest) && function_exists('apache_request_headers')) { if (empty($digest) && function_exists('apache_request_headers')) {
$headers = apache_request_headers(); $headers = apache_request_headers();
if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) == 'Digest ') { if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Digest ') {
$digest = substr($headers['Authorization'], 7); $digest = substr($headers['Authorization'], 7);
} }
} }
@ -205,7 +205,7 @@ class DigestAuthenticate extends BaseAuthenticate {
* @return array An array of digest authentication headers * @return array An array of digest authentication headers
*/ */
public function parseAuthData($digest) { public function parseAuthData($digest) {
if (substr($digest, 0, 7) == 'Digest ') { if (substr($digest, 0, 7) === 'Digest ') {
$digest = substr($digest, 7); $digest = substr($digest, 7);
} }
$keys = $match = array(); $keys = $match = array();

View file

@ -419,7 +419,7 @@ class AuthComponent extends Component {
* @param CakeRequest $request The request to authenticate for. If empty, the current request will be used. * @param CakeRequest $request The request to authenticate for. If empty, the current request will be used.
* @return boolean True if $user is authorized, otherwise false * @return boolean True if $user is authorized, otherwise false
*/ */
public function isAuthorized($user = null, $request = null) { public function isAuthorized($user = null, CakeRequest $request = null) {
if (empty($user) && !$this->user()) { if (empty($user) && !$this->user()) {
return false; return false;
} }
@ -771,7 +771,7 @@ class AuthComponent extends Component {
* @return boolean true if the user is logged in, false otherwise * @return boolean true if the user is logged in, false otherwise
*/ */
public function loggedIn() { public function loggedIn() {
return $this->user() != array(); return (boolean)$this->user();
} }
/** /**

View file

@ -130,7 +130,7 @@ class RequestHandlerComponent extends Component {
if (isset($this->request->params['ext'])) { if (isset($this->request->params['ext'])) {
$this->ext = $this->request->params['ext']; $this->ext = $this->request->params['ext'];
} }
if (empty($this->ext) || $this->ext == 'html') { if (empty($this->ext) || $this->ext === 'html') {
$this->_setExtension(); $this->_setExtension();
} }
$this->params = $controller->params; $this->params = $controller->params;
@ -590,7 +590,7 @@ class RequestHandlerComponent extends Component {
} }
$options = array_merge($defaults, $options); $options = array_merge($defaults, $options);
if ($type == 'ajax') { if ($type === 'ajax') {
$controller->layout = $this->ajaxLayout; $controller->layout = $this->ajaxLayout;
return $this->respondAs('html', $options); return $this->respondAs('html', $options);
} }

View file

@ -49,6 +49,7 @@ class SecurityComponent extends Component {
* List of controller actions for which a POST request is required * List of controller actions for which a POST request is required
* *
* @var array * @var array
* @deprecated Use CakeRequest::onlyAllow() instead.
* @see SecurityComponent::requirePost() * @see SecurityComponent::requirePost()
*/ */
public $requirePost = array(); public $requirePost = array();
@ -57,6 +58,7 @@ class SecurityComponent extends Component {
* List of controller actions for which a GET request is required * List of controller actions for which a GET request is required
* *
* @var array * @var array
* @deprecated Use CakeRequest::onlyAllow() instead.
* @see SecurityComponent::requireGet() * @see SecurityComponent::requireGet()
*/ */
public $requireGet = array(); public $requireGet = array();
@ -65,6 +67,7 @@ class SecurityComponent extends Component {
* List of controller actions for which a PUT request is required * List of controller actions for which a PUT request is required
* *
* @var array * @var array
* @deprecated Use CakeRequest::onlyAllow() instead.
* @see SecurityComponent::requirePut() * @see SecurityComponent::requirePut()
*/ */
public $requirePut = array(); public $requirePut = array();
@ -73,6 +76,7 @@ class SecurityComponent extends Component {
* List of controller actions for which a DELETE request is required * List of controller actions for which a DELETE request is required
* *
* @var array * @var array
* @deprecated Use CakeRequest::onlyAllow() instead.
* @see SecurityComponent::requireDelete() * @see SecurityComponent::requireDelete()
*/ */
public $requireDelete = array(); public $requireDelete = array();
@ -131,7 +135,9 @@ class SecurityComponent extends Component {
public $unlockedFields = array(); public $unlockedFields = array();
/** /**
* Actions to exclude from any security checks * Actions to exclude from CSRF and POST validation checks.
* Other checks like requireAuth(), requireSecure(),
* requirePost(), requireGet() etc. will still be applied.
* *
* @var array * @var array
*/ */
@ -248,6 +254,7 @@ class SecurityComponent extends Component {
* Sets the actions that require a POST request, or empty for all actions * Sets the actions that require a POST request, or empty for all actions
* *
* @return void * @return void
* @deprecated Use CakeRequest::onlyAllow() instead.
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requirePost * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requirePost
*/ */
public function requirePost() { public function requirePost() {
@ -258,6 +265,7 @@ class SecurityComponent extends Component {
/** /**
* Sets the actions that require a GET request, or empty for all actions * Sets the actions that require a GET request, or empty for all actions
* *
* @deprecated Use CakeRequest::onlyAllow() instead.
* @return void * @return void
*/ */
public function requireGet() { public function requireGet() {
@ -268,6 +276,7 @@ class SecurityComponent extends Component {
/** /**
* Sets the actions that require a PUT request, or empty for all actions * Sets the actions that require a PUT request, or empty for all actions
* *
* @deprecated Use CakeRequest::onlyAllow() instead.
* @return void * @return void
*/ */
public function requirePut() { public function requirePut() {
@ -278,6 +287,7 @@ class SecurityComponent extends Component {
/** /**
* Sets the actions that require a DELETE request, or empty for all actions * Sets the actions that require a DELETE request, or empty for all actions
* *
* @deprecated Use CakeRequest::onlyAllow() instead.
* @return void * @return void
*/ */
public function requireDelete() { public function requireDelete() {
@ -297,7 +307,11 @@ class SecurityComponent extends Component {
} }
/** /**
* Sets the actions that require an authenticated request, or empty for all actions * Sets the actions that require whitelisted form submissions.
*
* Adding actions with this method will enforce the restrictions
* set in SecurityComponent::$allowedControllers and
* SecurityComponent::$allowedActions.
* *
* @return void * @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireAuth * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireAuth

View file

@ -963,7 +963,7 @@ class Controller extends Object implements CakeEventListener {
} }
$referer = $this->request->referer($local); $referer = $this->request->referer($local);
if ($referer == '/' && $default) { if ($referer === '/' && $default) {
return Router::url($default, true); return Router::url($default, true);
} }
return $referer; return $referer;
@ -1048,13 +1048,13 @@ class Controller extends Object implements CakeEventListener {
if ($fieldOp === 'LIKE') { if ($fieldOp === 'LIKE') {
$key = $key . ' LIKE'; $key = $key . ' LIKE';
$value = '%' . $value . '%'; $value = '%' . $value . '%';
} elseif ($fieldOp && $fieldOp != '=') { } elseif ($fieldOp && $fieldOp !== '=') {
$key = $key . ' ' . $fieldOp; $key = $key . ' ' . $fieldOp;
} }
$cond[$key] = $value; $cond[$key] = $value;
} }
} }
if ($bool && strtoupper($bool) != 'AND') { if ($bool && strtoupper($bool) !== 'AND') {
$cond = array($bool => $cond); $cond = array($bool => $cond);
} }
return $cond; return $cond;

View file

@ -227,7 +227,7 @@ class Scaffold {
} }
if ($this->controller->beforeScaffold($action)) { if ($this->controller->beforeScaffold($action)) {
if ($action == 'edit') { if ($action === 'edit') {
if (isset($request->params['pass'][0])) { if (isset($request->params['pass'][0])) {
$this->ScaffoldModel->id = $request['pass'][0]; $this->ScaffoldModel->id = $request['pass'][0];
} }
@ -237,7 +237,7 @@ class Scaffold {
} }
if (!empty($request->data)) { if (!empty($request->data)) {
if ($action == 'create') { if ($action === 'create') {
$this->ScaffoldModel->create(); $this->ScaffoldModel->create();
} }
@ -443,7 +443,7 @@ class Scaffold {
$associations[$type][$assocKey]['controller'] = $associations[$type][$assocKey]['controller'] =
Inflector::pluralize(Inflector::underscore($model)); Inflector::pluralize(Inflector::underscore($model));
if ($type == 'hasAndBelongsToMany') { if ($type === 'hasAndBelongsToMany') {
$associations[$type][$assocKey]['with'] = $assocData['with']; $associations[$type][$assocKey]['with'] = $assocData['with'];
} }
} }

View file

@ -433,7 +433,7 @@ class App {
$type = 'plugins'; $type = 'plugins';
} }
if ($type == 'plugins') { if ($type === 'plugins') {
$extension = '/.*/'; $extension = '/.*/';
$includeDirectories = true; $includeDirectories = true;
} }
@ -637,11 +637,11 @@ class App {
return self::_loadClass($name, $plugin, $type, $originalType, $parent); return self::_loadClass($name, $plugin, $type, $originalType, $parent);
} }
if ($originalType == 'file' && !empty($file)) { if ($originalType === 'file' && !empty($file)) {
return self::_loadFile($name, $plugin, $search, $file, $return); return self::_loadFile($name, $plugin, $search, $file, $return);
} }
if ($originalType == 'vendor') { if ($originalType === 'vendor') {
return self::_loadVendor($name, $plugin, $file, $ext); return self::_loadVendor($name, $plugin, $file, $ext);
} }
@ -660,7 +660,7 @@ class App {
* @return boolean true indicating the successful load and existence of the class * @return boolean true indicating the successful load and existence of the class
*/ */
protected static function _loadClass($name, $plugin, $type, $originalType, $parent) { protected static function _loadClass($name, $plugin, $type, $originalType, $parent) {
if ($type == 'Console/Command' && $name == 'Shell') { if ($type === 'Console/Command' && $name === 'Shell') {
$type = 'Console'; $type = 'Console';
} elseif (isset(self::$types[$originalType]['suffix'])) { } elseif (isset(self::$types[$originalType]['suffix'])) {
$suffix = self::$types[$originalType]['suffix']; $suffix = self::$types[$originalType]['suffix'];

View file

@ -149,7 +149,7 @@ class ErrorHandler {
$message .= "\nException Attributes: " . var_export($exception->getAttributes(), true); $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
} }
} }
if (php_sapi_name() != 'cli') { if (php_sapi_name() !== 'cli') {
$request = Router::getRequest(); $request = Router::getRequest();
if ($request) { if ($request) {
$message .= "\nRequest URL: " . $request->here(); $message .= "\nRequest URL: " . $request->here();

View file

@ -104,7 +104,7 @@ class ExceptionRenderer {
if ($exception instanceof CakeException && !$methodExists) { if ($exception instanceof CakeException && !$methodExists) {
$method = '_cakeError'; $method = '_cakeError';
if (empty($template) || $template == 'internalError') { if (empty($template) || $template === 'internalError') {
$template = 'error500'; $template = 'error500';
} }
} elseif ($exception instanceof PDOException) { } elseif ($exception instanceof PDOException) {
@ -119,7 +119,7 @@ class ExceptionRenderer {
} }
$isNotDebug = !Configure::read('debug'); $isNotDebug = !Configure::read('debug');
if ($isNotDebug && $method == '_cakeError') { if ($isNotDebug && $method === '_cakeError') {
$method = 'error400'; $method = 'error400';
} }
if ($isNotDebug && $code == 500) { if ($isNotDebug && $code == 500) {

View file

@ -174,7 +174,7 @@ class I18n {
Cache::write($_this->domain, $_this->_domains[$domain][$_this->_lang], '_cake_core_'); Cache::write($_this->domain, $_this->_domains[$domain][$_this->_lang], '_cake_core_');
} }
if ($_this->category == 'LC_TIME') { if ($_this->category === 'LC_TIME') {
return $_this->_translateTime($singular, $domain); return $_this->_translateTime($singular, $domain);
} }
@ -410,7 +410,7 @@ class I18n {
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header); $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($header); extract($header);
if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && !$version) { if ((dechex($magic) === '950412de' || dechex($magic) === 'ffffffff950412de') && !$version) {
for ($n = 0; $n < $count; $n++) { for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8)); $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]); $msgid = substr($data, $r["offs"], $r["len"]);

View file

@ -750,7 +750,7 @@ class Multibyte {
$length = 75 - strlen($start) - strlen($end); $length = 75 - strlen($start) - strlen($end);
$length = $length - ($length % 4); $length = $length - ($length % 4);
if ($charset == 'UTF-8') { if ($charset === 'UTF-8') {
$parts = array(); $parts = array();
$maxchars = floor(($length * 3) / 4); $maxchars = floor(($length * 3) / 4);
$stringLength = strlen($string); $stringLength = strlen($string);

View file

@ -428,7 +428,7 @@ class CakeLog {
foreach (self::$_Collection->enabled() as $streamName) { foreach (self::$_Collection->enabled() as $streamName) {
$logger = self::$_Collection->{$streamName}; $logger = self::$_Collection->{$streamName};
$types = $scopes = $config = array(); $types = $scopes = $config = array();
if ($logger instanceof BaseLog) { if (method_exists($logger, 'config')) {
$config = $logger->config(); $config = $logger->config();
} }
if (isset($config['types'])) { if (isset($config['types'])) {

View file

@ -57,8 +57,10 @@ abstract class BaseLog implements CakeLogInterface {
*/ */
public function config($config = array()) { public function config($config = array()) {
if (!empty($config)) { if (!empty($config)) {
if (isset($config['types']) && is_string($config['types'])) { foreach (array('types', 'scopes') as $option) {
$config['types'] = array($config['types']); if (isset($config[$option]) && is_string($config[$option])) {
$config[$option] = array($config[$option]);
}
} }
$this->_config = $config; $this->_config = $config;
} }

View file

@ -50,7 +50,7 @@ class ConsoleLog extends BaseLog {
*/ */
public function __construct($config = array()) { public function __construct($config = array()) {
parent::__construct($config); parent::__construct($config);
if (DS == '\\' && !(bool)env('ANSICON')) { if (DS === '\\' && !(bool)env('ANSICON')) {
$outputAs = ConsoleOutput::PLAIN; $outputAs = ConsoleOutput::PLAIN;
} else { } else {
$outputAs = ConsoleOutput::COLOR; $outputAs = ConsoleOutput::COLOR;

View file

@ -200,7 +200,7 @@ class ContainableBehavior extends ModelBehavior {
if (!empty($mandatory[$Model->alias])) { if (!empty($mandatory[$Model->alias])) {
foreach ($mandatory[$Model->alias] as $field) { foreach ($mandatory[$Model->alias] as $field) {
if ($field == '--primaryKey--') { if ($field === '--primaryKey--') {
$field = $Model->primaryKey; $field = $Model->primaryKey;
} elseif (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) { } elseif (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) {
list($modelName, $field) = explode('.', $field); list($modelName, $field) = explode('.', $field);
@ -307,7 +307,7 @@ class ContainableBehavior extends ModelBehavior {
if (!$optionKey && is_string($key) && preg_match('/^[a-z(]/', $key) && (!isset($Model->{$key}) || !is_object($Model->{$key}))) { if (!$optionKey && is_string($key) && preg_match('/^[a-z(]/', $key) && (!isset($Model->{$key}) || !is_object($Model->{$key}))) {
$option = 'fields'; $option = 'fields';
$val = array($key); $val = array($key);
if ($key{0} == '(') { if ($key{0} === '(') {
$val = preg_split('/\s*,\s*/', substr($key, 1, -1)); $val = preg_split('/\s*,\s*/', substr($key, 1, -1));
} elseif (preg_match('/ASC|DESC$/', $key)) { } elseif (preg_match('/ASC|DESC$/', $key)) {
$option = 'order'; $option = 'order';
@ -374,9 +374,9 @@ class ContainableBehavior extends ModelBehavior {
foreach ($map as $parent => $children) { foreach ($map as $parent => $children) {
foreach ($children as $type => $bindings) { foreach ($children as $type => $bindings) {
foreach ($bindings as $dependency) { foreach ($bindings as $dependency) {
if ($type == 'hasAndBelongsToMany') { if ($type === 'hasAndBelongsToMany') {
$fields[$parent][] = '--primaryKey--'; $fields[$parent][] = '--primaryKey--';
} elseif ($type == 'belongsTo') { } elseif ($type === 'belongsTo') {
$fields[$parent][] = $dependency . '.--primaryKey--'; $fields[$parent][] = $dependency . '.--primaryKey--';
} }
} }

View file

@ -108,7 +108,8 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
$behavior = $config['className']; $behavior = $config['className'];
} }
$configDisabled = isset($config['enabled']) && $config['enabled'] === false; $configDisabled = isset($config['enabled']) && $config['enabled'] === false;
unset($config['enabled'], $config['className']); $priority = isset($config['priority']) ? $config['priority'] : $this->defaultPriority;
unset($config['enabled'], $config['className'], $config['priority']);
list($plugin, $name) = pluginSplit($behavior, true); list($plugin, $name) = pluginSplit($behavior, true);
if (!isset($alias)) { if (!isset($alias)) {
@ -145,6 +146,7 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
if (empty($config)) { if (empty($config)) {
$config = array(); $config = array();
} }
$this->_loaded[$alias]->settings['priority'] = $priority;
$this->_loaded[$alias]->setup(ClassRegistry::getObject($this->modelName), $config); $this->_loaded[$alias]->setup(ClassRegistry::getObject($this->modelName), $config);
foreach ($this->_loaded[$alias]->mapMethods as $method => $methodAlias) { foreach ($this->_loaded[$alias]->mapMethods as $method => $methodAlias) {
@ -160,7 +162,7 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
foreach ($methods as $m) { foreach ($methods as $m) {
if (!isset($parentMethods[$m])) { if (!isset($parentMethods[$m])) {
$methodAllowed = ( $methodAllowed = (
$m[0] != '_' && !array_key_exists($m, $this->_methods) && $m[0] !== '_' && !array_key_exists($m, $this->_methods) &&
!in_array($m, $callbacks) !in_array($m, $callbacks)
); );
if ($methodAllowed) { if ($methodAllowed) {
@ -169,11 +171,14 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
} }
} }
if (!in_array($alias, $this->_enabled) && !$configDisabled) { if ($configDisabled) {
$this->disable($alias);
} elseif (!$this->enabled($alias)) {
$this->enable($alias); $this->enable($alias);
} else { } else {
$this->disable($alias); $this->setPriority($alias, $priority);
} }
return true; return true;
} }

View file

@ -227,7 +227,7 @@ class CakeSchema extends Object {
foreach ($models as $model) { foreach ($models as $model) {
$importModel = $model; $importModel = $model;
$plugin = null; $plugin = null;
if ($model == 'AppModel') { if ($model === 'AppModel') {
continue; continue;
} }
@ -412,7 +412,7 @@ class CakeSchema extends Object {
if (is_array($fields)) { if (is_array($fields)) {
$cols = array(); $cols = array();
foreach ($fields as $field => $value) { foreach ($fields as $field => $value) {
if ($field != 'indexes' && $field != 'tableParameters') { if ($field !== 'indexes' && $field !== 'tableParameters') {
if (is_string($value)) { if (is_string($value)) {
$type = $value; $type = $value;
$value = array('type' => $type); $value = array('type' => $type);
@ -420,14 +420,14 @@ class CakeSchema extends Object {
$col = "\t\t'{$field}' => array('type' => '" . $value['type'] . "', "; $col = "\t\t'{$field}' => array('type' => '" . $value['type'] . "', ";
unset($value['type']); unset($value['type']);
$col .= implode(', ', $this->_values($value)); $col .= implode(', ', $this->_values($value));
} elseif ($field == 'indexes') { } elseif ($field === 'indexes') {
$col = "\t\t'indexes' => array(\n\t\t\t"; $col = "\t\t'indexes' => array(\n\t\t\t";
$props = array(); $props = array();
foreach ((array)$value as $key => $index) { foreach ((array)$value as $key => $index) {
$props[] = "'{$key}' => array(" . implode(', ', $this->_values($index)) . ")"; $props[] = "'{$key}' => array(" . implode(', ', $this->_values($index)) . ")";
} }
$col .= implode(",\n\t\t\t", $props) . "\n\t\t"; $col .= implode(",\n\t\t\t", $props) . "\n\t\t";
} elseif ($field == 'tableParameters') { } elseif ($field === 'tableParameters') {
$col = "\t\t'tableParameters' => array("; $col = "\t\t'tableParameters' => array(";
$props = array(); $props = array();
foreach ((array)$value as $key => $param) { foreach ((array)$value as $key => $param) {
@ -472,7 +472,7 @@ class CakeSchema extends Object {
} }
$tables = array(); $tables = array();
foreach ($new as $table => $fields) { foreach ($new as $table => $fields) {
if ($table == 'missing') { if ($table === 'missing') {
continue; continue;
} }
if (!array_key_exists($table, $old)) { if (!array_key_exists($table, $old)) {

View file

@ -586,8 +586,11 @@ class Mysql extends DboSource {
} }
$name = $this->startQuote . $name . $this->endQuote; $name = $this->startQuote . $name . $this->endQuote;
} }
// length attribute only used for MySQL datasource, for TEXT/BLOB index columns if (isset($value['type']) && strtolower($value['type']) === 'fulltext') {
$out .= 'FULLTEXT ';
}
$out .= 'KEY ' . $name . ' ('; $out .= 'KEY ' . $name . ' (';
if (is_array($value['column'])) { if (is_array($value['column'])) {
if (isset($value['length'])) { if (isset($value['length'])) {
$vals = array(); $vals = array();

View file

@ -94,6 +94,13 @@ class Postgres extends DboSource {
*/ */
protected $_sequenceMap = array(); protected $_sequenceMap = array();
/**
* The set of valid SQL operations usable in a WHERE statement
*
* @var array
*/
protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', '~', '~*', '!~', '!~*', 'similar to');
/** /**
* Connects to the database using options in the given configuration array. * Connects to the database using options in the given configuration array.
* *
@ -199,10 +206,10 @@ class Postgres extends DboSource {
foreach ($cols as $c) { foreach ($cols as $c) {
$type = $c->type; $type = $c->type;
if (!empty($c->oct_length) && $c->char_length === null) { if (!empty($c->oct_length) && $c->char_length === null) {
if ($c->type == 'character varying') { if ($c->type === 'character varying') {
$length = null; $length = null;
$type = 'text'; $type = 'text';
} elseif ($c->type == 'uuid') { } elseif ($c->type === 'uuid') {
$length = 36; $length = 36;
} else { } else {
$length = intval($c->oct_length); $length = intval($c->oct_length);
@ -217,7 +224,7 @@ class Postgres extends DboSource {
} }
$fields[$c->name] = array( $fields[$c->name] = array(
'type' => $this->column($type), 'type' => $this->column($type),
'null' => ($c->null == 'NO' ? false : true), 'null' => ($c->null === 'NO' ? false : true),
'default' => preg_replace( 'default' => preg_replace(
"/^'(.*)'$/", "/^'(.*)'$/",
"$1", "$1",
@ -234,7 +241,7 @@ class Postgres extends DboSource {
} }
} }
if ( if (
$fields[$c->name]['default'] == 'NULL' || $fields[$c->name]['default'] === 'NULL' ||
preg_match('/nextval\([\'"]?([\w.]+)/', $c->default, $seq) preg_match('/nextval\([\'"]?([\w.]+)/', $c->default, $seq)
) { ) {
$fields[$c->name]['default'] = null; $fields[$c->name]['default'] = null;
@ -247,7 +254,7 @@ class Postgres extends DboSource {
$this->_sequenceMap[$table][$c->name] = $sequenceName; $this->_sequenceMap[$table][$c->name] = $sequenceName;
} }
} }
if ($fields[$c->name]['type'] == 'boolean' && !empty($fields[$c->name]['default'])) { if ($fields[$c->name]['type'] === 'boolean' && !empty($fields[$c->name]['default'])) {
$fields[$c->name]['default'] = constant($fields[$c->name]['default']); $fields[$c->name]['default'] = constant($fields[$c->name]['default']);
} }
} }
@ -382,7 +389,7 @@ class Postgres extends DboSource {
$result = array(); $result = array();
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) { if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) {
if (substr($fields[$i], -1) == '*') { if (substr($fields[$i], -1) === '*') {
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') { if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
$build = explode('.', $fields[$i]); $build = explode('.', $fields[$i]);
$AssociatedModel = $model->{$build[0]}; $AssociatedModel = $model->{$build[0]};
@ -526,6 +533,12 @@ class Postgres extends DboSource {
$default = isset($col['default']) ? $col['default'] : null; $default = isset($col['default']) ? $col['default'] : null;
$nullable = isset($col['null']) ? $col['null'] : null; $nullable = isset($col['null']) ? $col['null'] : null;
unset($col['default'], $col['null']); unset($col['default'], $col['null']);
if ($field !== $col['name']) {
$newName = $this->name($col['name']);
$out .= "\tRENAME {$fieldName} TO {$newName};\n";
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
$fieldName = $newName;
}
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)); $colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
if (isset($nullable)) { if (isset($nullable)) {
$nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL'; $nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL';
@ -576,7 +589,7 @@ class Postgres extends DboSource {
if (isset($indexes['drop'])) { if (isset($indexes['drop'])) {
foreach ($indexes['drop'] as $name => $value) { foreach ($indexes['drop'] as $name => $value) {
$out = 'DROP '; $out = 'DROP ';
if ($name == 'PRIMARY') { if ($name === 'PRIMARY') {
continue; continue;
} else { } else {
$out .= 'INDEX ' . $name; $out .= 'INDEX ' . $name;
@ -587,7 +600,7 @@ class Postgres extends DboSource {
if (isset($indexes['add'])) { if (isset($indexes['add'])) {
foreach ($indexes['add'] as $name => $value) { foreach ($indexes['add'] as $name => $value) {
$out = 'CREATE '; $out = 'CREATE ';
if ($name == 'PRIMARY') { if ($name === 'PRIMARY') {
continue; continue;
} else { } else {
if (!empty($value['unique'])) { if (!empty($value['unique'])) {
@ -663,11 +676,11 @@ class Postgres extends DboSource {
return 'datetime'; return 'datetime';
case (strpos($col, 'time') === 0): case (strpos($col, 'time') === 0):
return 'time'; return 'time';
case ($col == 'bigint'): case ($col === 'bigint'):
return 'biginteger'; return 'biginteger';
case (strpos($col, 'int') !== false && $col != 'interval'): case (strpos($col, 'int') !== false && $col !== 'interval'):
return 'integer'; return 'integer';
case (strpos($col, 'char') !== false || $col == 'uuid'): case (strpos($col, 'char') !== false || $col === 'uuid'):
return 'string'; return 'string';
case (strpos($col, 'text') !== false): case (strpos($col, 'text') !== false):
return 'text'; return 'text';
@ -693,7 +706,7 @@ class Postgres extends DboSource {
if (strpos($col, '(') !== false) { if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col); list($col, $limit) = explode('(', $col);
} }
if ($col == 'uuid') { if ($col === 'uuid') {
return 36; return 36;
} }
if ($limit) { if ($limit) {
@ -852,7 +865,7 @@ class Postgres extends DboSource {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT NULL', $out); $out = str_replace('DEFAULT DEFAULT', 'DEFAULT NULL', $out);
} elseif (in_array($column['type'], array('integer', 'float'))) { } elseif (in_array($column['type'], array('integer', 'float'))) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT 0', $out); $out = str_replace('DEFAULT DEFAULT', 'DEFAULT 0', $out);
} elseif ($column['type'] == 'boolean') { } elseif ($column['type'] === 'boolean') {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT FALSE', $out); $out = str_replace('DEFAULT DEFAULT', 'DEFAULT FALSE', $out);
} }
} }
@ -872,7 +885,7 @@ class Postgres extends DboSource {
return array(); return array();
} }
foreach ($indexes as $name => $value) { foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') { if ($name === 'PRIMARY') {
$out = 'PRIMARY KEY (' . $this->name($value['column']) . ')'; $out = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
} else { } else {
$out = 'CREATE '; $out = 'CREATE ';

View file

@ -357,7 +357,7 @@ class Sqlite extends DboSource {
foreach ($this->map as $col => $meta) { foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta; list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col]; $resultRow[$table][$column] = $row[$col];
if ($type == 'boolean' && !is_null($row[$col])) { if ($type === 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
} }
} }
@ -412,7 +412,7 @@ class Sqlite extends DboSource {
return null; return null;
} }
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') { if (isset($column['key']) && $column['key'] === 'primary' && $type === 'integer') {
return $this->name($name) . ' ' . $this->columns['primary_key']['name']; return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
} }
return parent::buildColumn($column); return parent::buildColumn($column);
@ -456,7 +456,7 @@ class Sqlite extends DboSource {
foreach ($indexes as $name => $value) { foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') { if ($name === 'PRIMARY') {
continue; continue;
} }
$out = 'CREATE '; $out = 'CREATE ';

View file

@ -227,7 +227,7 @@ class Sqlserver extends DboSource {
$this->value($fields[$field]['default'], $fields[$field]['type']); $this->value($fields[$field]['default'], $fields[$field]['type']);
} }
if ($fields[$field]['key'] !== false && $fields[$field]['type'] == 'integer') { if ($fields[$field]['key'] !== false && $fields[$field]['type'] === 'integer') {
$fields[$field]['length'] = 11; $fields[$field]['length'] = 11;
} elseif ($fields[$field]['key'] === false) { } elseif ($fields[$field]['key'] === false) {
unset($fields[$field]['key']); unset($fields[$field]['key']);
@ -235,7 +235,7 @@ class Sqlserver extends DboSource {
if (in_array($fields[$field]['type'], array('date', 'time', 'datetime', 'timestamp'))) { if (in_array($fields[$field]['type'], array('date', 'time', 'datetime', 'timestamp'))) {
$fields[$field]['length'] = null; $fields[$field]['length'] = null;
} }
if ($fields[$field]['type'] == 'float' && !empty($column->Size)) { if ($fields[$field]['type'] === 'float' && !empty($column->Size)) {
$fields[$field]['length'] = $fields[$field]['length'] . ',' . $column->Size; $fields[$field]['length'] = $fields[$field]['length'] . ',' . $column->Size;
} }
} }
@ -271,7 +271,7 @@ class Sqlserver extends DboSource {
} }
if (!preg_match('/\s+AS\s+/i', $fields[$i])) { if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
if (substr($fields[$i], -1) == '*') { if (substr($fields[$i], -1) === '*') {
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') { if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
$build = explode('.', $fields[$i]); $build = explode('.', $fields[$i]);
$AssociatedModel = $model->{$build[0]}; $AssociatedModel = $model->{$build[0]};
@ -299,7 +299,7 @@ class Sqlserver extends DboSource {
$fieldName = $this->name($name); $fieldName = $this->name($name);
$fieldAlias = $this->name($alias); $fieldAlias = $this->name($alias);
} }
if ($model->getColumnType($fields[$i]) == 'datetime') { if ($model->getColumnType($fields[$i]) === 'datetime') {
$fieldName = "CONVERT(VARCHAR(20), {$fieldName}, 20)"; $fieldName = "CONVERT(VARCHAR(20), {$fieldName}, 20)";
} }
$fields[$i] = "{$fieldName} AS {$fieldAlias}"; $fields[$i] = "{$fieldName} AS {$fieldAlias}";
@ -402,13 +402,13 @@ class Sqlserver extends DboSource {
$col = $real->Type; $col = $real->Type;
} }
if ($col == 'datetime2') { if ($col === 'datetime2') {
return 'datetime'; return 'datetime';
} }
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) { if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col; return $col;
} }
if ($col == 'bit') { if ($col === 'bit') {
return 'boolean'; return 'boolean';
} }
if (strpos($col, 'bigint') !== false) { if (strpos($col, 'bigint') !== false) {
@ -426,7 +426,7 @@ class Sqlserver extends DboSource {
if (strpos($col, 'text') !== false) { if (strpos($col, 'text') !== false) {
return 'text'; return 'text';
} }
if (strpos($col, 'binary') !== false || $col == 'image') { if (strpos($col, 'binary') !== false || $col === 'image') {
return 'binary'; return 'binary';
} }
if (in_array($col, array('float', 'real', 'decimal', 'numeric'))) { if (in_array($col, array('float', 'real', 'decimal', 'numeric'))) {
@ -481,7 +481,7 @@ class Sqlserver extends DboSource {
} else { } else {
$map = array(0, $name); $map = array(0, $name);
} }
$map[] = ($column['sqlsrv:decl_type'] == 'bit') ? 'boolean' : $column['native_type']; $map[] = ($column['sqlsrv:decl_type'] === 'bit') ? 'boolean' : $column['native_type'];
$this->map[$index++] = $map; $this->map[$index++] = $map;
} }
} }
@ -683,7 +683,7 @@ class Sqlserver extends DboSource {
$join = array(); $join = array();
foreach ($indexes as $name => $value) { foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') { if ($name === 'PRIMARY') {
$join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')'; $join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
} elseif (isset($value['unique']) && $value['unique']) { } elseif (isset($value['unique']) && $value['unique']) {
$out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE"; $out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE";
@ -709,7 +709,7 @@ class Sqlserver extends DboSource {
protected function _getPrimaryKey($model) { protected function _getPrimaryKey($model) {
$schema = $this->describe($model); $schema = $this->describe($model);
foreach ($schema as $field => $props) { foreach ($schema as $field => $props) {
if (isset($props['key']) && $props['key'] == 'primary') { if (isset($props['key']) && $props['key'] === 'primary') {
return $field; return $field;
} }
} }

View file

@ -323,9 +323,9 @@ class DboSource extends DataSource {
$data, array_fill(0, count($data), $column) $data, array_fill(0, count($data), $column)
); );
} elseif (is_object($data) && isset($data->type, $data->value)) { } elseif (is_object($data) && isset($data->type, $data->value)) {
if ($data->type == 'identifier') { if ($data->type === 'identifier') {
return $this->name($data->value); return $this->name($data->value);
} elseif ($data->type == 'expression') { } elseif ($data->type === 'expression') {
return $data->value; return $data->value;
} }
} elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { } elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) {
@ -899,7 +899,7 @@ class DboSource extends DataSource {
if (empty($log['log'])) { if (empty($log['log'])) {
return; return;
} }
if (PHP_SAPI != 'cli') { if (PHP_SAPI !== 'cli') {
$controller = null; $controller = null;
$View = new View($controller, false); $View = new View($controller, false);
$View->set('logs', array($this->configKeyName => $log)); $View->set('logs', array($this->configKeyName => $log));
@ -1878,7 +1878,7 @@ class DboSource extends DataSource {
if ($quoteValues) { if ($quoteValues) {
$update .= $this->value($value, $model->getColumnType($field)); $update .= $this->value($value, $model->getColumnType($field));
} elseif ($model->getColumnType($field) == 'boolean' && (is_int($value) || is_bool($value))) { } elseif ($model->getColumnType($field) === 'boolean' && (is_int($value) || is_bool($value))) {
$update .= $this->boolean($value, true); $update .= $this->boolean($value, true);
} elseif (!$alias) { } elseif (!$alias) {
$update .= str_replace($quotedAlias . '.', '', str_replace( $update .= str_replace($quotedAlias . '.', '', str_replace(
@ -3170,8 +3170,6 @@ class DboSource extends DataSource {
} else { } else {
if (!empty($value['unique'])) { if (!empty($value['unique'])) {
$out .= 'UNIQUE '; $out .= 'UNIQUE ';
} elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') {
$out .= 'FULLTEXT ';
} }
$name = $this->startQuote . $name . $this->endQuote; $name = $this->startQuote . $name . $this->endQuote;
} }

View file

@ -818,7 +818,7 @@ class Model extends Object implements CakeEventListener {
$className = empty($this->__backAssociation[$type][$name]['className']) ? $className = empty($this->__backAssociation[$type][$name]['className']) ?
$name : $this->__backAssociation[$type][$name]['className']; $name : $this->__backAssociation[$type][$name]['className'];
break; break;
} elseif ($type == 'hasAndBelongsToMany') { } elseif ($type === 'hasAndBelongsToMany') {
foreach ($this->{$type} as $k => $relation) { foreach ($this->{$type} as $k => $relation) {
if (empty($relation['with'])) { if (empty($relation['with'])) {
continue; continue;
@ -1061,7 +1061,7 @@ class Model extends Object implements CakeEventListener {
break; break;
case 'foreignKey': case 'foreignKey':
$data = (($type == 'belongsTo') ? Inflector::underscore($assocKey) : Inflector::singularize($this->table)) . '_id'; $data = (($type === 'belongsTo') ? Inflector::underscore($assocKey) : Inflector::singularize($this->table)) . '_id';
break; break;
case 'associationForeignKey': case 'associationForeignKey':
@ -1262,7 +1262,7 @@ class Model extends Object implements CakeEventListener {
if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && 'am' == $data['meridian']) { if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && 'am' == $data['meridian']) {
$data['hour'] = '00'; $data['hour'] = '00';
} }
if ($type == 'time') { if ($type === 'time') {
foreach ($timeFields as $key => $val) { foreach ($timeFields as $key => $val) {
if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') { if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') {
$data[$val] = '00'; $data[$val] = '00';
@ -1277,9 +1277,9 @@ class Model extends Object implements CakeEventListener {
} }
} }
if ($type == 'datetime' || $type == 'timestamp' || $type == 'date') { if ($type === 'datetime' || $type === 'timestamp' || $type === 'date') {
foreach ($dateFields as $key => $val) { foreach ($dateFields as $key => $val) {
if ($val == 'hour' || $val == 'min' || $val == 'sec') { if ($val === 'hour' || $val === 'min' || $val === 'sec') {
if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') { if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') {
$data[$val] = '00'; $data[$val] = '00';
} else { } else {

View file

@ -100,7 +100,7 @@ class Permission extends AppModel {
return false; return false;
} }
if ($action != '*' && !in_array('_' . $action, $permKeys)) { if ($action !== '*' && !in_array('_' . $action, $permKeys)) {
trigger_error(__d('cake_dev', "ACO permissions key %s does not exist in DbAcl::check()", $action), E_USER_NOTICE); trigger_error(__d('cake_dev', "ACO permissions key %s does not exist in DbAcl::check()", $action), E_USER_NOTICE);
return false; return false;
} }
@ -126,7 +126,7 @@ class Permission extends AppModel {
} else { } else {
$perms = Hash::extract($perms, '{n}.' . $this->alias); $perms = Hash::extract($perms, '{n}.' . $this->alias);
foreach ($perms as $perm) { foreach ($perms as $perm) {
if ($action == '*') { if ($action === '*') {
foreach ($permKeys as $key) { foreach ($permKeys as $key) {
if (!empty($perm)) { if (!empty($perm)) {

View file

@ -194,7 +194,7 @@ class CakeValidationRule {
*/ */
public function skip() { public function skip() {
if (!empty($this->on)) { if (!empty($this->on)) {
if ($this->on == 'create' && $this->isUpdate() || $this->on == 'update' && !$this->isUpdate()) { if ($this->on === 'create' && $this->isUpdate() || $this->on === 'update' && !$this->isUpdate()) {
return true; return true;
} }
} }

View file

@ -134,7 +134,7 @@ class CakeRequest implements ArrayAccess {
if (empty($url)) { if (empty($url)) {
$url = $this->_url(); $url = $this->_url();
} }
if ($url[0] == '/') { if ($url[0] === '/') {
$url = substr($url, 1); $url = substr($url, 1);
} }
$this->url = $url; $this->url = $url;
@ -255,7 +255,7 @@ class CakeRequest implements ArrayAccess {
if (strpos($uri, '?') !== false) { if (strpos($uri, '?') !== false) {
list($uri) = explode('?', $uri, 2); list($uri) = explode('?', $uri, 2);
} }
if (empty($uri) || $uri == '/' || $uri == '//' || $uri == '/index.php') { if (empty($uri) || $uri === '/' || $uri === '//' || $uri === '/index.php') {
return '/'; return '/';
} }
return $uri; return $uri;
@ -412,7 +412,7 @@ class CakeRequest implements ArrayAccess {
if (!empty($ref) && !empty($base)) { if (!empty($ref) && !empty($base)) {
if ($local && strpos($ref, $base) === 0) { if ($local && strpos($ref, $base) === 0) {
$ref = substr($ref, strlen($base)); $ref = substr($ref, strlen($base));
if ($ref[0] != '/') { if ($ref[0] !== '/') {
$ref = '/' . $ref; $ref = '/' . $ref;
} }
return $ref; return $ref;
@ -907,10 +907,10 @@ class CakeRequest implements ArrayAccess {
if (isset($this->params[$name])) { if (isset($this->params[$name])) {
return $this->params[$name]; return $this->params[$name];
} }
if ($name == 'url') { if ($name === 'url') {
return $this->query; return $this->query;
} }
if ($name == 'data') { if ($name === 'data') {
return $this->data; return $this->data;
} }
return null; return null;

View file

@ -135,7 +135,7 @@ class CakeSocket {
} }
$scheme = null; $scheme = null;
if (isset($this->config['request']['uri']) && $this->config['request']['uri']['scheme'] == 'https') { if (isset($this->config['request']['uri']) && $this->config['request']['uri']['scheme'] === 'https') {
$scheme = 'ssl://'; $scheme = 'ssl://';
} }

View file

@ -1512,7 +1512,7 @@ class CakeEmail {
*/ */
protected function _getTypes() { protected function _getTypes() {
$types = array($this->_emailFormat); $types = array($this->_emailFormat);
if ($this->_emailFormat == 'both') { if ($this->_emailFormat === 'both') {
$types = array('html', 'text'); $types = array('html', 'text');
} }
return $types; return $types;

View file

@ -545,7 +545,7 @@ class HttpSocket extends CakeSocket {
if (is_array($port)) { if (is_array($port)) {
$port = $port[0]; $port = $port[0];
} }
if ($url{0} == '/') { if ($url{0} === '/') {
$url = $this->config['request']['uri']['host'] . ':' . $port . $url; $url = $this->config['request']['uri']['host'] . ':' . $port . $url;
} }
if (!preg_match('/^.+:\/\/|\*|^\//', $url)) { if (!preg_match('/^.+:\/\/|\*|^\//', $url)) {
@ -867,7 +867,7 @@ class HttpSocket extends CakeSocket {
if (is_string($request)) { if (is_string($request)) {
$isValid = preg_match("/(.+) (.+) (.+)\r\n/U", $request, $match); $isValid = preg_match("/(.+) (.+) (.+)\r\n/U", $request, $match);
if (!$this->quirksMode && (!$isValid || ($match[2] == '*' && !in_array($match[3], $asteriskMethods)))) { if (!$this->quirksMode && (!$isValid || ($match[2] === '*' && !in_array($match[3], $asteriskMethods)))) {
throw new SocketException(__d('cake_dev', 'HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.')); throw new SocketException(__d('cake_dev', 'HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.'));
} }
return $request; return $request;
@ -918,7 +918,7 @@ class HttpSocket extends CakeSocket {
$returnHeader = ''; $returnHeader = '';
foreach ($header as $field => $contents) { foreach ($header as $field => $contents) {
if (is_array($contents) && $mode == 'standard') { if (is_array($contents) && $mode === 'standard') {
$contents = implode(',', $contents); $contents = implode(',', $contents);
} }
foreach ((array)$contents as $content) { foreach ((array)$contents as $content) {

View file

@ -192,7 +192,9 @@ class Dispatcher implements CakeEventListener {
if ($render && $controller->autoRender) { if ($render && $controller->autoRender) {
$response = $controller->render(); $response = $controller->render();
} elseif ($response->body() === null) { } elseif (!($result instanceof CakeResponse) &&
$response->body() === null
) {
$response->body($result); $response->body($result);
} }
$controller->shutdownProcess(); $controller->shutdownProcess();

View file

@ -191,7 +191,7 @@ class Router {
*/ */
protected static function _validateRouteClass($routeClass) { protected static function _validateRouteClass($routeClass) {
if ( if (
$routeClass != 'CakeRoute' && $routeClass !== 'CakeRoute' &&
(!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute'))
) { ) {
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute')); throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
@ -332,7 +332,7 @@ class Router {
$routeClass = self::_validateRouteClass($routeClass); $routeClass = self::_validateRouteClass($routeClass);
unset($options['routeClass']); unset($options['routeClass']);
} }
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) { if ($routeClass === 'RedirectRoute' && isset($defaults['redirect'])) {
$defaults = $defaults['redirect']; $defaults = $defaults['redirect'];
} }
self::$routes[] = new $routeClass($route, $defaults, $options); self::$routes[] = new $routeClass($route, $defaults, $options);
@ -715,7 +715,7 @@ class Router {
return; return;
} }
foreach (self::$_initialState as $key => $val) { foreach (self::$_initialState as $key => $val) {
if ($key != '_initialState') { if ($key !== '_initialState') {
self::${$key} = $val; self::${$key} = $val;
} }
} }
@ -1001,7 +1001,7 @@ class Router {
$out .= $addition; $out .= $addition;
if (isset($out[0]) && $out[0] != '?') { if (isset($out[0]) && $out[0] !== '?') {
$out = '?' . $out; $out = '?' . $out;
} }
return $out; return $out;

View file

@ -767,7 +767,7 @@ EXPECTED;
'<div>this-is-a-test</div>' '<div>this-is-a-test</div>'
########################### ###########################
EXPECTED; EXPECTED;
if (php_sapi_name() == 'cli') { if (php_sapi_name() === 'cli') {
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17); $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else { } else {
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19); $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
@ -791,7 +791,7 @@ EXPECTED;
'<div>this-is-a-test</div>' '<div>this-is-a-test</div>'
########################### ###########################
EXPECTED; EXPECTED;
if (php_sapi_name() == 'cli') { if (php_sapi_name() === 'cli') {
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17); $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else { } else {
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19); $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);

View file

@ -228,7 +228,7 @@ class CacheTest extends CakeTestCase {
'duration' => 3600, 'duration' => 3600,
'probability' => 100, 'probability' => 100,
'engine' => 'File', 'engine' => 'File',
'isWindows' => DIRECTORY_SEPARATOR == '\\', 'isWindows' => DIRECTORY_SEPARATOR === '\\',
'mask' => 0664, 'mask' => 0664,
'groups' => array() 'groups' => array()
); );

View file

@ -412,7 +412,7 @@ class FileEngineTest extends CakeTestCase {
} }
/** /**
* Tests that deleteing from a groups-enabled config is possible * Tests that deleting from a groups-enabled config is possible
* *
* @return void * @return void
*/ */

View file

@ -504,12 +504,12 @@ class DbAclTest extends CakeTestCase {
$perms = ''; $perms = '';
foreach ($rights as $right) { foreach ($rights as $right) {
if ($this->Acl->check($aro, $aco, $right)) { if ($this->Acl->check($aro, $aco, $right)) {
if ($right == '*') { if ($right === '*') {
$perms .= '****'; $perms .= '****';
break; break;
} }
$perms .= $right[0]; $perms .= $right[0];
} elseif ($right != '*') { } elseif ($right !== '*') {
$perms .= ' '; $perms .= ' ';
} }
} }

View file

@ -165,11 +165,12 @@ class ActionsAuthorizeTest extends CakeTestCase {
*/ */
public function testActionNoDoubleSlash() { public function testActionNoDoubleSlash() {
$this->auth->settings['actionPath'] = '/controllers/'; $this->auth->settings['actionPath'] = '/controllers/';
$request = array( $request = new CakeRequest('/posts/index', false);
$request->addParams(array(
'plugin' => null, 'plugin' => null,
'controller' => 'posts', 'controller' => 'posts',
'action' => 'index' 'action' => 'index'
); ));
$result = $this->auth->action($request); $result = $this->auth->action($request);
$this->assertEquals('controllers/Posts/index', $result); $this->assertEquals('controllers/Posts/index', $result);
} }

View file

@ -453,6 +453,7 @@ class AuthComponentTest extends CakeTestCase {
$this->Controller->Auth->userModel = 'AuthUser'; $this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->authorize = false; $this->Controller->Auth->authorize = false;
$this->Controller->request->addParams(Router::parse('auth_test/add')); $this->Controller->request->addParams(Router::parse('auth_test/add'));
$this->Controller->Auth->initialize($this->Controller);
$result = $this->Controller->Auth->startup($this->Controller); $result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result); $this->assertTrue($result);

View file

@ -107,7 +107,7 @@ class PaginatorControllerPost extends CakeTestModel {
* @return void * @return void
*/ */
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) { public function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
if ($conditions == 'popular') { if ($conditions === 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1'); $conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
$options = Hash::merge($fields, compact('conditions')); $options = Hash::merge($fields, compact('conditions'));
return parent::find('all', $options); return parent::find('all', $options);
@ -278,7 +278,7 @@ class PaginatorCustomPost extends CakeTestModel {
* @return array * @return array
*/ */
protected function _findTotals($state, $query, $results = array()) { protected function _findTotals($state, $query, $results = array()) {
if ($state == 'before') { if ($state === 'before') {
$query['fields'] = array('author_id'); $query['fields'] = array('author_id');
$this->virtualFields['total_posts'] = "COUNT({$this->alias}.id)"; $this->virtualFields['total_posts'] = "COUNT({$this->alias}.id)";
$query['fields'][] = 'total_posts'; $query['fields'][] = 'total_posts';
@ -296,7 +296,7 @@ class PaginatorCustomPost extends CakeTestModel {
* @return array * @return array
*/ */
protected function _findTotalsOperation($state, $query, $results = array()) { protected function _findTotalsOperation($state, $query, $results = array()) {
if ($state == 'before') { if ($state === 'before') {
if (!empty($query['operation']) && $query['operation'] === 'count') { if (!empty($query['operation']) && $query['operation'] === 'count') {
unset($query['limit']); unset($query['limit']);
$query['recursive'] = -1; $query['recursive'] = -1;

View file

@ -103,7 +103,7 @@ class ControllerPost extends CakeTestModel {
* @return void * @return void
*/ */
public function find($type = 'first', $options = array()) { public function find($type = 'first', $options = array()) {
if ($type == 'popular') { if ($type === 'popular') {
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1'); $conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
$options = Hash::merge($options, compact('conditions')); $options = Hash::merge($options, compact('conditions'));
return parent::find('all', $options); return parent::find('all', $options);

View file

@ -424,6 +424,18 @@ class CakeLogTest extends CakeTestCase {
public function testScopedLogging() { public function testScopedLogging() {
$this->_resetLogConfig(); $this->_resetLogConfig();
$this->_deleteLogs(); $this->_deleteLogs();
CakeLog::config('string-scope', array(
'engine' => 'FileLog',
'types' => array('info', 'notice', 'warning'),
'scopes' => 'string-scope',
'file' => 'string-scope.log'
));
CakeLog::write('info', 'info message', 'string-scope');
$this->assertTrue(file_exists(LOGS . 'string-scope.log'));
CakeLog::drop('string-scope');
CakeLog::config('shops', array( CakeLog::config('shops', array(
'engine' => 'FileLog', 'engine' => 'FileLog',
'types' => array('info', 'notice', 'warning'), 'types' => array('info', 'notice', 'warning'),

View file

@ -124,7 +124,7 @@ class ConsoleLogTest extends CakeTestCase {
TestCakeLog::config('test_console_log', array( TestCakeLog::config('test_console_log', array(
'engine' => 'TestConsoleLog', 'engine' => 'TestConsoleLog',
)); ));
if (DS == '\\' && !(bool)env('ANSICON')) { if (DS === '\\' && !(bool)env('ANSICON')) {
$expected = ConsoleOutput::PLAIN; $expected = ConsoleOutput::PLAIN;
} else { } else {
$expected = ConsoleOutput::COLOR; $expected = ConsoleOutput::COLOR;

View file

@ -193,9 +193,9 @@ class DbAroUserTest extends CakeTestModel {
* @return void * @return void
*/ */
public function bindNode($ref = null) { public function bindNode($ref = null) {
if (Configure::read('DbAclbindMode') == 'string') { if (Configure::read('DbAclbindMode') === 'string') {
return 'ROOT/admins/Gandalf'; return 'ROOT/admins/Gandalf';
} elseif (Configure::read('DbAclbindMode') == 'array') { } elseif (Configure::read('DbAclbindMode') === 'array') {
return array('DbAroTest' => array('DbAroTest.model' => 'AuthUser', 'DbAroTest.foreign_key' => 2)); return array('DbAroTest' => array('DbAroTest.model' => 'AuthUser', 'DbAroTest.foreign_key' => 2));
} }
} }

View file

@ -61,7 +61,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function beforeFind(Model $model, $query) { public function beforeFind(Model $model, $query) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['beforeFind']) || $settings['beforeFind'] == 'off') { if (!isset($settings['beforeFind']) || $settings['beforeFind'] === 'off') {
return parent::beforeFind($model, $query); return parent::beforeFind($model, $query);
} }
switch ($settings['beforeFind']) { switch ($settings['beforeFind']) {
@ -86,7 +86,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function afterFind(Model $model, $results, $primary) { public function afterFind(Model $model, $results, $primary) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['afterFind']) || $settings['afterFind'] == 'off') { if (!isset($settings['afterFind']) || $settings['afterFind'] === 'off') {
return parent::afterFind($model, $results, $primary); return parent::afterFind($model, $results, $primary);
} }
switch ($settings['afterFind']) { switch ($settings['afterFind']) {
@ -109,7 +109,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function beforeSave(Model $model) { public function beforeSave(Model $model) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['beforeSave']) || $settings['beforeSave'] == 'off') { if (!isset($settings['beforeSave']) || $settings['beforeSave'] === 'off') {
return parent::beforeSave($model); return parent::beforeSave($model);
} }
switch ($settings['beforeSave']) { switch ($settings['beforeSave']) {
@ -132,7 +132,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function afterSave(Model $model, $created) { public function afterSave(Model $model, $created) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['afterSave']) || $settings['afterSave'] == 'off') { if (!isset($settings['afterSave']) || $settings['afterSave'] === 'off') {
return parent::afterSave($model, $created); return parent::afterSave($model, $created);
} }
$string = 'modified after'; $string = 'modified after';
@ -162,7 +162,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function beforeValidate(Model $model) { public function beforeValidate(Model $model) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['validate']) || $settings['validate'] == 'off') { if (!isset($settings['validate']) || $settings['validate'] === 'off') {
return parent::beforeValidate($model); return parent::beforeValidate($model);
} }
switch ($settings['validate']) { switch ($settings['validate']) {
@ -189,7 +189,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function afterValidate(Model $model) { public function afterValidate(Model $model) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['afterValidate']) || $settings['afterValidate'] == 'off') { if (!isset($settings['afterValidate']) || $settings['afterValidate'] === 'off') {
return parent::afterValidate($model); return parent::afterValidate($model);
} }
switch ($settings['afterValidate']) { switch ($settings['afterValidate']) {
@ -210,7 +210,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function beforeDelete(Model $model, $cascade = true) { public function beforeDelete(Model $model, $cascade = true) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') { if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] === 'off') {
return parent::beforeDelete($model, $cascade); return parent::beforeDelete($model, $cascade);
} }
switch ($settings['beforeDelete']) { switch ($settings['beforeDelete']) {
@ -235,7 +235,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function afterDelete(Model $model) { public function afterDelete(Model $model) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') { if (!isset($settings['afterDelete']) || $settings['afterDelete'] === 'off') {
return parent::afterDelete($model); return parent::afterDelete($model);
} }
switch ($settings['afterDelete']) { switch ($settings['afterDelete']) {
@ -253,7 +253,7 @@ class TestBehavior extends ModelBehavior {
*/ */
public function onError(Model $model, $error) { public function onError(Model $model, $error) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['onError']) || $settings['onError'] == 'off') { if (!isset($settings['onError']) || $settings['onError'] === 'off') {
return parent::onError($model, $error); return parent::onError($model, $error);
} }
echo "onError trigger success"; echo "onError trigger success";
@ -418,6 +418,39 @@ class Test7Behavior extends ModelBehavior{
class TestAliasBehavior extends TestBehavior { class TestAliasBehavior extends TestBehavior {
} }
/**
* FirstBehavior
*/
class FirstBehavior extends ModelBehavior {
public function beforeFind(Model $model, $query = array()) {
$model->called[] = get_class($this);
return $query;
}
}
/**
* SecondBehavior
*/
class SecondBehavior extends FirstBehavior {
}
/**
* ThirdBehavior
*/
class ThirdBehavior extends FirstBehavior {
}
/**
* Orangutan Model
*/
class Orangutan extends Monkey {
public $called = array();
}
/** /**
* BehaviorCollection class * BehaviorCollection class
* *
@ -432,7 +465,8 @@ class BehaviorCollectionTest extends CakeTestCase {
*/ */
public $fixtures = array( public $fixtures = array(
'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment', 'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment',
'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate' 'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate',
'core.device'
); );
/** /**
@ -489,14 +523,14 @@ class BehaviorCollectionTest extends CakeTestCase {
$this->assertEquals('testbehavior', strtolower(get_class($Apple->Behaviors->Test))); $this->assertEquals('testbehavior', strtolower(get_class($Apple->Behaviors->Test)));
$expected = array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value'); $expected = array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value');
$this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']); $this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']);
$this->assertEquals(array('Apple'), array_keys($Apple->Behaviors->Test->settings)); $this->assertEquals(array('priority', 'Apple'), array_keys($Apple->Behaviors->Test->settings));
$this->assertSame($Apple->Sample->Behaviors->loaded(), array()); $this->assertSame($Apple->Sample->Behaviors->loaded(), array());
$Apple->Sample->Behaviors->attach('Test', array('key2' => 'value2')); $Apple->Sample->Behaviors->attach('Test', array('key2' => 'value2'));
$this->assertSame($Apple->Sample->Behaviors->loaded(), array('Test')); $this->assertSame($Apple->Sample->Behaviors->loaded(), array('Test'));
$this->assertEquals(array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'), $Apple->Sample->Behaviors->Test->settings['Sample']); $this->assertEquals(array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'), $Apple->Sample->Behaviors->Test->settings['Sample']);
$this->assertEquals(array('Apple', 'Sample'), array_keys($Apple->Behaviors->Test->settings)); $this->assertEquals(array('priority', 'Apple', 'Sample'), array_keys($Apple->Behaviors->Test->settings));
$this->assertSame( $this->assertSame(
$Apple->Sample->Behaviors->Test->settings, $Apple->Sample->Behaviors->Test->settings,
$Apple->Behaviors->Test->settings $Apple->Behaviors->Test->settings
@ -1149,4 +1183,77 @@ class BehaviorCollectionTest extends CakeTestCase {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
/**
* Test that behavior priority
*/
public function testBehaviorOrderCallbacks() {
$model = ClassRegistry::init('Orangutan');
$model->Behaviors->init('Orangutan', array(
'Second' => array('priority' => 9),
'Third',
'First' => array('priority' => 8),
));
$this->assertEmpty($model->called);
$model->find('first');
$expected = array(
'FirstBehavior',
'SecondBehavior',
'ThirdBehavior',
);
$this->assertEquals($expected, $model->called);
$model->called = array();
$model->Behaviors->load('Third', array('priority' => 1));
$model->find('first');
$expected = array(
'ThirdBehavior',
'FirstBehavior',
'SecondBehavior'
);
$this->assertEquals($expected, $model->called);
$model->called = array();
$model->Behaviors->load('First');
$model->find('first');
$expected = array(
'ThirdBehavior',
'SecondBehavior',
'FirstBehavior'
);
$this->assertEquals($expected, $model->called);
$model->called = array();
$model->Behaviors->unload('Third');
$model->find('first');
$expected = array(
'SecondBehavior',
'FirstBehavior'
);
$this->assertEquals($expected, $model->called);
$model->called = array();
$model->Behaviors->disable('Second');
$model->find('first');
$expected = array(
'FirstBehavior'
);
$this->assertEquals($expected, $model->called);
$model->called = array();
$model->Behaviors->enable('Second');
$model->find('first');
$expected = array(
'SecondBehavior',
'FirstBehavior'
);
$this->assertEquals($expected, $model->called);
}
} }

View file

@ -1131,7 +1131,7 @@ class MysqlTest extends CakeTestCase {
$linkModel = $this->Model->Category2->{$assoc}; $linkModel = $this->Model->Category2->{$assoc};
$external = isset($assocData['external']); $external = isset($assocData['external']);
if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { if ($this->Model->Category2->alias == $linkModel->alias && $type !== 'hasAndBelongsToMany' && $type !== 'hasMany') {
$result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); $result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertFalse(empty($result)); $this->assertFalse(empty($result));
} else { } else {
@ -2984,6 +2984,7 @@ class MysqlTest extends CakeTestCase {
); );
$result = $this->Dbo->buildIndex($data); $result = $this->Dbo->buildIndex($data);
$expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)'); $expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)');
$this->assertEquals($expected, $result);
$data = array( $data = array(
'MyTextIndex' => array('column' => 'text_field', 'length' => array('text_field' => 20)) 'MyTextIndex' => array('column' => 'text_field', 'length' => array('text_field' => 20))

View file

@ -486,6 +486,18 @@ class PostgresTest extends CakeTestCase {
$this->assertEquals($data, $result['BinaryTest']['data']); $this->assertEquals($data, $result['BinaryTest']['data']);
} }
/**
* Tests passing PostgreSQL regular expression operators when building queries
*
* @return void
*/
public function testRegexpOperatorConditionsParsing() {
$this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
$this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
$this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
$this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
}
/** /**
* Tests the syntax of generated schema indexes * Tests the syntax of generated schema indexes
* *
@ -739,6 +751,25 @@ class PostgresTest extends CakeTestCase {
$this->Dbo->query($this->Dbo->dropSchema($schema1)); $this->Dbo->query($this->Dbo->dropSchema($schema1));
} }
/**
* Test the alterSchema RENAME statements
*
* @return void
*/
public function testAlterSchemaRenameTo() {
$query = $this->Dbo->alterSchema(array(
'posts' => array(
'change' => array(
'title' => array('name' => 'subject', 'type' => 'string', 'null' => false)
)
)
));
$this->assertContains('RENAME "title" TO "subject";', $query);
$this->assertContains('ALTER COLUMN "subject" TYPE', $query);
$this->assertNotContains(";\n\tALTER COLUMN \"subject\" TYPE", $query);
$this->assertNotContains('ALTER COLUMN "title" TYPE "subject"', $query);
}
/** /**
* Test it is possible to use virtual field with postgresql * Test it is possible to use virtual field with postgresql
* *
@ -922,6 +953,7 @@ class PostgresTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testNestedTransaction() { public function testNestedTransaction() {
$this->Dbo->useNestedTransactions = true;
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction'); $this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
$this->loadFixtures('Article'); $this->loadFixtures('Article');

View file

@ -2574,7 +2574,7 @@ class NumberTree extends CakeTestModel {
$this->create($data); $this->create($data);
if ($hierarchal) { if ($hierarchal) {
if ($this->name == 'UnconventionalTree') { if ($this->name === 'UnconventionalTree') {
$data[$this->name]['join'] = $parentId; $data[$this->name]['join'] = $parentId;
} else { } else {
$data[$this->name]['parent_id'] = $parentId; $data[$this->name]['parent_id'] = $parentId;

View file

@ -29,7 +29,7 @@ class TestCakeRequest extends CakeRequest {
if (empty($url)) { if (empty($url)) {
$url = $this->_url(); $url = $this->_url();
} }
if ($url[0] == '/') { if ($url[0] === '/') {
$url = substr($url, 1); $url = substr($url, 1);
} }
$this->url = $url; $this->url = $url;

View file

@ -87,6 +87,7 @@ class CakeSocketTest extends CakeTestCase {
$this->assertFalse($this->Socket->connected); $this->assertFalse($this->Socket->connected);
$this->Socket->disconnect(); $this->Socket->disconnect();
$this->assertFalse($this->Socket->connected); $this->assertFalse($this->Socket->connected);
try {
$this->Socket->connect(); $this->Socket->connect();
$this->assertTrue($this->Socket->connected); $this->assertTrue($this->Socket->connected);
$this->Socket->connect(); $this->Socket->connect();
@ -97,6 +98,9 @@ class CakeSocketTest extends CakeTestCase {
$this->Socket = new CakeSocket($config); $this->Socket = new CakeSocket($config);
$this->Socket->connect(); $this->Socket->connect();
$this->assertTrue($this->Socket->connected); $this->assertTrue($this->Socket->connected);
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**
@ -129,6 +133,7 @@ class CakeSocketTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testSocketHost() { public function testSocketHost() {
try {
$this->Socket = new CakeSocket(); $this->Socket = new CakeSocket();
$this->Socket->connect(); $this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address()); $this->assertEquals('127.0.0.1', $this->Socket->address());
@ -142,6 +147,9 @@ class CakeSocketTest extends CakeTestCase {
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host()); $this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertEquals(null, $this->Socket->lastError()); $this->assertEquals(null, $this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses())); $this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**
@ -150,8 +158,12 @@ class CakeSocketTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testSocketWriting() { public function testSocketWriting() {
try {
$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"; $request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
$this->assertTrue((bool)$this->Socket->write($request)); $this->assertTrue((bool)$this->Socket->write($request));
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**
@ -161,6 +173,7 @@ class CakeSocketTest extends CakeTestCase {
*/ */
public function testSocketReading() { public function testSocketReading() {
$this->Socket = new CakeSocket(array('timeout' => 5)); $this->Socket = new CakeSocket(array('timeout' => 5));
try {
$this->Socket->connect(); $this->Socket->connect();
$this->assertEquals(null, $this->Socket->read(26)); $this->assertEquals(null, $this->Socket->read(26));
@ -169,6 +182,9 @@ class CakeSocketTest extends CakeTestCase {
$this->assertTrue($this->Socket->connect()); $this->assertTrue($this->Socket->connect());
$this->assertEquals(null, $this->Socket->read(26)); $this->assertEquals(null, $this->Socket->read(26));
$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); $this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError());
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**
@ -179,12 +195,16 @@ class CakeSocketTest extends CakeTestCase {
public function testTimeOutConnection() { public function testTimeOutConnection() {
$config = array('host' => '127.0.0.1', 'timeout' => 0.5); $config = array('host' => '127.0.0.1', 'timeout' => 0.5);
$this->Socket = new CakeSocket($config); $this->Socket = new CakeSocket($config);
try {
$this->assertTrue($this->Socket->connect()); $this->assertTrue($this->Socket->connect());
$config = array('host' => '127.0.0.1', 'timeout' => 0.00001); $config = array('host' => '127.0.0.1', 'timeout' => 0.00001);
$this->Socket = new CakeSocket($config); $this->Socket = new CakeSocket($config);
$this->assertFalse($this->Socket->read(1024 * 1024)); $this->assertFalse($this->Socket->read(1024 * 1024));
$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); $this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError());
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**
@ -256,7 +276,11 @@ class CakeSocketTest extends CakeTestCase {
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); $this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
$configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5); $configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5);
$this->Socket = new CakeSocket($configSslTls); $this->Socket = new CakeSocket($configSslTls);
try {
$this->Socket->connect(); $this->Socket->connect();
} catch (SocketException $e) {
$this->markTestSkipped('Cannot test network, skipping.');
}
} }
/** /**

View file

@ -208,6 +208,16 @@ class SomePagesController extends AppController {
return new CakeResponse(array('body' => 'new response')); return new CakeResponse(array('body' => 'new response'));
} }
/**
* Test file sending
*
* @return CakeResponse
*/
public function sendfile() {
$this->response->file(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS . 'test_asset.css');
return $this->response;
}
} }
/** /**
@ -376,7 +386,7 @@ class SomePostsController extends AppController {
* @return void * @return void
*/ */
public function beforeFilter() { public function beforeFilter() {
if ($this->params['action'] == 'index') { if ($this->params['action'] === 'index') {
$this->params['action'] = 'view'; $this->params['action'] = 'view';
} else { } else {
$this->params['action'] = 'change'; $this->params['action'] = 'change';
@ -866,6 +876,40 @@ class DispatcherTest extends CakeTestCase {
$this->assertEquals('new response', $result); $this->assertEquals('new response', $result);
} }
/**
* testDispatchActionSendsFile
*
* @return void
*/
public function testDispatchActionSendsFile() {
Router::connect('/:controller/:action');
$Dispatcher = new Dispatcher();
$request = new CakeRequest('some_pages/sendfile');
$response = $this->getMock('CakeResponse', array(
'header',
'type',
'download',
'_sendHeader',
'_setContentType',
'_isActive',
'_clearBuffer',
'_flushBuffer'
));
$response->expects($this->never())
->method('body');
$response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
ob_start();
$Dispatcher->dispatch($request, $response);
$result = ob_get_clean();
$this->assertEquals("/* this is the test asset css file */\n", $result);
}
/** /**
* testAdminDispatch method * testAdminDispatch method
* *
@ -1666,7 +1710,7 @@ class DispatcherTest extends CakeTestCase {
*/ */
protected function _cachePath($here) { protected function _cachePath($here) {
$path = $here; $path = $here;
if ($here == '/') { if ($here === '/') {
$path = 'home'; $path = 'home';
} }
$path = strtolower(Inflector::slug($path)); $path = strtolower(Inflector::slug($path));

View file

@ -57,7 +57,7 @@ class RouterTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testFullBaseURL() { public function testFullBaseURL() {
$skip = PHP_SAPI == 'cli'; $skip = PHP_SAPI === 'cli';
if ($skip) { if ($skip) {
$this->markTestSkipped('Cannot validate base urls in CLI'); $this->markTestSkipped('Cannot validate base urls in CLI');
} }

View file

@ -303,7 +303,7 @@ class FileTest extends CakeTestCase {
*/ */
public function testPrepare() { public function testPrepare() {
$string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere"; $string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
if (DS == '\\') { if (DS === '\\') {
$expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n"; $expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
$expected .= "for\r\n\r\n\r\n\r\n\r\nhere"; $expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
} else { } else {

View file

@ -256,10 +256,27 @@ class SecurityTest extends CakeTestCase {
$result = Security::rijndael('', $key, 'encrypt'); $result = Security::rijndael('', $key, 'encrypt');
$this->assertEquals('', Security::rijndael($result, $key, 'decrypt')); $this->assertEquals('', Security::rijndael($result, $key, 'decrypt'));
$result = Security::rijndael($txt, $key = 'this is my key of over 32 chars, yes it is', 'encrypt'); $key = 'this is my key of over 32 chars, yes it is';
$result = Security::rijndael($txt, $key, 'encrypt');
$this->assertEquals($txt, Security::rijndael($result, $key, 'decrypt')); $this->assertEquals($txt, Security::rijndael($result, $key, 'decrypt'));
} }
/**
* Test that rijndael() can still decrypt values with a fixed iv.
*
* @return
*/
public function testRijndaelBackwardCompatibility() {
$this->skipIf(!function_exists('mcrypt_encrypt'));
$txt = 'The quick brown fox jumped over the lazy dog.';
$key = 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi';
// Encrypted before random iv
$value = base64_decode('1WPjnq96LMzLGwNgmudHF+cAIqVUN5DaUZEpf5tm1EzSgt5iYY9o3d66iRI/fKJLTlTVGsa8HzW0jDNitmVXoQ==');
$this->assertEquals($txt, Security::rijndael($value, $key, 'decrypt'));
}
/** /**
* testRijndaelInvalidOperation method * testRijndaelInvalidOperation method
* *

View file

@ -20,7 +20,7 @@
class TestAppCacheEngine extends CacheEngine { class TestAppCacheEngine extends CacheEngine {
public function write($key, $value, $duration) { public function write($key, $value, $duration) {
if ($key == 'fail') { if ($key === 'fail') {
return false; return false;
} }
} }

View file

@ -380,7 +380,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$tags = (string)$tags; $tags = (string)$tags;
} }
$i++; $i++;
if (is_string($tags) && $tags{0} == '<') { if (is_string($tags) && $tags{0} === '<') {
$tags = array(substr($tags, 1) => array()); $tags = array(substr($tags, 1) => array());
} elseif (is_string($tags)) { } elseif (is_string($tags)) {
$tagsTrimmed = preg_replace('/\s+/m', '', $tags); $tagsTrimmed = preg_replace('/\s+/m', '', $tags);
@ -388,7 +388,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') { if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') {
$prefix = array(null, null); $prefix = array(null, null);
if ($match[0] == '*/') { if ($match[0] === '*/') {
$prefix = array('Anything, ', '.*?'); $prefix = array('Anything, ', '.*?');
} }
$regex[] = array( $regex[] = array(

View file

@ -186,7 +186,7 @@ abstract class ControllerTestCase extends CakeTestCase {
* @throws BadMethodCallException when you call methods that don't exist. * @throws BadMethodCallException when you call methods that don't exist.
*/ */
public function __call($name, $arguments) { public function __call($name, $arguments) {
if ($name == 'testAction') { if ($name === 'testAction') {
return call_user_func_array(array($this, '_testAction'), $arguments); return call_user_func_array(array($this, '_testAction'), $arguments);
} }
throw new BadMethodCallException("Method '{$name}' does not exist."); throw new BadMethodCallException("Method '{$name}' does not exist.");
@ -226,7 +226,7 @@ abstract class ControllerTestCase extends CakeTestCase {
$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']); $_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
if (is_array($options['data'])) { if (is_array($options['data'])) {
if (strtoupper($options['method']) == 'GET') { if (strtoupper($options['method']) === 'GET') {
$_GET = $options['data']; $_GET = $options['data'];
$_POST = array(); $_POST = array();
} else { } else {
@ -263,7 +263,7 @@ abstract class ControllerTestCase extends CakeTestCase {
$this->generate($plugin . Inflector::camelize($request->params['controller'])); $this->generate($plugin . Inflector::camelize($request->params['controller']));
} }
$params = array(); $params = array();
if ($options['return'] == 'result') { if ($options['return'] === 'result') {
$params['return'] = 1; $params['return'] = 1;
$params['bare'] = 1; $params['bare'] = 1;
$params['requested'] = 1; $params['requested'] = 1;

View file

@ -157,14 +157,14 @@ HTML;
<script type="text/javascript"> <script type="text/javascript">
function coverage_show_hide(selector) { function coverage_show_hide(selector) {
var element = document.getElementById(selector); var element = document.getElementById(selector);
element.style.display = (element.style.display == 'none') ? '' : 'none'; element.style.display = (element.style.display === 'none') ? '' : 'none';
} }
function coverage_toggle_all() { function coverage_toggle_all() {
var divs = document.querySelectorAll('div.coverage-container'); var divs = document.querySelectorAll('div.coverage-container');
var i = divs.length; var i = divs.length;
while (i--) { while (i--) {
if (divs[i] && divs[i].className.indexOf('primary') == -1) { if (divs[i] && divs[i].className.indexOf('primary') == -1) {
divs[i].style.display = (divs[i].style.display == 'none') ? '' : 'none'; divs[i].style.display = (divs[i].style.display === 'none') ? '' : 'none';
} }
} }
} }
@ -183,7 +183,7 @@ HTML;
$filename = basename($filename); $filename = basename($filename);
list($file, $ext) = explode('.', $filename); list($file, $ext) = explode('.', $filename);
$display = in_array($file, $this->_testNames) ? 'block' : 'none'; $display = in_array($file, $this->_testNames) ? 'block' : 'none';
$primary = $display == 'block' ? 'primary' : ''; $primary = $display === 'block' ? 'primary' : '';
return <<<HTML return <<<HTML
<div class="coverage-container $primary" style="display:$display;"> <div class="coverage-container $primary" style="display:$display;">
<h4> <h4>

View file

@ -134,7 +134,7 @@ class CakeNumber {
return $size * pow(1024, $i + 1); return $size * pow(1024, $i + 1);
} }
if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, -1))) { if (substr($size, -1) === 'B' && ctype_digit(substr($size, 0, -1))) {
$size = substr($size, 0, -1); $size = substr($size, 0, -1);
return (int)$size; return (int)$size;
} }
@ -329,14 +329,14 @@ class CakeNumber {
} }
} }
$position = $options[$symbolKey . 'Position'] != 'after' ? 'before' : 'after'; $position = $options[$symbolKey . 'Position'] !== 'after' ? 'before' : 'after';
$options[$position] = $options[$symbolKey . 'Symbol']; $options[$position] = $options[$symbolKey . 'Symbol'];
$abs = abs($value); $abs = abs($value);
$result = self::format($abs, $options); $result = self::format($abs, $options);
if ($value < 0) { if ($value < 0) {
if ($options['negative'] == '()') { if ($options['negative'] === '()') {
$result = '(' . $result . ')'; $result = '(' . $result . ')';
} else { } else {
$result = $options['negative'] . $result; $result = $options['negative'] . $result;

View file

@ -165,7 +165,7 @@ class CakeTime {
break; break;
case 'c': case 'c':
$format = __dc('cake', 'd_t_fmt', 5); $format = __dc('cake', 'd_t_fmt', 5);
if ($format != 'd_t_fmt') { if ($format !== 'd_t_fmt') {
return self::convertSpecifiers($format, self::$_time); return self::convertSpecifiers($format, self::$_time);
} }
break; break;
@ -206,12 +206,12 @@ class CakeTime {
$format = __dc('cake', 'am_pm', 5); $format = __dc('cake', 'am_pm', 5);
if (is_array($format)) { if (is_array($format)) {
$meridiem = $format[$meridiem]; $meridiem = $format[$meridiem];
return ($specifier[1] == 'P') ? strtolower($meridiem) : strtoupper($meridiem); return ($specifier[1] === 'P') ? strtolower($meridiem) : strtoupper($meridiem);
} }
break; break;
case 'r': case 'r':
$complete = __dc('cake', 't_fmt_ampm', 5); $complete = __dc('cake', 't_fmt_ampm', 5);
if ($complete != 't_fmt_ampm') { if ($complete !== 't_fmt_ampm') {
return str_replace('%p', self::_translateSpecifier(array('%p', 'p')), $complete); return str_replace('%p', self::_translateSpecifier(array('%p', 'p')), $complete);
} }
break; break;
@ -225,13 +225,13 @@ class CakeTime {
return ($weekDay = date('w', self::$_time)) ? $weekDay : 7; return ($weekDay = date('w', self::$_time)) ? $weekDay : 7;
case 'x': case 'x':
$format = __dc('cake', 'd_fmt', 5); $format = __dc('cake', 'd_fmt', 5);
if ($format != 'd_fmt') { if ($format !== 'd_fmt') {
return self::convertSpecifiers($format, self::$_time); return self::convertSpecifiers($format, self::$_time);
} }
break; break;
case 'X': case 'X':
$format = __dc('cake', 't_fmt', 5); $format = __dc('cake', 't_fmt', 5);
if ($format != 't_fmt') { if ($format !== 't_fmt') {
return self::convertSpecifiers($format, self::$_time); return self::convertSpecifiers($format, self::$_time);
} }
break; break;

View file

@ -257,7 +257,7 @@ class Debugger {
); );
echo $self->outputError($data); echo $self->outputError($data);
if ($error == 'Fatal Error') { if ($error === 'Fatal Error') {
exit(); exit();
} }
return true; return true;
@ -326,9 +326,9 @@ class Debugger {
if (in_array($signature, $options['exclude'])) { if (in_array($signature, $options['exclude'])) {
continue; continue;
} }
if ($options['format'] == 'points' && $trace['file'] != '[internal]') { if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
$back[] = array('file' => $trace['file'], 'line' => $trace['line']); $back[] = array('file' => $trace['file'], 'line' => $trace['line']);
} elseif ($options['format'] == 'array') { } elseif ($options['format'] === 'array') {
$back[] = $trace; $back[] = $trace;
} else { } else {
if (isset($self->_templates[$options['format']]['traceLine'])) { if (isset($self->_templates[$options['format']]['traceLine'])) {
@ -343,7 +343,7 @@ class Debugger {
} }
} }
if ($options['format'] == 'array' || $options['format'] == 'points') { if ($options['format'] === 'array' || $options['format'] === 'points') {
return $back; return $back;
} }
return implode("\n", $back); return implode("\n", $back);
@ -847,7 +847,7 @@ class Debugger {
* @return void * @return void
*/ */
public static function checkSecurityKeys() { public static function checkSecurityKeys() {
if (Configure::read('Security.salt') == 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') { if (Configure::read('Security.salt') === 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') {
trigger_error(__d('cake_dev', 'Please change the value of \'Security.salt\' in app/Config/core.php to a salt value specific to your application'), E_USER_NOTICE); trigger_error(__d('cake_dev', 'Please change the value of \'Security.salt\' in app/Config/core.php to a salt value specific to your application'), E_USER_NOTICE);
} }

View file

@ -212,7 +212,7 @@ class File {
*/ */
public static function prepare($data, $forceWindows = false) { public static function prepare($data, $forceWindows = false) {
$lineBreak = "\n"; $lineBreak = "\n";
if (DIRECTORY_SEPARATOR == '\\' || $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));

View file

@ -267,7 +267,7 @@ class Folder {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::isWindowsPath * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::isWindowsPath
*/ */
public static function isWindowsPath($path) { public static function isWindowsPath($path) {
return (preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); return (preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) === '\\\\');
} }
/** /**
@ -278,7 +278,7 @@ class Folder {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::isAbsolute * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::isAbsolute
*/ */
public static function isAbsolute($path) { public static function isAbsolute($path) {
return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) === '\\\\');
} }
/** /**
@ -460,7 +460,7 @@ class Folder {
foreach ($iterator as $itemPath => $fsIterator) { foreach ($iterator as $itemPath => $fsIterator) {
if ($skipHidden) { if ($skipHidden) {
$subPathName = $fsIterator->getSubPathname(); $subPathName = $fsIterator->getSubPathname();
if ($subPathName{0} == '.' || strpos($subPathName, DS . '.') !== false) { if ($subPathName{0} === '.' || strpos($subPathName, DS . '.') !== false) {
continue; continue;
} }
} }

View file

@ -770,7 +770,7 @@ class Hash {
$dir = strtolower($dir); $dir = strtolower($dir);
$type = strtolower($type); $type = strtolower($type);
if ($type == 'natural' && version_compare(PHP_VERSION, '5.4.0', '<')) { if ($type === 'natural' && version_compare(PHP_VERSION, '5.4.0', '<')) {
$type = 'regular'; $type = 'regular';
} }
if ($dir === 'asc') { if ($dir === 'asc') {

View file

@ -271,7 +271,7 @@ class Inflector {
return; return;
} }
foreach (self::$_initialState as $key => $val) { foreach (self::$_initialState as $key => $val) {
if ($key != '_initialState') { if ($key !== '_initialState') {
self::${$key} = $val; self::${$key} = $val;
} }
} }

View file

@ -120,14 +120,14 @@ class Security {
$string = $salt . $string; $string = $salt . $string;
} }
if (!$type || $type == 'sha1') { if (!$type || $type === 'sha1') {
if (function_exists('sha1')) { if (function_exists('sha1')) {
return sha1($string); return sha1($string);
} }
$type = 'sha256'; $type = 'sha256';
} }
if ($type == 'sha256' && function_exists('mhash')) { if ($type === 'sha256' && function_exists('mhash')) {
return bin2hex(mhash(MHASH_SHA256, $string)); return bin2hex(mhash(MHASH_SHA256, $string));
} }
@ -198,8 +198,12 @@ class Security {
/** /**
* Encrypts/Decrypts a text using the given key using rijndael method. * Encrypts/Decrypts a text using the given key using rijndael method.
* *
* Prior to 2.3.1, a fixed initialization vector was used. This was not
* secure. This method now uses a random iv, and will silently upgrade values when
* they are re-encrypted.
*
* @param string $text Encrypted string to decrypt, normal string to encrypt * @param string $text Encrypted string to decrypt, normal string to encrypt
* @param string $key Key to use * @param string $key Key to use as the encryption key for encrypted data.
* @param string $operation Operation to perform, encrypt or decrypt * @param string $operation Operation to perform, encrypt or decrypt
* @return string Encrypted/Descrypted string * @return string Encrypted/Descrypted string
*/ */
@ -216,14 +220,23 @@ class Security {
trigger_error(__d('cake_dev', 'You must use a key larger than 32 bytes for Security::rijndael()'), E_USER_WARNING); trigger_error(__d('cake_dev', 'You must use a key larger than 32 bytes for Security::rijndael()'), E_USER_WARNING);
return ''; return '';
} }
$algorithm = 'rijndael-256'; $algorithm = MCRYPT_RIJNDAEL_256;
$mode = 'cbc'; $mode = MCRYPT_MODE_CBC;
$ivSize = mcrypt_get_iv_size($algorithm, $mode);
$cryptKey = substr($key, 0, 32); $cryptKey = substr($key, 0, 32);
$iv = substr($key, strlen($key) - 32, 32);
if ($operation === 'encrypt') { if ($operation === 'encrypt') {
return mcrypt_encrypt($algorithm, $cryptKey, $text, $mode, $iv); $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
return $iv . '$$' . mcrypt_encrypt($algorithm, $cryptKey, $text, $mode, $iv);
} }
// Backwards compatible decrypt with fixed iv
if (substr($text, $ivSize, 2) !== '$$') {
$iv = substr($key, strlen($key) - 32, 32);
return rtrim(mcrypt_decrypt($algorithm, $cryptKey, $text, $mode, $iv), "\0");
}
$iv = substr($text, 0, $ivSize);
$text = substr($text, $ivSize + 2);
return rtrim(mcrypt_decrypt($algorithm, $cryptKey, $text, $mode, $iv), "\0"); return rtrim(mcrypt_decrypt($algorithm, $cryptKey, $text, $mode, $iv), "\0");
} }

View file

@ -477,7 +477,7 @@ class String {
); );
if (isset($options['ending'])) { if (isset($options['ending'])) {
$default['ellipsis'] = $options['ending']; $default['ellipsis'] = $options['ending'];
} elseif (!empty($options['html']) && Configure::read('App.encoding') == 'UTF-8') { } elseif (!empty($options['html']) && Configure::read('App.encoding') === 'UTF-8') {
$default['ellipsis'] = "\xe2\x80\xa6"; $default['ellipsis'] = "\xe2\x80\xa6";
} }
$options = array_merge($default, $options); $options = array_merge($default, $options);

View file

@ -182,7 +182,7 @@ class Validation {
return self::luhn($check, $deep); return self::luhn($check, $deep);
} }
} }
} elseif ($type == 'all') { } elseif ($type === 'all') {
foreach ($cards['all'] as $value) { foreach ($cards['all'] as $value) {
$regex = $value; $regex = $value;
@ -533,7 +533,7 @@ class Validation {
*/ */
public static function money($check, $symbolPosition = 'left') { public static function money($check, $symbolPosition = 'left') {
$money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?'; $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?';
if ($symbolPosition == 'right') { if ($symbolPosition === 'right') {
$regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u'; $regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u';
} else { } else {
$regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u'; $regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u';

View file

@ -102,12 +102,16 @@ class Xml {
} elseif (file_exists($input)) { } elseif (file_exists($input)) {
return self::_loadXml(file_get_contents($input), $options); return self::_loadXml(file_get_contents($input), $options);
} elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) { } elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
try {
$socket = new HttpSocket(array('request' => array('redirect' => 10))); $socket = new HttpSocket(array('request' => array('redirect' => 10)));
$response = $socket->get($input); $response = $socket->get($input);
if (!$response->isOk()) { if (!$response->isOk()) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.')); throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
} }
return self::_loadXml($response->body, $options); return self::_loadXml($response->body, $options);
} catch (SocketException $e) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
}
} elseif (!is_string($input)) { } elseif (!is_string($input)) {
throw new XmlException(__d('cake_dev', 'Invalid input.')); throw new XmlException(__d('cake_dev', 'Invalid input.'));
} }

View file

@ -69,7 +69,7 @@ App::uses('Debugger', 'Utility');
<script type="text/javascript"> <script type="text/javascript">
function traceToggle(event, id) { function traceToggle(event, id) {
var el = document.getElementById(id); var el = document.getElementById(id);
el.style.display = (el.style.display == 'block') ? 'none' : 'block'; el.style.display = (el.style.display === 'block') ? 'none' : 'block';
event.preventDefault(); event.preventDefault();
return false; return false;
} }

View file

@ -355,7 +355,7 @@ class Helper extends Object {
/** /**
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in * Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force' * Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp === 'force'
* a timestamp will be added. * a timestamp will be added.
* *
* @param string $path The file path to timestamp, the path must be inside WWW_ROOT * @param string $path The file path to timestamp, the path must be inside WWW_ROOT

View file

@ -127,7 +127,7 @@ class CacheHelper extends AppHelper {
} }
} }
if (!isset($index) && $this->request->params['action'] == 'index') { if (!isset($index) && $this->request->params['action'] === 'index') {
$index = 'index'; $index = 'index';
} }

View file

@ -793,7 +793,7 @@ class FormHelper extends AppHelper {
} else { } else {
$text = $fieldName; $text = $fieldName;
} }
if (substr($text, -3) == '_id') { if (substr($text, -3) === '_id') {
$text = substr($text, 0, -3); $text = substr($text, 0, -3);
} }
$text = __(Inflector::humanize(Inflector::underscore($text))); $text = __(Inflector::humanize(Inflector::underscore($text)));
@ -993,7 +993,7 @@ class FormHelper extends AppHelper {
unset($options['type'], $options['before'], $options['between'], $options['after'], $options['format']); unset($options['type'], $options['before'], $options['between'], $options['after'], $options['format']);
$out['error'] = null; $out['error'] = null;
if ($type != 'hidden' && $error !== false) { if ($type !== 'hidden' && $error !== false) {
$errMsg = $this->error($fieldName, $error); $errMsg = $this->error($fieldName, $error);
if ($errMsg) { if ($errMsg) {
$divOptions = $this->addClass($divOptions, 'error'); $divOptions = $this->addClass($divOptions, 'error');
@ -1192,13 +1192,13 @@ class FormHelper extends AppHelper {
* @return array * @return array
*/ */
protected function _getFormat($options) { protected function _getFormat($options) {
if ($options['type'] == 'hidden') { if ($options['type'] === 'hidden') {
return array('input'); return array('input');
} }
if (is_array($options['format']) && in_array('input', $options['format'])) { if (is_array($options['format']) && in_array('input', $options['format'])) {
return $options['format']; return $options['format'];
} }
if ($options['type'] == 'checkbox') { if ($options['type'] === 'checkbox') {
return array('before', 'input', 'between', 'label', 'after', 'error'); return array('before', 'input', 'between', 'label', 'after', 'error');
} }
return array('before', 'label', 'between', 'input', 'after', 'error'); return array('before', 'label', 'between', 'input', 'after', 'error');
@ -1246,7 +1246,7 @@ class FormHelper extends AppHelper {
) { ) {
$options['maxlength'] = $fieldDef['length']; $options['maxlength'] = $fieldDef['length'];
} }
if ($autoLength && $fieldDef['type'] == 'float') { if ($autoLength && $fieldDef['type'] === 'float') {
$options['maxlength'] = array_sum(explode(',', $fieldDef['length'])) + 1; $options['maxlength'] = array_sum(explode(',', $fieldDef['length'])) + 1;
} }
return $options; return $options;
@ -2053,7 +2053,7 @@ class FormHelper extends AppHelper {
) )
)); ));
$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend'; $template = ($style === 'checkbox') ? 'checkboxmultipleend' : 'selectend';
$select[] = $this->Html->useTag($template); $select[] = $this->Html->useTag($template);
return implode("\n", $select); return implode("\n", $select);
} }
@ -2503,14 +2503,14 @@ class FormHelper extends AppHelper {
if (!empty($timeFormat)) { if (!empty($timeFormat)) {
$time = explode(':', $days[1]); $time = explode(':', $days[1]);
if ($time[0] >= '12' && $timeFormat == '12') { if ($time[0] >= '12' && $timeFormat === '12') {
$meridian = 'pm'; $meridian = 'pm';
} elseif ($time[0] == '00' && $timeFormat == '12') { } elseif ($time[0] === '00' && $timeFormat === '12') {
$time[0] = 12; $time[0] = 12;
} elseif ($time[0] >= 12) { } elseif ($time[0] >= 12) {
$meridian = 'pm'; $meridian = 'pm';
} }
if ($time[0] == 0 && $timeFormat == '12') { if ($time[0] == 0 && $timeFormat === '12') {
$time[0] = 12; $time[0] = 12;
} }
$hour = $min = null; $hour = $min = null;
@ -2531,7 +2531,7 @@ class FormHelper extends AppHelper {
* @return array * @return array
*/ */
protected function _name($options = array(), $field = null, $key = 'name') { protected function _name($options = array(), $field = null, $key = 'name') {
if ($this->requestType == 'get') { if ($this->requestType === 'get') {
if ($options === null) { if ($options === null) {
$options = array(); $options = array();
} elseif (is_string($options)) { } elseif (is_string($options)) {
@ -2767,7 +2767,7 @@ class FormHelper extends AppHelper {
for ($i = $min; $i <= $max; $i++) { for ($i = $min; $i <= $max; $i++) {
$data[$i] = $i; $data[$i] = $i;
} }
if ($options['order'] != 'asc') { if ($options['order'] !== 'asc') {
$data = array_reverse($data, true); $data = array_reverse($data, true);
} }
break; break;

Some files were not shown because too many files have changed in this diff Show more