mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-07 20:12:42 +00:00
Fix cookie component being inconsistent about writes.
Instead of treating multi-key and single key writes differently, they should be treated consistently to allow simpler and more consistent interactions with the stored data. This also results in fewer cookies being sent across the wire which is an added benefit. Fixes #2182
This commit is contained in:
parent
eef2d919af
commit
07f4779efe
2 changed files with 57 additions and 9 deletions
|
@ -230,17 +230,27 @@ class CookieComponent extends Component {
|
|||
}
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
if (strpos($name, '.') === false) {
|
||||
$this->_values[$this->name][$name] = $value;
|
||||
$this->_write("[$name]", $value);
|
||||
} else {
|
||||
$names = array($name);
|
||||
if (strpos($name, '.') !== false) {
|
||||
$names = explode('.', $name, 2);
|
||||
if (!isset($this->_values[$this->name][$names[0]])) {
|
||||
$this->_values[$this->name][$names[0]] = array();
|
||||
}
|
||||
$this->_values[$this->name][$names[0]] = Hash::insert($this->_values[$this->name][$names[0]], $names[1], $value);
|
||||
$this->_write('[' . implode('][', $names) . ']', $value);
|
||||
}
|
||||
$firstName = $names[0];
|
||||
$isMultiValue = (is_array($value) || count($names) > 1);
|
||||
|
||||
if (!isset($this->_values[$this->name][$firstName]) && $isMultiValue) {
|
||||
$this->_values[$this->name][$firstName] = array();
|
||||
}
|
||||
|
||||
if (count($names) > 1) {
|
||||
$this->_values[$this->name][$firstName] = Hash::insert(
|
||||
$this->_values[$this->name][$firstName],
|
||||
$names[1],
|
||||
$value
|
||||
);
|
||||
} else {
|
||||
$this->_values[$this->name][$firstName] = $value;
|
||||
}
|
||||
$this->_write('[' . $firstName . ']', $this->_values[$this->name][$firstName]);
|
||||
}
|
||||
$this->_encrypted = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue