Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.3' into currency

  • Loading branch information...
commit 22311a1e62934da757d53d7aecfce884f5a1ca10 2 parents fda331e + d051b69
@ceeram ceeram authored
Showing with 1,211 additions and 779 deletions.
  1. +18 −18 app/Config/acl.php
  2. +1 −1  app/Config/bootstrap.php
  3. +2 −2 app/Config/core.php
  4. +1 −1  app/Config/routes.php
  5. +13 −14 app/Console/cake
  6. +2 −3 lib/Cake/Cache/Engine/ApcEngine.php
  7. +6 −1 lib/Cake/Configure/IniReader.php
  8. +1 −1  lib/Cake/Console/Command/AclShell.php
  9. +5 −4 lib/Cake/Console/Command/ApiShell.php
  10. +7 −7 lib/Cake/Console/Command/ConsoleShell.php
  11. +3 −3 lib/Cake/Console/Command/Task/ControllerTask.php
  12. +13 −17 lib/Cake/Console/Command/Task/DbConfigTask.php
  13. +4 −4 lib/Cake/Console/Command/Task/ExtractTask.php
  14. +10 −13 lib/Cake/Console/Command/Task/ModelTask.php
  15. +4 −7 lib/Cake/Console/Command/Task/ProjectTask.php
  16. +2 −2 lib/Cake/Console/Command/Task/TemplateTask.php
  17. +4 −3 lib/Cake/Console/Command/Task/TestTask.php
  18. +2 −2 lib/Cake/Console/Command/Task/ViewTask.php
  19. +1 −1  lib/Cake/Console/ConsoleErrorHandler.php
  20. +5 −5 lib/Cake/Console/Shell.php
  21. +2 −2 lib/Cake/Console/Templates/skel/Config/bootstrap.php
  22. +18 −14 lib/Cake/Console/Templates/skel/Console/cake
  23. +12 −8 lib/Cake/Console/cake
  24. +1 −1  lib/Cake/Controller/Component/Acl/IniAcl.php
  25. +2 −2 lib/Cake/Controller/Component/Acl/PhpAcl.php
  26. +2 −2 lib/Cake/Controller/Component/CookieComponent.php
  27. +1 −1  lib/Cake/Controller/Component/EmailComponent.php
  28. +2 −2 lib/Cake/Controller/Component/SecurityComponent.php
  29. +12 −11 lib/Cake/Controller/Controller.php
  30. +1 −1  lib/Cake/Controller/Scaffold.php
  31. +1 −1  lib/Cake/Core/App.php
  32. +2 −2 lib/Cake/Core/Configure.php
  33. +0 −1  lib/Cake/Error/ErrorHandler.php
  34. +2 −2 lib/Cake/Error/ExceptionRenderer.php
  35. +1 −8 lib/Cake/I18n/I18n.php
  36. +0 −255 lib/Cake/I18n/Multibyte.php
  37. +24 −15 lib/Cake/Log/CakeLog.php
  38. +11 −7 lib/Cake/Model/Behavior/ContainableBehavior.php
  39. +1 −1  lib/Cake/Model/Behavior/TranslateBehavior.php
  40. +8 −10 lib/Cake/Model/Behavior/TreeBehavior.php
  41. +3 −3 lib/Cake/Model/Datasource/CakeSession.php
  42. +29 −11 lib/Cake/Model/Datasource/Database/Mysql.php
  43. +14 −11 lib/Cake/Model/Datasource/Database/Postgres.php
  44. +9 −9 lib/Cake/Model/Datasource/Database/Sqlite.php
  45. +3 −3 lib/Cake/Model/Datasource/Database/Sqlserver.php
  46. +14 −15 lib/Cake/Model/Datasource/DboSource.php
  47. +14 −15 lib/Cake/Model/Model.php
  48. +5 −5 lib/Cake/Model/Permission.php
  49. +1 −1  lib/Cake/Model/Validator/CakeValidationSet.php
  50. +7 −5 lib/Cake/Network/CakeRequest.php
  51. +1 −1  lib/Cake/Network/CakeResponse.php
  52. +2 −2 lib/Cake/Network/CakeSocket.php
  53. +2 −2 lib/Cake/Network/Http/HttpResponse.php
  54. +1 −1  lib/Cake/Network/Http/HttpSocket.php
  55. +1 −1  lib/Cake/Routing/Route/RedirectRoute.php
  56. +3 −3 lib/Cake/Routing/Router.php
  57. +12 −0 lib/Cake/Test/Case/BasicsTest.php
  58. +0 −1  lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
  59. +1 −0  lib/Cake/Test/Case/Configure/IniReaderTest.php
  60. +6 −6 lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php
  61. +4 −4 lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php
  62. +9 −9 lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php
  63. +14 −4 lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
  64. +1 −1  lib/Cake/Test/Case/Core/AppTest.php
  65. +16 −6 lib/Cake/Test/Case/Event/CakeEventManagerTest.php
  66. +40 −17 lib/Cake/Test/Case/Log/CakeLogTest.php
  67. +13 −0 lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
  68. +30 −2 lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
  69. +32 −0 lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php
  70. +75 −1 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
  71. +18 −3 lib/Cake/Test/Case/Model/ModelReadTest.php
  72. +73 −2 lib/Cake/Test/Case/Model/ModelWriteTest.php
  73. +45 −3 lib/Cake/Test/Case/Network/CakeRequestTest.php
  74. +2 −2 lib/Cake/Test/Case/Network/CakeResponseTest.php
  75. +1 −1  lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
  76. +6 −6 lib/Cake/Test/Case/Routing/DispatcherTest.php
  77. +11 −11 lib/Cake/Test/Case/Utility/CakeTimeTest.php
  78. +7 −0 lib/Cake/Test/Case/Utility/DebuggerTest.php
  79. +2 −0  lib/Cake/Test/Case/Utility/InflectorTest.php
  80. +16 −23 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  81. +32 −0 lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
  82. +69 −43 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
  83. +2 −2 lib/Cake/Test/Case/View/MediaViewTest.php
  84. +1 −1  lib/Cake/Test/test_app/Vendor/css/test_asset.css
  85. +1 −1  lib/Cake/Test/test_app/View/Themed/TestTheme/webroot/css/test_asset.css
  86. +1 −1  lib/Cake/Test/test_app/webroot/theme/test_theme/css/theme_webroot.css
  87. +1 −1  lib/Cake/Test/test_app/webroot/theme/test_theme/css/webroot_test.css
  88. +2 −0  lib/Cake/TestSuite/CakeTestRunner.php
  89. +1 −1  lib/Cake/TestSuite/CakeTestSuiteCommand.php
  90. +1 −1  lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
  91. +8 −2 lib/Cake/TestSuite/Fixture/CakeTestFixture.php
  92. +3 −3 lib/Cake/TestSuite/Reporter/CakeTextReporter.php
  93. +2 −2 lib/Cake/Utility/CakeNumber.php
  94. +4 −4 lib/Cake/Utility/CakeTime.php
  95. +1 −1  lib/Cake/Utility/Debugger.php
  96. +3 −3 lib/Cake/Utility/File.php
  97. +1 −1  lib/Cake/Utility/Folder.php
  98. +2 −1  lib/Cake/Utility/Inflector.php
  99. +1 −1  lib/Cake/Utility/Security.php
  100. +4 −4 lib/Cake/Utility/Set.php
  101. +1 −1  lib/Cake/Utility/String.php
  102. +2 −2 lib/Cake/Utility/Validation.php
  103. +4 −5 lib/Cake/View/Helper.php
  104. +3 −3 lib/Cake/View/Helper/CacheHelper.php
  105. +13 −10 lib/Cake/View/Helper/FormHelper.php
  106. +7 −8 lib/Cake/View/Helper/HtmlHelper.php
  107. +1 −1  lib/Cake/View/Helper/JsHelper.php
  108. +17 −12 lib/Cake/View/Helper/PaginatorHelper.php
  109. +1 −1  lib/Cake/View/Helper/RssHelper.php
  110. +1 −1  lib/Cake/View/Helper/SessionHelper.php
  111. +1 −1  lib/Cake/View/Helper/TextHelper.php
  112. +2 −2 lib/Cake/View/View.php
  113. +5 −10 lib/Cake/basics.php
  114. +263 −4 lib/Cake/bootstrap.php
View
36 app/Config/acl.php
@@ -22,18 +22,18 @@
/**
* Example
* -------
- *
+ *
* Assumptions:
*
- * 1. In your application you created a User model with the following properties:
+ * 1. In your application you created a User model with the following properties:
* username, group_id, password, email, firstname, lastname and so on.
- * 2. You configured AuthComponent to authorize actions via
- * $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...)
- *
+ * 2. You configured AuthComponent to authorize actions via
+ * $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...)
+ *
* Now, when a user (i.e. jeff) authenticates successfully and requests a controller action (i.e. /invoices/delete)
- * that is not allowed by default (e.g. via $this->Auth->allow('edit') in the Invoices controller) then AuthComponent
- * will ask the configured ACL interface if access is granted. Under the assumptions 1. and 2. this will be
- * done via a call to Acl->check() with
+ * that is not allowed by default (e.g. via $this->Auth->allow('edit') in the Invoices controller) then AuthComponent
+ * will ask the configured ACL interface if access is granted. Under the assumptions 1. and 2. this will be
+ * done via a call to Acl->check() with
*
* array('User' => array('username' => 'jeff', 'group_id' => 4, ...))
*
@@ -42,7 +42,7 @@
* '/controllers/invoices/delete'
*
* as ACO.
- *
+ *
* If the configured map looks like
*
* $config['map'] = array(
@@ -50,17 +50,17 @@
* 'Role' => 'User/group_id',
* );
*
- * then PhpAcl will lookup if we defined a role like User/jeff. If that role is not found, PhpAcl will try to
- * find a definition for Role/4. If the definition isn't found then a default role (Role/default) will be used to
+ * then PhpAcl will lookup if we defined a role like User/jeff. If that role is not found, PhpAcl will try to
+ * find a definition for Role/4. If the definition isn't found then a default role (Role/default) will be used to
* check rules for the given ACO. The search can be expanded by defining aliases in the alias configuration.
* E.g. if you want to use a more readable name than Role/4 in your definitions you can define an alias like
*
* $config['alias'] = array(
* 'Role/4' => 'Role/editor',
* );
- *
+ *
* In the roles configuration you can define roles on the lhs and inherited roles on the rhs:
- *
+ *
* $config['roles'] = array(
* 'Role/admin' => null,
* 'Role/accountant' => null,
@@ -68,7 +68,7 @@
* 'Role/manager' => 'Role/editor, Role/accountant',
* 'User/jeff' => 'Role/manager',
* );
- *
+ *
* In this example manager inherits all rules from editor and accountant. Role/admin doesn't inherit from any role.
* Lets define some rules:
*
@@ -87,10 +87,10 @@
* ),
* );
*
- * Ok, so as jeff inherits from Role/manager he's matched every rule that references User/jeff, Role/manager,
- * Role/editor, Role/accountant and Role/default. However, for jeff, rules for User/jeff are more specific than
+ * Ok, so as jeff inherits from Role/manager he's matched every rule that references User/jeff, Role/manager,
+ * Role/editor, Role/accountant and Role/default. However, for jeff, rules for User/jeff are more specific than
* rules for Role/manager, rules for Role/manager are more specific than rules for Role/editor and so on.
- * This is important when allow and deny rules match for a role. E.g. Role/accountant is allowed
+ * This is important when allow and deny rules match for a role. E.g. Role/accountant is allowed
* controllers/invoices/* but at the same time controllers/invoices/delete is denied. But there is a more
* specific rule defined for Role/manager which is allowed controllers/invoices/delete. However, the most specific
* rule denies access to the delete action explicitly for User/jeff, so he'll be denied access to the resource.
@@ -101,7 +101,7 @@
/**
* The role map defines how to resolve the user record from your application
- * to the roles you defined in the roles configuration.
+ * to the roles you defined in the roles configuration.
*/
$config['map'] = array(
'User' => 'User/username',
View
2  app/Config/bootstrap.php
@@ -2,7 +2,7 @@
/**
* This file is loaded automatically by the app/webroot/index.php file after core.php
*
- * This file should load/create any application wide configuration settings, such as
+ * This file should load/create any application wide configuration settings, such as
* Caching, Logging, loading additional configuration files.
*
* You should also use this file to include any files that provide global functions/constants
View
4 app/Config/core.php
@@ -226,7 +226,7 @@
Configure::write('Acl.database', 'default');
/**
- * Uncomment this line and correct your server timezone to fix
+ * Uncomment this line and correct your server timezone to fix
* any date & time related errors.
*/
//date_default_timezone_set('UTC');
@@ -238,7 +238,7 @@
* By default File is used, but for improved performance you should use APC.
*
* Note: 'default' and other application caches should be configured in app/Config/bootstrap.php.
- * Please check the comments in boostrap.php for more info on the cache engines available
+ * Please check the comments in boostrap.php for more info on the cache engines available
* and their setttings.
*/
$engine = 'File';
View
2  app/Config/routes.php
@@ -32,7 +32,7 @@
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
- * Load all plugin routes. See the CakePlugin documentation on
+ * Load all plugin routes. See the CakePlugin documentation on
* how to customize the loading of plugin routes.
*/
CakePlugin::routes();
View
27 app/Console/cake
@@ -17,22 +17,21 @@
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
################################################################################
-if [[ `uname` =~ 'Darwin' ]]; then
- ME=$0
-else
- ME=$(readlink -f $0)
-fi
-LIB=$(cd -P -- "$(dirname -- "$ME")" && pwd -P) && LIB=$LIB/$(basename -- "$ME")
-while [ -h "$LIB" ]; do
- DIR=$(dirname -- "$LIB")
- SYM=$(readlink "$LIB")
- LIB=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
-done
+# Canonicalize by following every symlink of the given name recursively
+canonicalize() {
+ NAME=$1
+ while [ -h "$NAME" ]; do
+ DIR=$(dirname -- "$NAME")
+ SYM=$(readlink "$NAME")
+ NAME=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+ echo "$NAME"
+}
-LIB=$(dirname -- "$LIB")/
-APP=$(dirname $(cd $(dirname $ME) && pwd))
+CONSOLE=$(dirname $(canonicalize "$0"))
+APP=$(dirname "$CONSOLE")
-exec php -q "$LIB"cake.php -working "$APP" "$@"
+exec php -q $CONSOLE/cake.php -working "$APP" "$@"
exit;
View
5 lib/Cake/Cache/Engine/ApcEngine.php
@@ -61,9 +61,8 @@ public function init($settings = array()) {
* @return boolean True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
- if ($duration == 0) {
- $expires = 0;
- } else {
+ $expires = 0;
+ if ($duration) {
$expires = time() + $duration;
}
apc_store($key . '_expires', $expires, $duration);
View
7 lib/Cake/Configure/IniReader.php
@@ -173,8 +173,10 @@ protected function _parseNestedValues($values) {
public function dump($filename, $data) {
$result = array();
foreach ($data as $key => $value) {
+ $isSection = false;
if ($key[0] != '[') {
$result[] = "[$key]";
+ $isSection = true;
}
if (is_array($value)) {
$keyValues = Hash::flatten($value, '.');
@@ -182,8 +184,11 @@ public function dump($filename, $data) {
$result[] = "$k = " . $this->_value($v);
}
}
+ if ($isSection) {
+ $result[] = '';
+ }
}
- $contents = implode("\n", $result);
+ $contents = trim(implode("\n", $result));
if (substr($filename, -4) !== '.ini') {
$filename .= '.ini';
View
2  lib/Cake/Console/Command/AclShell.php
@@ -598,7 +598,7 @@ protected function _getParams() {
* @return array Variables
*/
protected function _dataVars($type = null) {
- if ($type == null) {
+ if (!$type) {
$type = $this->args[0];
}
$vars = array();
View
9 lib/Cake/Console/Command/ApiShell.php
@@ -73,12 +73,13 @@ public function main() {
$path = $this->paths['core'];
}
- if (count($this->args) == 1) {
- $file = $type;
- $class = Inflector::camelize($type);
- } elseif (count($this->args) > 1) {
+ $count = count($this->args);
+ if ($count > 1) {
$file = Inflector::underscore($this->args[1]);
$class = Inflector::camelize($this->args[1]);
+ } elseif ($count) {
+ $file = $type;
+ $class = Inflector::camelize($type);
}
$objects = App::objects('class', $path);
if (in_array($class, $objects)) {
View
14 lib/Cake/Console/Command/ConsoleShell.php
@@ -182,7 +182,7 @@ public function main($command = null) {
$this->out(" - {$model}");
}
break;
- case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true):
+ case preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) {
$data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $data);
@@ -200,7 +200,7 @@ public function main($command = null) {
$this->out(__d('cake_console', "Please verify you are using valid models and association types"));
}
break;
- case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true):
+ case preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) {
$data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $data);
@@ -298,7 +298,7 @@ public function main($command = null) {
$this->out(__d('cake_console', 'Saved record for %s', $modelToSave));
}
break;
- case (preg_match("/^(\w+) columns/", $command, $tmp) == true):
+ case preg_match("/^(\w+) columns/", $command, $tmp):
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
if ($this->_isValidModel($modelToCheck)) {
@@ -315,22 +315,22 @@ public function main($command = null) {
$this->out(__d('cake_console', "Please verify that you selected a valid model"));
}
break;
- case (preg_match("/^routes\s+reload/i", $command, $tmp) == true):
+ case preg_match("/^routes\s+reload/i", $command, $tmp):
if (!$this->_loadRoutes()) {
$this->err(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors."));
break;
}
$this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes)));
break;
- case (preg_match("/^routes\s+show/i", $command, $tmp) == true):
+ case preg_match("/^routes\s+show/i", $command, $tmp):
$this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true));
break;
- case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true):
+ case preg_match("/^route\s+(\(.*\))$/i", $command, $tmp):
if ($url = eval('return array' . $tmp[1] . ';')) {
$this->out(Router::url($url));
}
break;
- case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true):
+ case preg_match("/^route\s+(.*)/i", $command, $tmp):
$this->out(var_export(Router::parse($tmp[1]), true));
break;
default:
View
6 lib/Cake/Console/Command/Task/ControllerTask.php
@@ -395,7 +395,7 @@ public function listAll($useDbConfig = null) {
}
$this->__tables = $this->Model->getAllTables($useDbConfig);
- if ($this->interactive == true) {
+ if ($this->interactive) {
$this->out(__d('cake_console', 'Possible Controllers based on your current database:'));
$this->hr();
$this->_controllerNames = array();
@@ -419,14 +419,14 @@ public function getName($useDbConfig = null) {
$controllers = $this->listAll($useDbConfig);
$enteredController = '';
- while ($enteredController == '') {
+ while (!$enteredController) {
$enteredController = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
if ($enteredController === 'q') {
$this->out(__d('cake_console', 'Exit'));
return $this->_stop();
}
- if ($enteredController == '' || intval($enteredController) > count($controllers)) {
+ if (!$enteredController || intval($enteredController) > count($controllers)) {
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
$enteredController = '';
}
View
30 lib/Cake/Console/Command/Task/DbConfigTask.php
@@ -92,10 +92,10 @@ protected function _interactive() {
$done = false;
$dbConfigs = array();
- while ($done == false) {
+ while (!$done) {
$name = '';
- while ($name == '') {
+ while (!$name) {
$name = $this->in(__d('cake_console', "Name:"), null, 'default');
if (preg_match('/[^a-z0-9_]/i', $name)) {
$name = '';
@@ -116,12 +116,12 @@ protected function _interactive() {
}
$host = '';
- while ($host == '') {
+ while (!$host) {
$host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost');
}
$port = '';
- while ($port == '') {
+ while (!$port) {
$port = $this->in(__d('cake_console', 'Port?'), null, 'n');
}
@@ -130,16 +130,16 @@ protected function _interactive() {
}
$login = '';
- while ($login == '') {
+ while (!$login) {
$login = $this->in(__d('cake_console', 'User:'), null, 'root');
}
$password = '';
$blankPassword = false;
- while ($password == '' && $blankPassword == false) {
+ while (!$password && !$blankPassword) {
$password = $this->in(__d('cake_console', 'Password:'));
- if ($password == '') {
+ if (!$password) {
$blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n');
if ($blank == 'y') {
$blankPassword = true;
@@ -148,12 +148,12 @@ protected function _interactive() {
}
$database = '';
- while ($database == '') {
+ while (!$database) {
$database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake');
}
$prefix = '';
- while ($prefix == '') {
+ while (!$prefix) {
$prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n');
}
if (strtolower($prefix) == 'n') {
@@ -161,7 +161,7 @@ protected function _interactive() {
}
$encoding = '';
- while ($encoding == '') {
+ while (!$encoding) {
$encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n');
}
if (strtolower($encoding) == 'n') {
@@ -170,7 +170,7 @@ protected function _interactive() {
$schema = '';
if ($datasource == 'postgres') {
- while ($schema == '') {
+ while (!$schema) {
$schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n');
}
}
@@ -180,7 +180,7 @@ protected function _interactive() {
$config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
- while ($this->_verify($config) == false) {
+ while (!$this->_verify($config)) {
$this->_interactive();
}
@@ -277,11 +277,7 @@ public function bake($configs) {
$info['port'] = null;
}
- if ($info['persistent'] === false) {
- $info['persistent'] = 'false';
- } else {
- $info['persistent'] = ($info['persistent'] == true) ? 'true' : 'false';
- }
+ $info['persistent'] = var_export((bool)$info['persistent'], true);
$oldConfigs[] = array(
'name' => $configName,
View
8 lib/Cake/Console/Command/Task/ExtractTask.php
@@ -391,7 +391,7 @@ protected function _parse($functionName, $map) {
$position = $count;
$depth = 0;
- while ($depth == 0) {
+ while (!$depth) {
if ($this->_tokens[$position] == '(') {
$depth++;
} elseif ($this->_tokens[$position] == ')') {
@@ -480,7 +480,7 @@ protected function _processValidationRules($field, $rules, $file, $domain) {
}
$dims = Hash::dimensions($rules);
- if ($dims == 1 || ($dims == 2 && isset($rules['message']))) {
+ if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
$rules = array($rules);
}
@@ -523,7 +523,7 @@ protected function _buildFiles() {
$occurrences[] = $file . ':' . implode(';', $lines);
}
$occurrences = implode("\n#: ", $occurrences);
- $header = '#: ' . str_replace($paths, '', $occurrences) . "\n";
+ $header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
if ($plural === false) {
$sentence = "msgid \"{$msgid}\"\n";
@@ -591,7 +591,7 @@ protected function _writeFiles() {
);
if (strtoupper($response) === 'N') {
$response = '';
- while ($response == '') {
+ while (!$response) {
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
$File = new File($this->_output . $response);
$filename = $response;
View
23 lib/Cake/Console/Command/Task/ModelTask.php
@@ -472,16 +472,14 @@ public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
}
if ($choice != $defaultChoice) {
+ $validate[$validatorName] = $choice;
if (is_numeric($choice) && isset($this->_validations[$choice])) {
$validate[$validatorName] = $this->_validations[$choice];
- } else {
- $validate[$validatorName] = $choice;
}
}
- if ($this->interactive == true && $choice != $defaultChoice) {
+ $anotherValidator = 'n';
+ if ($this->interactive && $choice != $defaultChoice) {
$anotherValidator = $this->in(__d('cake_console', 'Would you like to add another validation rule?'), array('y', 'n'), 'n');
- } else {
- $anotherValidator = 'n';
}
}
return $validate;
@@ -583,7 +581,7 @@ public function findHasOneAndMany(Model $model, $associations) {
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
$possibleJoinTable = preg_match($pattern, $otherTable);
- if ($possibleJoinTable == true) {
+ if ($possibleJoinTable) {
continue;
}
foreach ($modelFieldsTemp as $fieldName => $field) {
@@ -780,7 +778,7 @@ protected function _generatePossibleKeys() {
*/
public function bake($name, $data = array()) {
if (is_object($name)) {
- if ($data == false) {
+ if (!$data) {
$data = array();
$data['associations'] = $this->doAssociations($name);
$data['validate'] = $this->doValidation($name);
@@ -935,7 +933,7 @@ public function getName($useDbConfig = null) {
$enteredModel = '';
- while ($enteredModel == '') {
+ while (!$enteredModel) {
$enteredModel = $this->in(__d('cake_console', "Enter a number from the list above,\n" .
"type in the name of another model, or 'q' to exit"), null, 'q');
@@ -944,18 +942,17 @@ public function getName($useDbConfig = null) {
$this->_stop();
}
- if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
+ if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) {
$this->err(__d('cake_console', "The model name you supplied was empty,\n" .
"or the number you selected was not an option. Please try again."));
$enteredModel = '';
}
}
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
- $currentModelName = $this->_modelNames[intval($enteredModel) - 1];
- } else {
- $currentModelName = $enteredModel;
+ return $this->_modelNames[intval($enteredModel) - 1];
}
- return $currentModelName;
+
+ return $enteredModel;
}
/**
View
11 lib/Cake/Console/Command/Task/ProjectTask.php
@@ -66,7 +66,7 @@ public function execute() {
}
$response = false;
- while ($response == false && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
+ while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
$prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
$response = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($response) === 'n') {
@@ -349,10 +349,7 @@ protected function _replaceCorePath($filename, $hardCode) {
if (!file_put_contents($filename, $result)) {
return false;
}
- if ($count == 0) {
- return false;
- }
- return true;
+ return (bool)$count;
}
/**
@@ -387,7 +384,7 @@ public function getPrefix() {
$admin = '';
$prefixes = Configure::read('Routing.prefixes');
if (!empty($prefixes)) {
- if (count($prefixes) == 1) {
+ if (count($prefixes) === 1) {
return $prefixes[0] . '_';
}
if ($this->interactive) {
@@ -409,7 +406,7 @@ public function getPrefix() {
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/core.php to use prefix routing.'));
$this->out(__d('cake_console', 'What would you like the prefix route to be?'));
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller'));
- while ($admin == '') {
+ while (!$admin) {
$admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
}
if ($this->cakeAdmin($admin) !== true) {
View
4 lib/Cake/Console/Command/Task/TemplateTask.php
@@ -123,7 +123,7 @@ public function set($one, $two = null) {
$data = array($one => $two);
}
- if ($data == null) {
+ if (!$data) {
return false;
}
$this->templateVars = $data + $this->templateVars;
@@ -166,7 +166,7 @@ public function generate($directory, $filename, $vars = null) {
* @return string returns the path to the selected theme.
*/
public function getThemePath() {
- if (count($this->templatePaths) == 1) {
+ if (count($this->templatePaths) === 1) {
$paths = array_values($this->templatePaths);
return $paths[0];
}
View
7 lib/Cake/Console/Command/Task/TestTask.php
@@ -83,15 +83,16 @@ class TestTask extends BakeTask {
*/
public function execute() {
parent::execute();
- if (empty($this->args)) {
+ $count = count($this->args);
+ if (!$count) {
$this->_interactive();
}
- if (count($this->args) == 1) {
+ if ($count === 1) {
$this->_interactive($this->args[0]);
}
- if (count($this->args) > 1) {
+ if ($count > 1) {
$type = Inflector::classify($this->args[0]);
if ($this->bake($type, $this->args[1])) {
$this->out('<success>Done</success>');
View
4 lib/Cake/Console/Command/Task/ViewTask.php
@@ -316,9 +316,9 @@ public function bakeActions($actions, $vars) {
*/
public function customAction() {
$action = '';
- while ($action == '') {
+ while (!$action) {
$action = $this->in(__d('cake_console', 'Action Name? (use lowercase_underscored function name)'));
- if ($action == '') {
+ if (!$action) {
$this->out(__d('cake_console', 'The action name you supplied was empty. Please try again.'));
}
}
View
2  lib/Cake/Console/ConsoleErrorHandler.php
@@ -81,7 +81,7 @@ public function handleError($code, $description, $file = null, $line = null, $co
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
$stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));
- if (Configure::read('debug') == 0) {
+ if (!Configure::read('debug')) {
CakeLog::write($log, $message);
}
View
10 lib/Cake/Console/Shell.php
@@ -154,7 +154,7 @@ class Shell extends Object {
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell
*/
public function __construct($stdout = null, $stderr = null, $stdin = null) {
- if ($this->name == null) {
+ if (!$this->name) {
$this->name = Inflector::camelize(str_replace(array('Shell', 'Task'), '', get_class($this)));
}
$this->Tasks = new TaskCollection($this);
@@ -162,13 +162,13 @@ public function __construct($stdout = null, $stderr = null, $stdin = null) {
$this->stdout = $stdout;
$this->stderr = $stderr;
$this->stdin = $stdin;
- if ($this->stdout == null) {
+ if (!$this->stdout) {
$this->stdout = new ConsoleOutput('php://stdout');
}
- if ($this->stderr == null) {
+ if (!$this->stderr) {
$this->stderr = new ConsoleOutput('php://stderr');
}
- if ($this->stdin == null) {
+ if (!$this->stdin) {
$this->stdin = new ConsoleInput('php://stdin');
}
$this->_useLogger();
@@ -325,7 +325,7 @@ public function hasMethod($name) {
*/
public function dispatchShell() {
$args = func_get_args();
- if (is_string($args[0]) && count($args) == 1) {
+ if (is_string($args[0]) && count($args) === 1) {
$args = explode(' ', $args[0]);
}
View
4 lib/Cake/Console/Templates/skel/Config/bootstrap.php
@@ -98,11 +98,11 @@
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
- 'scopes' => array('notice', 'info', 'debug'),
+ 'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
- 'scopes' => array('warning', 'error', 'critical', 'alert', 'emergency'),
+ 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
View
32 lib/Cake/Console/Templates/skel/Console/cake
@@ -10,24 +10,28 @@
# Licensed under The MIT License
# Redistributions of files must retain the above copyright notice.
#
-# @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
-# @link http://cakephp.org CakePHP(tm) Project
-# @package app.Console
-# @since CakePHP(tm) v 2.0
-# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+# @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
+# @link http://cakephp.org CakePHP(tm) Project
+# @package app.Console
+# @since CakePHP(tm) v 2.0
+# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
################################################################################
-LIB=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && LIB=$LIB/$(basename -- "$0")
-while [ -h "$LIB" ]; do
- DIR=$(dirname -- "$LIB")
- SYM=$(readlink "$LIB")
- LIB=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
-done
+# Canonicalize by following every symlink of the given name recursively
+canonicalize() {
+ NAME=$1
+ while [ -h "$NAME" ]; do
+ DIR=$(dirname -- "$NAME")
+ SYM=$(readlink "$NAME")
+ NAME=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+ echo "$NAME"
+}
-LIB=$(dirname -- "$LIB")/
-APP=`pwd`
+CONSOLE=$(dirname $(canonicalize "$0"))
+APP=$(dirname "$CONSOLE")
-exec php -q "$LIB"cake.php -working "$APP" "$@"
+exec php -q $CONSOLE/cake.php -working "$APP" "$@"
exit;
View
20 lib/Cake/Console/cake
@@ -17,17 +17,21 @@
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
#
################################################################################
-LIB=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && LIB=$LIB/$(basename -- "$0")
-while [ -h "$LIB" ]; do
- DIR=$(dirname -- "$LIB")
- SYM=$(readlink "$LIB")
- LIB=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
-done
+# Canonicalize by following every symlink of the given name recursively
+canonicalize() {
+ NAME=$1
+ while [ -h "$NAME" ]; do
+ DIR=$(dirname -- "$NAME")
+ SYM=$(readlink "$NAME")
+ NAME=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+ echo "$NAME"
+}
-LIB=$(dirname -- "$LIB")/
+CONSOLE=$(dirname $(canonicalize "$0"))
APP=`pwd`
-exec php -q "$LIB"cake.php -working "$APP" "$@"
+exec php -q $CONSOLE/cake.php -working "$APP" "$@"
exit;
View
2  lib/Cake/Controller/Component/Acl/IniAcl.php
@@ -91,7 +91,7 @@ public function inherit($aro, $aco, $action = "*") {
* @return boolean Success
*/
public function check($aro, $aco, $action = null) {
- if ($this->config == null) {
+ if (!$this->config) {
$this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php');
}
$aclConfig = $this->config;
View
4 lib/Cake/Controller/Component/Acl/PhpAcl.php
@@ -170,11 +170,11 @@ public function check($aro, $aco, $action = "*") {
foreach ($path as $depth => $node) {
foreach ($prioritizedAros as $aros) {
if (!empty($node['allow'])) {
- $allow = $allow || count(array_intersect($node['allow'], $aros)) > 0;
+ $allow = $allow || count(array_intersect($node['allow'], $aros));
}
if (!empty($node['deny'])) {
- $allow = $allow && count(array_intersect($node['deny'], $aros)) == 0;
+ $allow = $allow && !count(array_intersect($node['deny'], $aros));
}
}
}
View
4 lib/Cake/Controller/Component/CookieComponent.php
@@ -391,7 +391,7 @@ protected function _expire($expires = null) {
}
$this->_reset = $this->_expires;
- if ($expires == 0) {
+ if (!$expires) {
return $this->_expires = 0;
}
@@ -517,7 +517,7 @@ protected function _explode($string) {
$first = substr($string, 0, 1);
if ($first === '{' || $first === '[') {
$ret = json_decode($string, true);
- return ($ret != null) ? $ret : $string;
+ return ($ret) ? $ret : $string;
}
$array = array();
foreach (explode(',', $string) as $pair) {
View
2  lib/Cake/Controller/Component/EmailComponent.php
@@ -316,7 +316,7 @@ public function send($content = null, $template = null, $layout = null) {
foreach ($this->headers as $key => $value) {
$headers['X-' . $key] = $value;
}
- if ($this->date != false) {
+ if ($this->date) {
$headers['Date'] = $this->date;
}
$lib->setHeaders($headers);
View
4 lib/Cake/Controller/Component/SecurityComponent.php
@@ -314,7 +314,7 @@ public function requireAuth() {
* @throws BadRequestException
*/
public function blackHole(Controller $controller, $error = '') {
- if ($this->blackHoleCallback == null) {
+ if (!$this->blackHoleCallback) {
throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
}
return $this->_callback($controller, $this->blackHoleCallback, array($error));
@@ -493,7 +493,7 @@ protected function _validatePost(Controller $controller) {
$fieldList += $lockedFields;
$unlocked = implode('|', $unlocked);
- $check = Security::hash(serialize($fieldList) . $unlocked . Configure::read('Security.salt'));
+ $check = Security::hash(serialize($fieldList) . $unlocked . Configure::read('Security.salt'), 'sha1');
return ($token === $check);
}
View
23 lib/Cake/Controller/Controller.php
@@ -319,7 +319,7 @@ public function __construct($request = null, $response = null) {
$this->name = substr(get_class($this), 0, -10);
}
- if ($this->viewPath == null) {
+ if (!$this->viewPath) {
$this->viewPath = $this->name;
}
@@ -454,7 +454,7 @@ public function setRequest(CakeRequest $request) {
$this->passedArgs = array_merge($request->params['pass'], $request->params['named']);
}
- if (array_key_exists('return', $request->params) && $request->params['return'] == 1) {
+ if (!empty($request->params['return']) && $request->params['return'] == 1) {
$this->autoRender = false;
}
if (!empty($request->params['bare'])) {
@@ -796,7 +796,7 @@ public function redirect($url, $status = null, $exit = true) {
* @return array Array with keys url, status and exit
*/
protected function _parseBeforeRedirect($response, $url, $status, $exit) {
- if (is_array($response) && isset($response[0])) {
+ if (is_array($response) && array_key_exists(0, $response)) {
foreach ($response as $resp) {
if (is_array($resp) && isset($resp['url'])) {
extract($resp, EXTR_OVERWRITE);
@@ -966,14 +966,15 @@ public function render($view = null, $layout = null) {
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer
*/
public function referer($default = null, $local = false) {
- if ($this->request) {
- $referer = $this->request->referer($local);
- if ($referer == '/' && $default != null) {
- return Router::url($default, true);
- }
- return $referer;
+ if(!$this->request) {
+ return '/';
+ }
+
+ $referer = $this->request->referer($local);
+ if ($referer == '/' && $default) {
+ return Router::url($default, true);
}
- return '/';
+ return $referer;
}
/**
@@ -1061,7 +1062,7 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
$cond[$key] = $value;
}
}
- if ($bool != null && strtoupper($bool) != 'AND') {
+ if ($bool && strtoupper($bool) != 'AND') {
$cond = array($bool => $cond);
}
return $cond;
View
2  lib/Cake/Controller/Scaffold.php
@@ -146,7 +146,7 @@ public function __construct(Controller $controller, CakeRequest $request) {
$this->controller->viewClass = 'Scaffold';
}
$this->_validSession = (
- isset($this->controller->Session) && $this->controller->Session->valid() != false
+ isset($this->controller->Session) && $this->controller->Session->valid()
);
$this->_scaffold($request);
}
View
2  lib/Cake/Core/App.php
@@ -607,7 +607,7 @@ public static function import($type = null, $name = null, $parent = true, $searc
extract($parent, EXTR_OVERWRITE);
}
- if ($name == null && $file == null) {
+ if (!$name && !$file) {
return false;
}
View
4 lib/Cake/Core/Configure.php
@@ -319,10 +319,10 @@ public static function load($key, $config = 'default', $merge = true) {
public static function dump($key, $config = 'default', $keys = array()) {
$reader = self::_getReader($config);
if (!$reader) {
- throw new ConfigureException(__d('cake', 'There is no "%s" adapter.', $config));
+ throw new ConfigureException(__d('cake_dev', 'There is no "%s" adapter.', $config));
}
if (!method_exists($reader, 'dump')) {
- throw new ConfigureException(__d('cake', 'The "%s" adapter, does not have a dump() method.', $config));
+ throw new ConfigureException(__d('cake_dev', 'The "%s" adapter, does not have a dump() method.', $config));
}
$values = self::$_values;
if (!empty($keys) && is_array($keys)) {
View
1  lib/Cake/Error/ErrorHandler.php
@@ -22,7 +22,6 @@
App::uses('Debugger', 'Utility');
App::uses('CakeLog', 'Log');
App::uses('ExceptionRenderer', 'Error');
-App::uses('AppController', 'Controller');
/**
*
View
4 lib/Cake/Error/ExceptionRenderer.php
@@ -201,7 +201,7 @@ protected function _cakeError(CakeException $error) {
*/
public function error400($error) {
$message = $error->getMessage();
- if (Configure::read('debug') == 0 && $error instanceof CakeException) {
+ if (!Configure::read('debug') && $error instanceof CakeException) {
$message = __d('cake', 'Not Found');
}
$url = $this->controller->request->here();
@@ -223,7 +223,7 @@ public function error400($error) {
*/
public function error500($error) {
$message = $error->getMessage();
- if (Configure::read('debug') == 0) {
+ if (!Configure::read('debug')) {
$message = __d('cake', 'An Internal Error Has Occurred.');
}
$url = $this->controller->request->here();
View
9 lib/Cake/I18n/I18n.php
@@ -24,13 +24,6 @@
App::uses('L10n', 'I18n');
App::uses('Multibyte', 'I18n');
-if (function_exists('mb_internal_encoding')) {
- $encoding = Configure::read('App.encoding');
- if (!empty($encoding)) {
- mb_internal_encoding($encoding);
- }
-}
-
/**
* I18n handles translation of Text and time format strings.
*
@@ -412,7 +405,7 @@ public static function loadMo($filename) {
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($header);
- if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
+ if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && !$version) {
for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
View
255 lib/Cake/I18n/Multibyte.php
@@ -18,261 +18,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-if (!function_exists('mb_stripos')) {
-
-/**
- * Find position of first occurrence of a case-insensitive string.
- *
- * @param string $haystack The string from which to get the position of the first occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param integer $offset The position in $haystack to start searching.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
- * if $needle is not found.
- */
- function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
- return Multibyte::stripos($haystack, $needle, $offset);
- }
-
-}
-
-if (!function_exists('mb_stristr')) {
-
-/**
- * Finds first occurrence of a string within another, case insensitive.
- *
- * @param string $haystack The string from which to get the first occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
- * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
- * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
- * Default value is false.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack, or false if $needle is not found.
- */
- function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
- return Multibyte::stristr($haystack, $needle, $part);
- }
-
-}
-
-if (!function_exists('mb_strlen')) {
-
-/**
- * Get string length.
- *
- * @param string $string The string being checked for length.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer The number of characters in string $string having character encoding encoding.
- * A multi-byte character is counted as 1.
- */
- function mb_strlen($string, $encoding = null) {
- return Multibyte::strlen($string);
- }
-
-}
-
-if (!function_exists('mb_strpos')) {
-
-/**
- * Find position of first occurrence of a string.
- *
- * @param string $haystack The string being checked.
- * @param string $needle The position counted from the beginning of haystack.
- * @param integer $offset The search offset. If it is not specified, 0 is used.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
- * If $needle is not found, it returns false.
- */
- function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
- return Multibyte::strpos($haystack, $needle, $offset);
- }
-
-}
-
-if (!function_exists('mb_strrchr')) {
-
-/**
- * Finds the last occurrence of a character in a string within another.
- *
- * @param string $haystack The string from which to get the last occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
- * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
- * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
- * Default value is false.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
- */
- function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
- return Multibyte::strrchr($haystack, $needle, $part);
- }
-
-}
-
-if (!function_exists('mb_strrichr')) {
-
-/**
- * Finds the last occurrence of a character in a string within another, case insensitive.
- *
- * @param string $haystack The string from which to get the last occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
- * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
- * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
- * Default value is false.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
- */
- function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
- return Multibyte::strrichr($haystack, $needle, $part);
- }
-
-}
-
-if (!function_exists('mb_strripos')) {
-
-/**
- * Finds position of last occurrence of a string within another, case insensitive
- *
- * @param string $haystack The string from which to get the position of the last occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param integer $offset The position in $haystack to start searching.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
- * or false if $needle is not found.
- */
- function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
- return Multibyte::strripos($haystack, $needle, $offset);
- }
-
-}
-
-if (!function_exists('mb_strrpos')) {
-
-/**
- * Find position of last occurrence of a string in a string.
- *
- * @param string $haystack The string being checked, for the last occurrence of $needle.
- * @param string $needle The string to find in $haystack.
- * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
- * Negative values will stop searching at an arbitrary point prior to the end of the string.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
- * If $needle is not found, it returns false.
- */
- function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
- return Multibyte::strrpos($haystack, $needle, $offset);
- }
-
-}
-
-if (!function_exists('mb_strstr')) {
-
-/**
- * Finds first occurrence of a string within another
- *
- * @param string $haystack The string from which to get the first occurrence of $needle.
- * @param string $needle The string to find in $haystack
- * @param boolean $part Determines which portion of $haystack this function returns.
- * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
- * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
- * Default value is FALSE.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack, or true if $needle is not found.
- */
- function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
- return Multibyte::strstr($haystack, $needle, $part);
- }
-
-}
-
-if (!function_exists('mb_strtolower')) {
-
-/**
- * Make a string lowercase
- *
- * @param string $string The string being lowercased.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string with all alphabetic characters converted to lowercase.
- */
- function mb_strtolower($string, $encoding = null) {
- return Multibyte::strtolower($string);
- }
-
-}
-
-if (!function_exists('mb_strtoupper')) {
-
-/**
- * Make a string uppercase
- *
- * @param string $string The string being uppercased.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string with all alphabetic characters converted to uppercase.
- */
- function mb_strtoupper($string, $encoding = null) {
- return Multibyte::strtoupper($string);
- }
-
-}
-
-if (!function_exists('mb_substr_count')) {
-
-/**
- * Count the number of substring occurrences
- *
- * @param string $haystack The string being checked.
- * @param string $needle The string being found.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer The number of times the $needle substring occurs in the $haystack string.
- */
- function mb_substr_count($haystack, $needle, $encoding = null) {
- return Multibyte::substrCount($haystack, $needle);
- }
-
-}
-
-if (!function_exists('mb_substr')) {
-
-/**
- * Get part of string
- *
- * @param string $string The string being checked.
- * @param integer $start The first position used in $string.
- * @param integer $length The maximum length of the returned string.
- * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string The portion of $string specified by the $string and $length parameters.
- */
- function mb_substr($string, $start, $length = null, $encoding = null) {
- return Multibyte::substr($string, $start, $length);
- }
-
-}
-
-if (!function_exists('mb_encode_mimeheader')) {
-
-/**
- * Encode string for MIME header
- *
- * @param string $str The string being encoded
- * @param string $charset specifies the name of the character set in which str is represented in.
- * The default value is determined by the current NLS setting (mbstring.language).
- * @param string $transfer_encoding specifies the scheme of MIME encoding.
- * It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
- * @param string $linefeed specifies the EOL (end-of-line) marker with which
- * mb_encode_mimeheader() performs line-folding
- * (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
- * The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
- * @param integer $indent [definition unknown and appears to have no affect]
- * @return string A converted version of the string represented in ASCII.
- */
- function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
- return Multibyte::mimeEncode($str, $charset, $linefeed);
- }
-
-}
-
/**
* Multibyte handling methods.
*
View
39 lib/Cake/Log/CakeLog.php
@@ -67,6 +67,7 @@
* application. By using scopes you can control logging for each part
* of your application and still keep standard log levels.
*
+ *
* See CakeLog::config() and CakeLog::write() for more information
* on scopes
*
@@ -173,7 +174,10 @@ protected static function _init() {
*
* The above logger will only capture log entries made in the
* `payment` and `order` scopes. All other scopes including the
- * undefined scope will be ignored.
+ * undefined scope will be ignored. Its important to remember that
+ * when using scopes you must also define the `types` of log messages
+ * that a logger will handle. Failing to do so will result in the logger
+ * catching all log messages even if the scope is incorrect.
*
* @param string $key The keyname for this logger, used to remove the
* logger later.
@@ -422,24 +426,29 @@ public static function write($type, $message, $scope = array()) {
$logged = false;
foreach (self::$_Collection->enabled() as $streamName) {
$logger = self::$_Collection->{$streamName};
- $types = null;
- $scopes = array();
+ $types = $scopes = $config = array();
if ($logger instanceof BaseLog) {
$config = $logger->config();
- if (isset($config['types'])) {
- $types = $config['types'];
- }
- if (isset($config['scopes'])) {
- $scopes = $config['scopes'];
- }
}
- if (is_string($scope)) {
- $inScope = in_array($scope, $scopes);
- } else {
- $intersect = array_intersect($scope, $scopes);
- $inScope = !empty($intersect);
+ if (isset($config['types'])) {
+ $types = $config['types'];
+ }
+ if (isset($config['scopes'])) {
+ $scopes = $config['scopes'];
}
- if (empty($types) || in_array($type, $types) || in_array($type, $scopes) && $inScope) {
+ $inScope = (count(array_intersect((array)$scope, $scopes)) > 0);
+ $correctLevel = in_array($type, $types);
+
+ if (
+ // No config is a catch all (bc mode)
+ (empty($types) && empty($scopes)) ||
+ // BC layer for mixing scope & level
+ (in_array($type, $scopes)) ||
+ // no scopes, but has level
+ (empty($scopes) && $correctLevel) ||
+ // exact scope + level
+ ($correctLevel && $inScope)
+ ) {
$logger->write($type, $message);
$logged = true;
}
View
18 lib/Cake/Model/Behavior/ContainableBehavior.php
@@ -92,21 +92,25 @@ public function setup(Model $Model, $settings = array()) {
*/
public function beforeFind(Model $Model, $query) {
$reset = (isset($query['reset']) ? $query['reset'] : true);
- $noContain = (
- (isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) ||
- (isset($query['contain']) && empty($query['contain']))
- );
+ $noContain = false;
$contain = array();
+
if (isset($this->runtime[$Model->alias]['contain'])) {
+ $noContain = empty($this->runtime[$Model->alias]['contain']);
$contain = $this->runtime[$Model->alias]['contain'];
unset($this->runtime[$Model->alias]['contain']);
}
+
if (isset($query['contain'])) {
- $contain = array_merge($contain, (array)$query['contain']);
+ $noContain = $noContain || empty($query['contain']);
+ if ($query['contain'] !== false) {
+ $contain = array_merge($contain, (array)$query['contain']);
+ }
}
+ $noContain = $noContain && empty($contain);
+
if (
- $noContain || !$contain || in_array($contain, array(null, false), true) ||
- (isset($contain[0]) && $contain[0] === null)
+ $noContain || empty($contain) || (isset($contain[0]) && $contain[0] === null)
) {
if ($noContain) {
$query['recursive'] = -1;
View
2  lib/Cake/Model/Behavior/TranslateBehavior.php
@@ -338,7 +338,7 @@ public function beforeValidate(Model $Model) {
* @return boolean true.
*/
public function beforeSave(Model $Model, $options = array()) {
- if (isset($options['validate']) && $options['validate'] == false) {
+ if (isset($options['validate']) && !$options['validate']) {
unset($this->runtime[$Model->alias]['beforeSave']);
}
if (isset($this->runtime[$Model->alias]['beforeSave'])) {
View
18 lib/Cake/Model/Behavior/TreeBehavior.php
@@ -179,7 +179,7 @@ public function beforeSave(Model $Model) {
extract($this->settings[$Model->alias]);
$this->_addToWhitelist($Model, array($left, $right));
- if (!$Model->id) {
+ if (!$Model->id || !$Model->exists()) {
if (array_key_exists($parent, $Model->data[$Model->alias]) && $Model->data[$Model->alias][$parent]) {
$parentNode = $Model->find('first', array(
'conditions' => array($scope, $Model->escapeField() => $Model->data[$Model->alias][$parent]),
@@ -355,17 +355,16 @@ public function generateTreeList(Model $Model, $conditions = null, $keyPath = nu
$recursive = $overrideRecursive;
}
- if ($keyPath == null && $valuePath == null && $Model->hasField($Model->displayField)) {
+ $fields = null;
+ if (!$keyPath && !$valuePath && $Model->hasField($Model->displayField)) {
$fields = array($Model->primaryKey, $Model->displayField, $left, $right);
- } else {
- $fields = null;
}
- if ($keyPath == null) {
+ if (!$keyPath) {
$keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey;
}
- if ($valuePath == null) {
+ if (!$valuePath) {
$valuePath = array('%s%s', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField);
} elseif (is_string($valuePath)) {
@@ -645,9 +644,8 @@ public function recover(Model $Model, $mode = 'parent', $missingParentAction = n
$db = ConnectionManager::getDataSource($Model->useDbConfig);
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
$path = $this->getPath($Model, $array[$Model->alias][$Model->primaryKey]);
- if ($path == null || count($path) < 2) {
- $parentId = null;
- } else {
+ $parentId = null;
+ if (count($path) > 1) {
$parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey];
}
$Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
@@ -800,7 +798,7 @@ public function verify(Model $Model) {
$scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i)
)));
if ($count != 1) {
- if ($count == 0) {
+ if (!$count) {
$errors[] = array('index', $i, 'missing');
} else {
$errors[] = array('index', $i, 'duplicate');
View
6 lib/Cake/Model/Datasource/CakeSession.php
@@ -131,7 +131,7 @@ public static function init($base = null) {
self::$time = time();
$checkAgent = Configure::read('Session.checkAgent');
- if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) {
+ if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT')) {
self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
}
self::_setPath($base);
@@ -247,7 +247,7 @@ public static function id($id = null) {
public static function delete($name) {
if (self::check($name)) {
self::_overwrite($_SESSION, Hash::remove($_SESSION, $name));
- return (self::check($name) == false);
+ return !self::check($name);
}
self::_setError(2, __d('cake_dev', "%s doesn't exist", $name));
return false;
@@ -660,7 +660,7 @@ protected static function _checkValid() {
*/
public static function renew() {
if (session_id()) {
- if (session_id() != '' || isset($_COOKIE[session_name()])) {
+ if (session_id() || isset($_COOKIE[session_name()])) {
setcookie(Configure::read('Session.cookie'), '', time() - 42000, self::$path);
}
session_regenerate_id(true);
View
40 lib/Cake/Model/Datasource/Database/Mysql.php
@@ -120,6 +120,13 @@ class Mysql extends DboSource {
);
/**
+ * Mapping of collation names to character set names
+ *
+ * @var array
+ */
+ protected $_charsets = array();
+
+/**
* Connects to the database using options in the given configuration array.
*
* @return boolean True if the database could be connected, else false
@@ -156,6 +163,7 @@ public function connect() {
));
}
+ $this->_charsets = array();
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
return $this->connected;
@@ -178,7 +186,7 @@ public function enabled() {
*/
public function listSources($data = null) {
$cache = parent::listSources();
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
@@ -262,15 +270,24 @@ public function getEncoding() {
* @return string Character set name
*/
public function getCharsetName($name) {
- if ((bool)version_compare($this->getVersion(), "5", ">=")) {
- $r = $this->_execute('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME = ?', array($name));
- $cols = $r->fetch(PDO::FETCH_ASSOC);
+ if ((bool)version_compare($this->getVersion(), "5", "<")) {
+ return false;
+ }
+ if (isset($this->_charsets[$name])) {
+ return $this->_charsets[$name];
+ }
+ $r = $this->_execute(
+ 'SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME = ?',
+ array($name)
+ );
+ $cols = $r->fetch(PDO::FETCH_ASSOC);
- if (isset($cols['CHARACTER_SET_NAME'])) {
- return $cols['CHARACTER_SET_NAME'];
- }
+ if (isset($cols['CHARACTER_SET_NAME'])) {
+ $this->_charsets[$name] = $cols['CHARACTER_SET_NAME'];
+ } else {
+ $this->_charsets[$name] = false;
}
- return false;
+ return $this->_charsets[$name];
}
/**
@@ -283,7 +300,7 @@ public function getCharsetName($name) {
public function describe($model) {
$key = $this->fullTableName($model, false);
$cache = parent::describe($key);
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$table = $this->fullTableName($model);
@@ -335,7 +352,7 @@ public function update(Model $model, $fields = array(), $values = null, $conditi
return parent::update($model, $fields, $values, $conditions);
}
- if ($values == null) {
+ if (!$values) {
$combined = $fields;
} else {
$combined = array_combine($fields, $values);
@@ -436,6 +453,7 @@ public function index($model) {
if (!isset($index[$idx->Key_name]['column'])) {
$col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name;
+
if ($idx->Index_type === 'FULLTEXT') {
$index[$idx->Key_name]['type'] = strtolower($idx->Index_type);
} else {
@@ -637,7 +655,7 @@ public function column($real) {
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
- if (($col === 'tinyint' && $limit == 1) || $col