mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '2.1' of github.com:cakephp/cakephp into 2.1
This commit is contained in:
commit
b62d9729a9
6 changed files with 102 additions and 75 deletions
|
@ -86,13 +86,12 @@ class <?php echo $fullClassName; ?>TestCase extends CakeTestCase {
|
|||
|
||||
<?php foreach ($methods as $method): ?>
|
||||
/**
|
||||
* test<?php echo Inflector::classify($method); ?> method
|
||||
* test<?php echo Inflector::camelize($method); ?> method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test<?php echo Inflector::classify($method); ?>() {
|
||||
public function test<?php echo Inflector::camelize($method); ?>() {
|
||||
|
||||
}
|
||||
|
||||
<?php endforeach;?>
|
||||
}
|
||||
|
|
|
@ -124,26 +124,12 @@ class Configure {
|
|||
}
|
||||
|
||||
foreach ($config as $name => $value) {
|
||||
if (strpos($name, '.') === false) {
|
||||
self::$_values[$name] = $value;
|
||||
} else {
|
||||
$names = explode('.', $name, 4);
|
||||
switch (count($names)) {
|
||||
case 2:
|
||||
self::$_values[$names[0]][$names[1]] = $value;
|
||||
break;
|
||||
case 3:
|
||||
self::$_values[$names[0]][$names[1]][$names[2]] = $value;
|
||||
break;
|
||||
case 4:
|
||||
$names = explode('.', $name, 2);
|
||||
if (!isset(self::$_values[$names[0]])) {
|
||||
self::$_values[$names[0]] = array();
|
||||
}
|
||||
self::$_values[$names[0]] = Set::insert(self::$_values[$names[0]], $names[1], $value);
|
||||
break;
|
||||
}
|
||||
$pointer = &self::$_values;
|
||||
foreach (explode('.', $name) as $key) {
|
||||
$pointer = &$pointer[$key];
|
||||
}
|
||||
$pointer = $value;
|
||||
unset($pointer);
|
||||
}
|
||||
|
||||
if (isset($config['debug']) && function_exists('ini_set')) {
|
||||
|
@ -177,30 +163,15 @@ class Configure {
|
|||
if (isset(self::$_values[$var])) {
|
||||
return self::$_values[$var];
|
||||
}
|
||||
if (strpos($var, '.') !== false) {
|
||||
$names = explode('.', $var, 3);
|
||||
$var = $names[0];
|
||||
$pointer = &self::$_values;
|
||||
foreach (explode('.', $var) as $key) {
|
||||
if (isset($pointer[$key])) {
|
||||
$pointer = &$pointer[$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!isset(self::$_values[$var])) {
|
||||
return null;
|
||||
}
|
||||
switch (count($names)) {
|
||||
case 2:
|
||||
if (isset(self::$_values[$var][$names[1]])) {
|
||||
return self::$_values[$var][$names[1]];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (isset(self::$_values[$var][$names[1]][$names[2]])) {
|
||||
return self::$_values[$var][$names[1]][$names[2]];
|
||||
}
|
||||
if (!isset(self::$_values[$var][$names[1]])) {
|
||||
return null;
|
||||
}
|
||||
return Set::classicExtract(self::$_values[$var][$names[1]], $names[2]);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
return $pointer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,13 +188,13 @@ class Configure {
|
|||
* @return void
|
||||
*/
|
||||
public static function delete($var = null) {
|
||||
if (strpos($var, '.') === false) {
|
||||
unset(self::$_values[$var]);
|
||||
return;
|
||||
$keys = explode('.', $var);
|
||||
$last = array_pop($keys);
|
||||
$pointer = &self::$_values;
|
||||
foreach ($keys as $key) {
|
||||
$pointer = &$pointer[$key];
|
||||
}
|
||||
|
||||
$names = explode('.', $var, 2);
|
||||
self::$_values[$names[0]] = Set::remove(self::$_values[$names[0]], $names[1]);
|
||||
unset($pointer[$last]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2368,7 +2368,7 @@ class DboSource extends DataSource {
|
|||
$keys = array_keys($value);
|
||||
if ($keys === array_values($keys)) {
|
||||
$count = count($value);
|
||||
if ($count === 1) {
|
||||
if ($count === 1 && !preg_match("/\s+NOT$/", $key)) {
|
||||
$data = $this->_quoteFields($key) . ' = (';
|
||||
} else {
|
||||
$data = $this->_quoteFields($key) . ' IN (';
|
||||
|
|
|
@ -447,6 +447,7 @@ class Model extends Object implements CakeEventListener {
|
|||
* - `unique`: If true (default value) cake will first delete existing relationship
|
||||
* records in the foreign keys table before inserting new ones, when updating a
|
||||
* record. So existing associations need to be passed again when updating.
|
||||
* To prevent deletion of existing relationship records, set this key to a string 'keepExisting'.
|
||||
* - `conditions`: An SQL fragment used to filter related model records. It's good
|
||||
* practice to use model names in SQL fragments: "Comment.status = 1" is always
|
||||
* better than just "status = 1."
|
||||
|
@ -2034,7 +2035,7 @@ class Model extends Object implements CakeEventListener {
|
|||
|
||||
if ($options['atomic']) {
|
||||
$db = $this->getDataSource();
|
||||
$transactionBegun = $db->begin($this);
|
||||
$transactionBegun = $db->begin();
|
||||
}
|
||||
$return = array();
|
||||
foreach ($data as $key => $record) {
|
||||
|
@ -2055,12 +2056,12 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
if ($validates) {
|
||||
if ($transactionBegun) {
|
||||
return $db->commit($this) !== false;
|
||||
return $db->commit() !== false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$db->rollback($this);
|
||||
$db->rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2138,7 +2139,7 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
if ($options['atomic']) {
|
||||
$db = $this->getDataSource();
|
||||
$transactionBegun = $db->begin($this);
|
||||
$transactionBegun = $db->begin();
|
||||
}
|
||||
$associations = $this->getAssociated();
|
||||
$return = array();
|
||||
|
@ -2200,12 +2201,12 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
if ($validates) {
|
||||
if ($transactionBegun) {
|
||||
return $db->commit($this) !== false;
|
||||
return $db->commit() !== false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$db->rollback($this);
|
||||
$db->rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3200,10 +3201,6 @@ class Model extends Object implements CakeEventListener {
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
if (empty($this->id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->id[$list]) && !empty($this->id[$list])) {
|
||||
return $this->id[$list];
|
||||
} elseif (isset($this->id[$list])) {
|
||||
|
|
|
@ -160,14 +160,33 @@ class Router {
|
|||
protected static $_routeClass = 'CakeRoute';
|
||||
|
||||
/**
|
||||
* Set the default rotue class to use
|
||||
* Set the default route class to use or return the current one
|
||||
*
|
||||
* @param sting $routeClass to set as default
|
||||
* @return void
|
||||
* @param string $routeClass to set as default
|
||||
* @return mixed void|string
|
||||
* @throws RouterException
|
||||
*/
|
||||
public static function defaultRouteClass($routeClass) {
|
||||
self::$_routeClass = $routeClass;
|
||||
}
|
||||
public static function defaultRouteClass($routeClass = null) {
|
||||
if (is_null($routeClass)) {
|
||||
return self::$_routeClass;
|
||||
}
|
||||
|
||||
self::$_routeClass = self::_validateRouteClass($routeClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the passed route class exists and is a subclass of CakeRoute
|
||||
*
|
||||
* @param $routeClass
|
||||
* @return string
|
||||
* @throws RouterException
|
||||
*/
|
||||
protected static function _validateRouteClass($routeClass) {
|
||||
if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) {
|
||||
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
|
||||
}
|
||||
return $routeClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Routing prefixes.
|
||||
|
@ -278,14 +297,11 @@ class Router {
|
|||
}
|
||||
$routeClass = self::$_routeClass;
|
||||
if (isset($options['routeClass'])) {
|
||||
$routeClass = $options['routeClass'];
|
||||
if (!is_subclass_of($routeClass, 'CakeRoute')) {
|
||||
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
|
||||
}
|
||||
$routeClass = self::_validateRouteClass($options['routeClass']);
|
||||
unset($options['routeClass']);
|
||||
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
|
||||
$defaults = $defaults['redirect'];
|
||||
}
|
||||
}
|
||||
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
|
||||
$defaults = $defaults['redirect'];
|
||||
}
|
||||
self::$routes[] = new $routeClass($route, $defaults, $options);
|
||||
return self::$routes;
|
||||
|
|
|
@ -2519,4 +2519,48 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertInstanceOf('TestDefaultRouteClass', $result[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the default route class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultRouteClassGetter() {
|
||||
$routeClass = 'TestDefaultRouteClass';
|
||||
Router::defaultRouteClass($routeClass);
|
||||
|
||||
$this->assertEqual($routeClass, Router::defaultRouteClass());
|
||||
$this->assertEqual($routeClass, Router::defaultRouteClass(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that route classes must extend CakeRoute
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultRouteException() {
|
||||
Router::defaultRouteClass('');
|
||||
Router::connect('/:controller', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that route classes must extend CakeRoute
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingInvalidDefaultRouteException() {
|
||||
Router::defaultRouteClass('Object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that class must exist
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingNonExistentDefaultRouteException() {
|
||||
Router::defaultRouteClass('NonExistentClass');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue