mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge remote branch 'origin/2.0' into 2.0-class-loading
Conflicts: lib/Cake/View/Helper.php
This commit is contained in:
commit
e57b3d8e74
7 changed files with 142 additions and 33 deletions
|
@ -112,7 +112,7 @@ class Controller extends Object {
|
||||||
* @var array
|
* @var array
|
||||||
* @link http://book.cakephp.org/view/1231/Pagination
|
* @link http://book.cakephp.org/view/1231/Pagination
|
||||||
*/
|
*/
|
||||||
public $paginate = array('limit' => 20, 'page' => 1);
|
public $paginate = array('limit' => 20, 'page' => 1, 'maxLimit' => 100);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the views subfolder containing views for this controller.
|
* The name of the views subfolder containing views for this controller.
|
||||||
|
@ -1068,8 +1068,8 @@ class Controller extends Object {
|
||||||
unset($defaults[0]);
|
unset($defaults[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
|
$options = array_merge(array('page' => 1, 'limit' => 20, 'maxLimit' => 100), $defaults, $options);
|
||||||
$options['limit'] = (int) $options['limit'];
|
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);
|
||||||
if (empty($options['limit']) || $options['limit'] < 1) {
|
if (empty($options['limit']) || $options['limit'] < 1) {
|
||||||
$options['limit'] = 1;
|
$options['limit'] = 1;
|
||||||
}
|
}
|
||||||
|
@ -1108,7 +1108,7 @@ class Controller extends Object {
|
||||||
} elseif (intval($page) < 1) {
|
} elseif (intval($page) < 1) {
|
||||||
$options['page'] = $page = 1;
|
$options['page'] = $page = 1;
|
||||||
}
|
}
|
||||||
$page = $options['page'] = (integer)$page;
|
$page = $options['page'] = (int)$page;
|
||||||
|
|
||||||
if (method_exists($object, 'paginate')) {
|
if (method_exists($object, 'paginate')) {
|
||||||
$results = $object->paginate(
|
$results = $object->paginate(
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Deals with Collections of objects. Keeping registries of those objects,
|
|
||||||
* loading and constructing new objects and triggering callbacks.
|
|
||||||
*
|
|
||||||
* PHP 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
*
|
*
|
||||||
|
@ -13,11 +8,21 @@
|
||||||
*
|
*
|
||||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
* @link http://cakephp.org CakePHP(tm) Project
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.cake.libs.view
|
|
||||||
* @since CakePHP(tm) v 0.10.0.1076
|
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Deals with Collections of objects. Keeping registries of those objects,
|
||||||
|
* loading and constructing new objects and triggering callbacks. Each subclass needs
|
||||||
|
* to implement its own load() functionality.
|
||||||
|
*
|
||||||
|
* All core subclasses of ObjectCollection by convention loaded objects are stored
|
||||||
|
* in `$this->_loaded`. Enabled objects are stored in `$this->_enabled`. In addition
|
||||||
|
* the all support an `enabled` option that controls the enabled/disabled state of the object
|
||||||
|
* when loaded.
|
||||||
|
*
|
||||||
|
* @package cake.libs
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
*/
|
||||||
abstract class ObjectCollection {
|
abstract class ObjectCollection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,6 +105,30 @@ class Helper extends Object {
|
||||||
*/
|
*/
|
||||||
protected $_View;
|
protected $_View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimized attributes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_minimizedAttributes = array(
|
||||||
|
'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected',
|
||||||
|
'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format to attribute
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_attributeFormat = '%s="%s"';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format to attribute
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_minimizedAttributeFormat = '%s="%s"';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*
|
*
|
||||||
|
@ -358,7 +382,7 @@ class Helper extends Object {
|
||||||
|
|
||||||
foreach ($options as $key => $value) {
|
foreach ($options as $key => $value) {
|
||||||
if (!isset($exclude[$key]) && $value !== false && $value !== null) {
|
if (!isset($exclude[$key]) && $value !== false && $value !== null) {
|
||||||
$attributes[] = $this->__formatAttribute($key, $value, $escape);
|
$attributes[] = $this->_formatAttribute($key, $value, $escape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$out = implode(' ', $attributes);
|
$out = implode(' ', $attributes);
|
||||||
|
@ -375,30 +399,21 @@ class Helper extends Object {
|
||||||
* @param string $key The name of the attribute to create
|
* @param string $key The name of the attribute to create
|
||||||
* @param string $value The value of the attribute to create.
|
* @param string $value The value of the attribute to create.
|
||||||
* @return string The composed attribute.
|
* @return string The composed attribute.
|
||||||
* @access private
|
|
||||||
*/
|
*/
|
||||||
function __formatAttribute($key, $value, $escape = true) {
|
protected function _formatAttribute($key, $value, $escape = true) {
|
||||||
$attribute = '';
|
$attribute = '';
|
||||||
$attributeFormat = '%s="%s"';
|
|
||||||
static $minimizedAttributes = array();
|
|
||||||
if (empty($minimizedAttributes)) {
|
|
||||||
$minimizedAttributes = array_flip(array(
|
|
||||||
'compact', 'checked', 'declare', 'readonly', 'disabled',
|
|
||||||
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap',
|
|
||||||
'multiple', 'noresize'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$value = '';
|
$value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($minimizedAttributes[$key])) {
|
if (is_numeric($key)) {
|
||||||
|
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
|
||||||
|
} elseif (in_array($key, $this->_minimizedAttributes)) {
|
||||||
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
||||||
$attribute = sprintf($attributeFormat, $key, $key);
|
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$attribute = sprintf($attributeFormat, $key, ($escape ? h($value) : $value));
|
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
|
||||||
}
|
}
|
||||||
return $attribute;
|
return $attribute;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,12 +85,12 @@
|
||||||
* Only runs if debug level is greater than zero.
|
* Only runs if debug level is greater than zero.
|
||||||
*
|
*
|
||||||
* @param boolean $var Variable to show debug information for.
|
* @param boolean $var Variable to show debug information for.
|
||||||
* @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way.
|
* @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way.
|
||||||
* @param boolean $showFrom If set to true, the method prints from where the function was called.
|
* @param boolean $showFrom If set to true, the method prints from where the function was called.
|
||||||
* @link http://book.cakephp.org/view/1190/Basic-Debugging
|
* @link http://book.cakephp.org/view/1190/Basic-Debugging
|
||||||
* @link http://book.cakephp.org/view/1128/debug
|
* @link http://book.cakephp.org/view/1128/debug
|
||||||
*/
|
*/
|
||||||
function debug($var = false, $showHtml = false, $showFrom = true) {
|
function debug($var = false, $showHtml = null, $showFrom = true) {
|
||||||
if (Configure::read('debug') > 0) {
|
if (Configure::read('debug') > 0) {
|
||||||
$file = '';
|
$file = '';
|
||||||
$line = '';
|
$line = '';
|
||||||
|
@ -116,10 +116,14 @@ TEXT;
|
||||||
$template = $html;
|
$template = $html;
|
||||||
if (php_sapi_name() == 'cli') {
|
if (php_sapi_name() == 'cli') {
|
||||||
$template = $text;
|
$template = $text;
|
||||||
|
} else {
|
||||||
|
if ($showHtml === null) {
|
||||||
|
$showHtml = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$var = print_r($var, true);
|
$var = print_r($var, true);
|
||||||
if ($showHtml) {
|
if ($showHtml) {
|
||||||
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
$var = str_replace(array('<', '>'), array('<', '>'), $var);
|
||||||
}
|
}
|
||||||
printf($template, $file, $line, $var);
|
printf($template, $file, $line, $var);
|
||||||
}
|
}
|
||||||
|
|
|
@ -687,12 +687,20 @@ class BasicsTest extends CakeTestCase {
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
debug('<div>this-is-a-test</div>', true);
|
debug('<div>this-is-a-test</div>');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||||
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||||
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s';
|
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
debug('<div>this-is-a-test</div>', false);
|
||||||
|
$result = ob_get_clean();
|
||||||
|
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
|
||||||
|
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
|
||||||
|
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*\<div\>this-is-a-test\<\/div\>.*/s';
|
||||||
|
$this->assertPattern($pattern, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -751,6 +751,45 @@ class ControllerTest extends CakeTestCase {
|
||||||
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
|
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testPaginateMaxLimit
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testPaginateMaxLimit() {
|
||||||
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
$request->params['pass'] = $request->params['named'] = array();
|
||||||
|
|
||||||
|
$Controller = new Controller($request);
|
||||||
|
|
||||||
|
$Controller->uses = array('ControllerPost', 'ControllerComment');
|
||||||
|
$Controller->passedArgs[] = '1';
|
||||||
|
$Controller->params['url'] = array();
|
||||||
|
$Controller->constructClasses();
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
|
||||||
|
$result = $Controller->paginate('ControllerPost');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
|
||||||
|
$result = $Controller->paginate('ControllerPost');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '10');
|
||||||
|
$result = $Controller->paginate('ControllerPost');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 10);
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
|
||||||
|
$Controller->paginate = array('maxLimit' => 2000);
|
||||||
|
$result = $Controller->paginate('ControllerPost');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 1000);
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '5000');
|
||||||
|
$result = $Controller->paginate('ControllerPost');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 2000);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testPaginateFieldsDouble method
|
* testPaginateFieldsDouble method
|
||||||
*
|
*
|
||||||
|
@ -821,6 +860,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
'fields' => array(),
|
'fields' => array(),
|
||||||
'order' => '',
|
'order' => '',
|
||||||
'limit' => 5,
|
'limit' => 5,
|
||||||
|
'maxLimit' => 100,
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => array()
|
'conditions' => array()
|
||||||
|
|
|
@ -184,11 +184,41 @@ class TestHelper extends Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Html5TestHelper class
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases.libs.view
|
||||||
|
*/
|
||||||
|
class Html5TestHelper extends TestHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimized
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_minimizedAttributes = array('require', 'checked');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow compact use in HTML
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_minimizedAttributeFormat = '%s';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to attribute format
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_attributeFormat = 'data-%s="%s"';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HelperTest class
|
* HelperTest class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs
|
* @subpackage cake.tests.cases.libs.view
|
||||||
*/
|
*/
|
||||||
class HelperTest extends CakeTestCase {
|
class HelperTest extends CakeTestCase {
|
||||||
|
|
||||||
|
@ -809,6 +839,13 @@ class HelperTest extends CakeTestCase {
|
||||||
$this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value);
|
$this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->assertEqual($helper->parseAttributes(array('compact')), ' compact="compact"');
|
||||||
|
|
||||||
|
$helper = new Html5TestHelper($this->View);
|
||||||
|
$expected = ' require';
|
||||||
|
$this->assertEqual($helper->parseAttributes(array('require')), $expected);
|
||||||
|
$this->assertEqual($helper->parseAttributes(array('require' => true)), $expected);
|
||||||
|
$this->assertEqual($helper->parseAttributes(array('require' => false)), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue