diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 7507ede6a5a..9ed88ca8dee 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -53,7 +53,7 @@ class TreeBehavior extends ModelBehavior { * * @var array */ - protected $_deletedRow = null; + protected $_deletedRow = array(); /** * Initiate Tree behavior @@ -130,7 +130,7 @@ public function beforeDelete(Model $Model, $cascade = true) { 'fields' => array($Model->escapeField($left), $Model->escapeField($right)), 'recursive' => -1)); if ($data) { - $this->_deletedRow = current($data); + $this->_deletedRow[$Model->alias] = current($data); } return true; } @@ -145,8 +145,8 @@ public function beforeDelete(Model $Model, $cascade = true) { */ public function afterDelete(Model $Model) { extract($this->settings[$Model->alias]); - $data = $this->_deletedRow; - $this->_deletedRow = null; + $data = $this->_deletedRow[$Model->alias]; + $this->_deletedRow[$Model->alias] = null; if (!$data[$right] || !$data[$left]) { return true; diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 85913ee12c2..33631b62870 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1317,10 +1317,8 @@ public function schema($field = false) { if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) { $db = $this->getDataSource(); $db->cacheSources = ($this->cacheSources && $db->cacheSources); - if (method_exists($db, 'describe') && $this->useTable !== false) { + if (method_exists($db, 'describe')) { $this->_schema = $db->describe($this); - } elseif ($this->useTable === false) { - $this->_schema = array(); } } if (!is_string($field)) { @@ -1484,7 +1482,8 @@ public function create($data = array(), $filterKey = false) { $this->validationErrors = array(); if ($data !== null && $data !== false) { - foreach ($this->schema() as $field => $properties) { + $schema = (array)$this->schema(); + foreach ($schema as $field => $properties) { if ($this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') { $defaults[$field] = $properties['default']; } diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index c081966b27e..c096a975569 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1242,7 +1242,7 @@ protected function _encodeString($text, $charset) { * @param string $message Message to wrap * @return array Wrapped message */ - protected function _wrap($message) { + protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) { $message = str_replace(array("\r\n", "\r"), "\n", $message); $lines = explode("\n", $message); $formatted = array(); @@ -1253,7 +1253,10 @@ protected function _wrap($message) { continue; } if (!preg_match('/\<[a-z]/i', $line)) { - $formatted = array_merge($formatted, explode("\n", wordwrap($line, self::LINE_LENGTH_SHOULD, "\n"))); + $formatted = array_merge( + $formatted, + explode("\n", wordwrap($line, $wrapLength, "\n")) + ); continue; } @@ -1266,7 +1269,7 @@ protected function _wrap($message) { $tag .= $char; if ($char === '>') { $tagLength = strlen($tag); - if ($tagLength + $tmpLineLength < self::LINE_LENGTH_SHOULD) { + if ($tagLength + $tmpLineLength < $wrapLength) { $tmpLine .= $tag; $tmpLineLength += $tagLength; } else { @@ -1275,7 +1278,7 @@ protected function _wrap($message) { $tmpLine = ''; $tmpLineLength = 0; } - if ($tagLength > self::LINE_LENGTH_SHOULD) { + if ($tagLength > $wrapLength) { $formatted[] = $tag; } else { $tmpLine = $tag; @@ -1292,14 +1295,14 @@ protected function _wrap($message) { $tag = '<'; continue; } - if ($char === ' ' && $tmpLineLength >= self::LINE_LENGTH_SHOULD) { + if ($char === ' ' && $tmpLineLength >= $wrapLength) { $formatted[] = $tmpLine; $tmpLineLength = 0; continue; } $tmpLine .= $char; $tmpLineLength++; - if ($tmpLineLength === self::LINE_LENGTH_SHOULD) { + if ($tmpLineLength === $wrapLength) { $nextChar = $line[$i + 1]; if ($nextChar === ' ' || $nextChar === '<') { $formatted[] = trim($tmpLine); diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index a6c257b63e3..bf9bcb9fa69 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -906,6 +906,20 @@ public function testSchema() { $this->assertEquals($Post->getColumnTypes(), array_combine($columns, $types)); } +/** + * Check schema() on a model with useTable = false; + * + * @return void + */ + public function testSchemaUseTableFalse() { + $model = new TheVoid(); + $result = $model->schema(); + $this->assertNull($result); + + $result = $model->create(); + $this->assertEmpty($result); + } + /** * data provider for time tests. * diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index e84536e1de1..5924374bfb6 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -42,8 +42,8 @@ public function formatAddress($address) { * Wrap to protected method * */ - public function wrap($text) { - return parent::_wrap($text); + public function wrap($text, $length = CakeEmail::LINE_LENGTH_MUST) { + return parent::_wrap($text, $length); } /** @@ -1398,7 +1398,7 @@ public function testResetWithCharset() { */ public function testWrap() { $text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,', 'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.', @@ -1407,7 +1407,7 @@ public function testWrap() { $this->assertSame($expected, $result); $text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis', 'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan', @@ -1417,7 +1417,7 @@ public function testWrap() { $this->assertSame($expected, $result); $text = '

Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec ac turpis orci, non commodo odio.
Morbi nibh nisi, vehicula pellentesque accumsan amet.


'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( '

Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec ac', 'turpis orci, non commodo odio.
Morbi nibh nisi, vehicula', @@ -1427,7 +1427,7 @@ public function testWrap() { $this->assertSame($expected, $result); $text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac', 'turpis orci, non commodo odio. Morbi nibh', @@ -1437,7 +1437,7 @@ public function testWrap() { $this->assertSame($expected, $result); $text = 'Lorem ipsum ok'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum', '', @@ -1447,7 +1447,7 @@ public function testWrap() { $this->assertSame($expected, $result); $text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum', 'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite', diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index c99175f895a..3961b1b3345 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -699,6 +699,17 @@ public static function reduce(array $data, $path, $function) { * Apply a callback to a set of extracted values using `$function`. * The function will get the extracted values as the first argument. * + * ### Example + * + * You can easily count the results of an extract using apply(). + * For example to count the comments on an Article: + * + * `$count = Hash::apply($data, 'Article.Comment.{n}', 'count');` + * + * You could also use a function like `array_sum` to sum the results. + * + * `$total = Hash::apply($data, '{n}.Item.price', 'array_sum');` + * * @param array $data The data to reduce. * @param string $path The path to extract from $data. * @param callable $function The function to call on each extracted value. diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 0b8f5398e5f..0e54f5fac65 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -751,8 +751,7 @@ public function value($options = array(), $field = null, $key = 'value') { /** * Sets the defaults for an input tag. Will set the - * name, value, and id attributes for an array of html attributes. Will also - * add a 'form-error' class if the field contains validation errors. + * name, value, and id attributes for an array of html attributes. * * @param string $field The field name to initialize. * @param array $options Array of options to use while initializing an input field. diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index c7cc88e68e1..dc258a0a652 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -303,9 +303,10 @@ public function tagIsInvalid() { * can be overridden when calling input() * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` * - * @param string|array $model The model object which the form is being defined for. Should - * include the plugin name for plugin forms. e.g. `ContactManager.Contact`. + * @param mixed $model The model name for which the form is being defined. Should + * include the plugin name for plugin models. e.g. `ContactManager.Contact`. * If an array is passed and $options argument is empty, the array will be used as options. + * If `false` no model is used. * @param array $options An array of html attributes and options. * @return string An formatted opening FORM tag. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create @@ -2746,7 +2747,8 @@ protected function _generateOptions($name, $options = array()) { } /** - * Sets field defaults and adds field to form security input hash + * Sets field defaults and adds field to form security input hash. + * Will also add a 'form-error' class if the field contains validation errors. * * ### Options * diff --git a/lib/Cake/View/ThemeView.php b/lib/Cake/View/ThemeView.php index 6b3617c98ca..7605d89b144 100644 --- a/lib/Cake/View/ThemeView.php +++ b/lib/Cake/View/ThemeView.php @@ -25,6 +25,7 @@ * Stub class for 2.1 Compatibility * * @package Cake.View + * @deprecated Deprecated since 2.1, use View class instead */ class ThemeView extends View {