mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'master' into 2.5
This commit is contained in:
commit
99e4dbd827
5 changed files with 46 additions and 15 deletions
|
@ -72,7 +72,7 @@ class CakeEventManager {
|
|||
self::$_generalManager = $manager;
|
||||
}
|
||||
if (empty(self::$_generalManager)) {
|
||||
self::$_generalManager = new CakeEventManager;
|
||||
self::$_generalManager = new CakeEventManager();
|
||||
}
|
||||
|
||||
self::$_generalManager->_isGlobal = true;
|
||||
|
@ -249,7 +249,6 @@ class CakeEventManager {
|
|||
if ($result !== null) {
|
||||
$event->result = $result;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ class CakeRequest implements ArrayAccess {
|
|||
* Get the IP the client is using, or says they are using.
|
||||
*
|
||||
* @param boolean $safe Use safe = false when you think the user might manipulate their HTTP_CLIENT_IP
|
||||
* header. Setting $safe = false will will also look at HTTP_X_FORWARDED_FOR
|
||||
* header. Setting $safe = false will also look at HTTP_X_FORWARDED_FOR
|
||||
* @return string The client IP.
|
||||
*/
|
||||
public function clientIp($safe = true) {
|
||||
|
@ -417,10 +417,6 @@ class CakeRequest implements ArrayAccess {
|
|||
*/
|
||||
public function referer($local = false) {
|
||||
$ref = env('HTTP_REFERER');
|
||||
$forwarded = env('HTTP_X_FORWARDED_HOST');
|
||||
if ($forwarded) {
|
||||
$ref = $forwarded;
|
||||
}
|
||||
|
||||
$base = Configure::read('App.fullBaseUrl') . $this->webroot;
|
||||
if (!empty($ref) && !empty($base)) {
|
||||
|
@ -678,9 +674,13 @@ class CakeRequest implements ArrayAccess {
|
|||
/**
|
||||
* Get the host that the request was handled on.
|
||||
*
|
||||
* @param boolean $trustProxy Whether or not to trust the proxy host.
|
||||
* @return string
|
||||
*/
|
||||
public function host() {
|
||||
public function host($trustProxy = false) {
|
||||
if ($trustProxy) {
|
||||
return env('HTTP_X_FORWARDED_HOST');
|
||||
}
|
||||
return env('HTTP_HOST');
|
||||
}
|
||||
|
||||
|
|
|
@ -698,10 +698,6 @@ class CakeRequestTest extends CakeTestCase {
|
|||
$_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/recipes/add';
|
||||
$result = $request->referer(true);
|
||||
$this->assertSame($result, '/recipes/add');
|
||||
|
||||
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
|
||||
$result = $request->referer();
|
||||
$this->assertSame($result, 'cakephp.org');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,9 +800,11 @@ class CakeRequestTest extends CakeTestCase {
|
|||
*/
|
||||
public function testHost() {
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
|
||||
$request = new CakeRequest('some/path');
|
||||
|
||||
$this->assertEquals('localhost', $request->host());
|
||||
$this->assertEquals('cakephp.org', $request->host(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1527,6 +1527,34 @@ class HashTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test combine() giving errors on key/value length mismatches.
|
||||
*
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
public function testCombineErrorMissingValue() {
|
||||
$data = array(
|
||||
array('User' => array('id' => 1, 'name' => 'mark')),
|
||||
array('User' => array('name' => 'jose')),
|
||||
);
|
||||
Hash::combine($data, '{n}.User.id', '{n}.User.name');
|
||||
}
|
||||
|
||||
/**
|
||||
* test combine() giving errors on key/value length mismatches.
|
||||
*
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
public function testCombineErrorMissingKey() {
|
||||
$data = array(
|
||||
array('User' => array('id' => 1, 'name' => 'mark')),
|
||||
array('User' => array('id' => 2)),
|
||||
);
|
||||
Hash::combine($data, '{n}.User.id', '{n}.User.name');
|
||||
}
|
||||
|
||||
/**
|
||||
* test combine() with a group path.
|
||||
*
|
||||
|
|
|
@ -365,6 +365,7 @@ class Hash {
|
|||
* @param string $groupPath A dot-separated string.
|
||||
* @return array Combined array
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::combine
|
||||
* @throws CakeException CakeException When keys and values count is unequal.
|
||||
*/
|
||||
public static function combine(array $data, $keyPath, $valuePath = null, $groupPath = null) {
|
||||
if (empty($data)) {
|
||||
|
@ -387,10 +388,15 @@ class Hash {
|
|||
} elseif (!empty($valuePath)) {
|
||||
$vals = self::extract($data, $valuePath);
|
||||
}
|
||||
if (empty($vals)) {
|
||||
$vals = array_fill(0, count($keys), null);
|
||||
}
|
||||
|
||||
$count = count($keys);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$vals[$i] = isset($vals[$i]) ? $vals[$i] : null;
|
||||
if (count($keys) !== count($vals)) {
|
||||
throw new CakeException(__d(
|
||||
'cake_dev',
|
||||
'Hash::combine() needs an equal number of keys + values.'
|
||||
));
|
||||
}
|
||||
|
||||
if ($groupPath !== null) {
|
||||
|
|
Loading…
Reference in a new issue