mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Merge commit 'origin/1.3' into 1.3-form
This commit is contained in:
commit
1f1e0f4ff7
9 changed files with 104 additions and 58 deletions
|
@ -1,5 +1,6 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// +--------------------------------------------------------------------------------------------+ // // CakePHP Version
|
// +--------------------------------------------------------------------------------------------+ //
|
||||||
|
// CakePHP Version
|
||||||
//
|
//
|
||||||
// Holds a static string representing the current version of CakePHP
|
// Holds a static string representing the current version of CakePHP
|
||||||
//
|
//
|
||||||
|
|
|
@ -264,10 +264,13 @@ class ShellDispatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
|
||||||
|
|
||||||
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
||||||
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
||||||
|
App::build();
|
||||||
}
|
}
|
||||||
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,9 +289,10 @@ class ViewTask extends Shell {
|
||||||
}
|
}
|
||||||
$controllerClassName = $this->controllerName . 'Controller';
|
$controllerClassName = $this->controllerName . 'Controller';
|
||||||
$controllerObj =& new $controllerClassName();
|
$controllerObj =& new $controllerClassName();
|
||||||
|
$controllerObj->plugin = $this->plugin;
|
||||||
$controllerObj->constructClasses();
|
$controllerObj->constructClasses();
|
||||||
$modelClass = $controllerObj->modelClass;
|
$modelClass = $controllerObj->modelClass;
|
||||||
$modelObj =& ClassRegistry::getObject($controllerObj->modelKey);
|
$modelObj =& $controllerObj->{$controllerObj->modelClass};
|
||||||
|
|
||||||
if ($modelObj) {
|
if ($modelObj) {
|
||||||
$primaryKey = $modelObj->primaryKey;
|
$primaryKey = $modelObj->primaryKey;
|
||||||
|
@ -302,13 +303,10 @@ class ViewTask extends Shell {
|
||||||
$fields = array_keys($schema);
|
$fields = array_keys($schema);
|
||||||
$associations = $this->__associations($modelObj);
|
$associations = $this->__associations($modelObj);
|
||||||
} else {
|
} else {
|
||||||
$primaryKey = null;
|
$primaryKey = $displayField = null;
|
||||||
$displayField = null;
|
|
||||||
$singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
|
$singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
|
||||||
$singularHumanName = $this->_singularHumanName($this->controllerName);
|
$singularHumanName = $this->_singularHumanName($this->controllerName);
|
||||||
$fields = array();
|
$fields = $schema = $associations = array();
|
||||||
$schema = array();
|
|
||||||
$associations = array();
|
|
||||||
}
|
}
|
||||||
$pluralVar = Inflector::variable($this->controllerName);
|
$pluralVar = Inflector::variable($this->controllerName);
|
||||||
$pluralHumanName = $this->_pluralHumanName($this->controllerName);
|
$pluralHumanName = $this->_pluralHumanName($this->controllerName);
|
||||||
|
|
|
@ -56,9 +56,15 @@ if (!empty($validate)):
|
||||||
echo "\t);\n";
|
echo "\t);\n";
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
foreach ($associations as $assoc):
|
||||||
|
if (!empty($assoc)):
|
||||||
?>
|
?>
|
||||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||||
<?php
|
<?php
|
||||||
|
break;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
foreach (array('hasOne', 'belongsTo') as $assocType):
|
foreach (array('hasOne', 'belongsTo') as $assocType):
|
||||||
if (!empty($associations[$assocType])):
|
if (!empty($associations[$assocType])):
|
||||||
$typeCount = count($associations[$assocType]);
|
$typeCount = count($associations[$assocType]);
|
||||||
|
|
|
@ -484,26 +484,26 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
$cacheKey = crc32($data);
|
$cacheKey = crc32($this->startQuote.$data.$this->endQuote);
|
||||||
if (isset($this->methodCache[__FUNCTION__][$cacheKey])) {
|
if (isset($this->methodCache[__FUNCTION__][$cacheKey])) {
|
||||||
return $this->methodCache[__FUNCTION__][$cacheKey];
|
return $this->methodCache[__FUNCTION__][$cacheKey];
|
||||||
}
|
}
|
||||||
$data = trim($data);
|
$data = trim($data);
|
||||||
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
|
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
|
||||||
if (strpos($data, '.') === false) { // string
|
if (strpos($data, '.') === false) { // string
|
||||||
return $this->startQuote . $data . $this->endQuote;
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . $data . $this->endQuote;
|
||||||
}
|
}
|
||||||
$items = explode('.', $data);
|
$items = explode('.', $data);
|
||||||
return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
|
||||||
}
|
}
|
||||||
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
|
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
|
||||||
return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
|
||||||
}
|
}
|
||||||
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
|
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
|
||||||
return $matches[1] . '(' . $this->name($matches[2]) . ')';
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $matches[1] . '(' . $this->name($matches[2]) . ')';
|
||||||
}
|
}
|
||||||
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) {
|
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) {
|
||||||
return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
|
return $this->methodCache[__FUNCTION__][$cacheKey] = preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
|
||||||
}
|
}
|
||||||
return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2105,9 +2105,6 @@ class Model extends Overloadable {
|
||||||
function _findFirst($state, $query, $results = array()) {
|
function _findFirst($state, $query, $results = array()) {
|
||||||
if ($state == 'before') {
|
if ($state == 'before') {
|
||||||
$query['limit'] = 1;
|
$query['limit'] = 1;
|
||||||
if (empty($query['conditions']) && !empty($this->id)) {
|
|
||||||
$query['conditions'] = array($this->escapeField() => $this->id);
|
|
||||||
}
|
|
||||||
return $query;
|
return $query;
|
||||||
} elseif ($state == 'after') {
|
} elseif ($state == 'after') {
|
||||||
if (empty($results[0])) {
|
if (empty($results[0])) {
|
||||||
|
|
|
@ -698,8 +698,8 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($options['type'])) {
|
if (!isset($options['type'])) {
|
||||||
|
$magicType = true;
|
||||||
$options['type'] = 'text';
|
$options['type'] = 'text';
|
||||||
$fieldDef = array();
|
|
||||||
if (isset($options['options'])) {
|
if (isset($options['options'])) {
|
||||||
$options['type'] = 'select';
|
$options['type'] = 'select';
|
||||||
} elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) {
|
} elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) {
|
||||||
|
@ -740,13 +740,19 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
$types = array('checkbox', 'radio', 'select');
|
$types = array('checkbox', 'radio', 'select');
|
||||||
|
|
||||||
if (!isset($options['options']) && in_array($options['type'], $types)) {
|
if (
|
||||||
|
(!isset($options['options']) && in_array($options['type'], $types)) ||
|
||||||
|
(isset($magicType) && $options['type'] == 'text')
|
||||||
|
) {
|
||||||
$view =& ClassRegistry::getObject('view');
|
$view =& ClassRegistry::getObject('view');
|
||||||
$varName = Inflector::variable(
|
$varName = Inflector::variable(
|
||||||
Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey))
|
Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey))
|
||||||
);
|
);
|
||||||
$varOptions = $view->getVar($varName);
|
$varOptions = $view->getVar($varName);
|
||||||
if (is_array($varOptions)) {
|
if (is_array($varOptions)) {
|
||||||
|
if ($options['type'] !== 'radio') {
|
||||||
|
$options['type'] = 'select';
|
||||||
|
}
|
||||||
$options['options'] = $varOptions;
|
$options['options'] = $varOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,13 +765,9 @@ class FormHelper extends AppHelper {
|
||||||
$options['maxlength'] = array_sum(explode(',', $fieldDef['length']))+1;
|
$options['maxlength'] = array_sum(explode(',', $fieldDef['length']))+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$div = true;
|
|
||||||
$divOptions = array();
|
$divOptions = array();
|
||||||
|
$div = $this->_extractOption('div', $options, true);
|
||||||
if (array_key_exists('div', $options)) {
|
unset($options['div']);
|
||||||
$div = $options['div'];
|
|
||||||
unset($options['div']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($div)) {
|
if (!empty($div)) {
|
||||||
$divOptions['class'] = 'input';
|
$divOptions['class'] = 'input';
|
||||||
|
@ -778,7 +780,7 @@ class FormHelper extends AppHelper {
|
||||||
if (
|
if (
|
||||||
isset($this->fieldset[$modelKey]) &&
|
isset($this->fieldset[$modelKey]) &&
|
||||||
in_array($fieldKey, $this->fieldset[$modelKey]['validates'])
|
in_array($fieldKey, $this->fieldset[$modelKey]['validates'])
|
||||||
) {
|
) {
|
||||||
$divOptions = $this->addClass($divOptions, 'required');
|
$divOptions = $this->addClass($divOptions, 'required');
|
||||||
}
|
}
|
||||||
if (!isset($divOptions['tag'])) {
|
if (!isset($divOptions['tag'])) {
|
||||||
|
@ -795,11 +797,7 @@ class FormHelper extends AppHelper {
|
||||||
if ($options['type'] === 'radio') {
|
if ($options['type'] === 'radio') {
|
||||||
$label = false;
|
$label = false;
|
||||||
if (isset($options['options'])) {
|
if (isset($options['options'])) {
|
||||||
if (is_array($options['options'])) {
|
$radioOptions = (array)$options['options'];
|
||||||
$radioOptions = $options['options'];
|
|
||||||
} else {
|
|
||||||
$radioOptions = array($options['options']);
|
|
||||||
}
|
|
||||||
unset($options['options']);
|
unset($options['options']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -833,36 +831,24 @@ class FormHelper extends AppHelper {
|
||||||
$label = $this->label($fieldName, $labelText, $labelAttributes);
|
$label = $this->label($fieldName, $labelText, $labelAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = null;
|
$error = $this->_extractOption('error', $options, null);
|
||||||
if (isset($options['error'])) {
|
unset($options['error']);
|
||||||
$error = $options['error'];
|
|
||||||
unset($options['error']);
|
$selected = $this->_extractOption('selected', $options, null);
|
||||||
}
|
unset($options['selected']);
|
||||||
|
|
||||||
$selected = null;
|
|
||||||
if (array_key_exists('selected', $options)) {
|
|
||||||
$selected = $options['selected'];
|
|
||||||
unset($options['selected']);
|
|
||||||
}
|
|
||||||
if (isset($options['rows']) || isset($options['cols'])) {
|
if (isset($options['rows']) || isset($options['cols'])) {
|
||||||
$options['type'] = 'textarea';
|
$options['type'] = 'textarea';
|
||||||
}
|
}
|
||||||
|
|
||||||
$timeFormat = 12;
|
|
||||||
if (isset($options['timeFormat'])) {
|
|
||||||
$timeFormat = $options['timeFormat'];
|
|
||||||
unset($options['timeFormat']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dateFormat = 'MDY';
|
|
||||||
if (isset($options['dateFormat'])) {
|
|
||||||
$dateFormat = $options['dateFormat'];
|
|
||||||
unset($options['dateFormat']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time' || $options['type'] === 'select') {
|
if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time' || $options['type'] === 'select') {
|
||||||
$options += array('empty' => false);
|
$options += array('empty' => false);
|
||||||
}
|
}
|
||||||
|
if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time') {
|
||||||
|
$dateFormat = $this->_extractOption('dateFormat', $options, 'MDY');
|
||||||
|
$timeFormat = $this->_extractOption('timeFormat', $options, 12);
|
||||||
|
unset($options['dateFormat'], $options['timeFormat']);
|
||||||
|
}
|
||||||
|
|
||||||
$type = $options['type'];
|
$type = $options['type'];
|
||||||
$out = array_merge(
|
$out = array_merge(
|
||||||
|
@ -938,6 +924,22 @@ class FormHelper extends AppHelper {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts a single option from an options array.
|
||||||
|
*
|
||||||
|
* @param string $name The name of the option to pull out.
|
||||||
|
* @param array $options The array of options you want to extract.
|
||||||
|
* @param mixed $default The default option value
|
||||||
|
* @return the contents of the option or default
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
function _extractOption($name, $options, $default = null) {
|
||||||
|
if (array_key_exists($name, $options)) {
|
||||||
|
return $options[$name];
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a checkbox input widget.
|
* Creates a checkbox input widget.
|
||||||
*
|
*
|
||||||
|
@ -1224,13 +1226,24 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a submit button element.
|
* Creates a submit button element. This method will generate `<input />` elements that
|
||||||
|
* can be used to submit, and reset forms by using $options. image submits can be created by supplying an
|
||||||
|
* image path for $caption.
|
||||||
|
*
|
||||||
|
* ### Options
|
||||||
|
*
|
||||||
|
* - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to
|
||||||
|
* FormHelper::input().
|
||||||
|
* - `before` - Content to include before the input.
|
||||||
|
* - `after` - Content to include after the input.
|
||||||
|
* - `type` - Set to 'reset' for reset inputs. Defaults to 'submit'
|
||||||
|
* - Other attributes will be assigned to the input element.
|
||||||
*
|
*
|
||||||
* @param string $caption The label appearing on the button OR if string contains :// or the
|
* @param string $caption The label appearing on the button OR if string contains :// or the
|
||||||
* extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension
|
* extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension
|
||||||
* exists, AND the first character is /, image is relative to webroot,
|
* exists, AND the first character is /, image is relative to webroot,
|
||||||
* OR if the first character is not /, image is relative to webroot/img.
|
* OR if the first character is not /, image is relative to webroot/img.
|
||||||
* @param array $options
|
* @param array $options Array of options. See above.
|
||||||
* @return string A HTML submit button
|
* @return string A HTML submit button
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4857,6 +4857,7 @@ class ModelReadTest extends BaseModelTest {
|
||||||
* Tests that the database configuration assigned to the model can be changed using
|
* Tests that the database configuration assigned to the model can be changed using
|
||||||
* (before|after)Find callbacks
|
* (before|after)Find callbacks
|
||||||
*
|
*
|
||||||
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testCallbackSourceChange() {
|
function testCallbackSourceChange() {
|
||||||
|
@ -4865,9 +4866,6 @@ class ModelReadTest extends BaseModelTest {
|
||||||
$this->assertEqual(3, count($TestModel->find('all')));
|
$this->assertEqual(3, count($TestModel->find('all')));
|
||||||
|
|
||||||
$this->expectError(new PatternExpectation('/Non-existent data source foo/i'));
|
$this->expectError(new PatternExpectation('/Non-existent data source foo/i'));
|
||||||
if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50300) {
|
|
||||||
$this->expectError(new PatternExpectation('/Only variable references/i'));
|
|
||||||
}
|
|
||||||
$this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
|
$this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6380,6 +6378,21 @@ class ModelReadTest extends BaseModelTest {
|
||||||
$this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']);
|
$this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that find('first') does not use the id set to the object.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testFindFirstNoIdUsed() {
|
||||||
|
$this->loadFixtures('Project');
|
||||||
|
|
||||||
|
$Project =& new Project();
|
||||||
|
$Project->id = 3;
|
||||||
|
$result = $Project->find('first');
|
||||||
|
|
||||||
|
$this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test find with COUNT(DISTINCT field)
|
* test find with COUNT(DISTINCT field)
|
||||||
*
|
*
|
||||||
|
|
|
@ -2063,6 +2063,21 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
//Check that magic types still work for plural/singular vars
|
||||||
|
$view =& ClassRegistry::getObject('view');
|
||||||
|
$view->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
|
||||||
|
$result = $this->Form->input('Model.type');
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input select'),
|
||||||
|
'label' => array('for' => 'ModelType'), 'Type', '/label',
|
||||||
|
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
|
||||||
|
array('option' => array('value' => 'value')), 'good', '/option',
|
||||||
|
array('option' => array('value' => 'other')), 'bad', '/option',
|
||||||
|
'/select',
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue