mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Merge branch 'master' into 13920-validation-marks-valid-field-as-invalid
This commit is contained in:
@ -68,7 +68,7 @@ class BaseYii
|
||||
*/
|
||||
public static $classMap = [];
|
||||
/**
|
||||
* @var \yii\console\Application|\yii\web\Application|\yii\base\Application the application instance
|
||||
* @var \yii\console\Application|\yii\web\Application the application instance
|
||||
*/
|
||||
public static $app;
|
||||
/**
|
||||
|
||||
@ -5,6 +5,7 @@ Yii Framework 2 Change Log
|
||||
------------------------
|
||||
|
||||
- Bug #13920: Fixed erroneous validation for specific cases (tim-fischer-maschinensucher)
|
||||
- Bug #19872: Fixed the definition of dirty attributes in AR properties for a non-associative array in case of changing the order of elements (eegusakov)
|
||||
- Bug #19899: Fixed `GridView` in some cases calling `Model::generateAttributeLabel()` to generate label values that are never used (PowerGamer1)
|
||||
- Bug #9899: Fix caching a MSSQL query with BLOB data type (terabytesoftw)
|
||||
- Bug #16208: Fix `yii\log\FileTarget` to not export empty messages (terabytesoftw)
|
||||
@ -16,6 +17,8 @@ Yii Framework 2 Change Log
|
||||
- Enh #19884: Added support Enums in Query Builder (sk1t0n)
|
||||
- Bug #19908: Fix associative array cell content rendering in Table widget (rhertogh)
|
||||
- Bug #19906: Fixed multiline strings in the `\yii\console\widgets\Table` widget (rhertogh)
|
||||
- Bug #19914: Fixed `ArrayHelper::keyExists()` and `::remove()` functions when the key is a float and the value is `null` (rhertogh)
|
||||
- Enh #19920: Broadened the accepted type of `Cookie::$expire` from `int` to `int|string|\DateTimeInterface|null` (rhertogh)
|
||||
|
||||
|
||||
2.0.48.1 May 24, 2023
|
||||
|
||||
@ -282,7 +282,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) {
|
||||
if (array_key_exists($name, $this->_attributes)) {
|
||||
return $this->_attributes[$name];
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) {
|
||||
if (array_key_exists($name, $this->_related)) {
|
||||
return $this->_related[$name];
|
||||
}
|
||||
$value = parent::__get($name);
|
||||
@ -1774,7 +1774,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
*/
|
||||
private function isValueDifferent($newValue, $oldValue)
|
||||
{
|
||||
if (is_array($newValue) && is_array($oldValue) && !ArrayHelper::isAssociative($oldValue)) {
|
||||
if (is_array($newValue) && is_array($oldValue) && ArrayHelper::isAssociative($oldValue)) {
|
||||
$newValue = ArrayHelper::recursiveSort($newValue);
|
||||
$oldValue = ArrayHelper::recursiveSort($oldValue);
|
||||
}
|
||||
|
||||
@ -327,7 +327,12 @@ class BaseArrayHelper
|
||||
*/
|
||||
public static function remove(&$array, $key, $default = null)
|
||||
{
|
||||
if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) {
|
||||
// ToDo: This check can be removed when the minimum PHP version is >= 8.1 (Yii2.2)
|
||||
if (is_float($key)) {
|
||||
$key = (int)$key;
|
||||
}
|
||||
|
||||
if (is_array($array) && array_key_exists($key, $array)) {
|
||||
$value = $array[$key];
|
||||
unset($array[$key]);
|
||||
|
||||
@ -608,17 +613,20 @@ class BaseArrayHelper
|
||||
* Checks if the given array contains the specified key.
|
||||
* This method enhances the `array_key_exists()` function by supporting case-insensitive
|
||||
* key comparison.
|
||||
* @param string $key the key to check
|
||||
* @param string|int $key the key to check
|
||||
* @param array|ArrayAccess $array the array with keys to check
|
||||
* @param bool $caseSensitive whether the key comparison should be case-sensitive
|
||||
* @return bool whether the array contains the specified key
|
||||
*/
|
||||
public static function keyExists($key, $array, $caseSensitive = true)
|
||||
{
|
||||
// ToDo: This check can be removed when the minimum PHP version is >= 8.1 (Yii2.2)
|
||||
if (is_float($key)) {
|
||||
$key = (int)$key;
|
||||
}
|
||||
|
||||
if ($caseSensitive) {
|
||||
// Function `isset` checks key faster but skips `null`, `array_key_exists` handles this case
|
||||
// https://www.php.net/manual/en/function.array-key-exists.php#107786
|
||||
if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) {
|
||||
if (is_array($array) && array_key_exists($key, $array)) {
|
||||
return true;
|
||||
}
|
||||
// Cannot use `array_has_key` on Objects for PHP 7.4+, therefore we need to check using [[ArrayAccess::offsetExists()]]
|
||||
|
||||
@ -57,8 +57,8 @@ class Cookie extends \yii\base\BaseObject
|
||||
*/
|
||||
public $domain = '';
|
||||
/**
|
||||
* @var int the timestamp at which the cookie expires. This is the server timestamp.
|
||||
* Defaults to 0, meaning "until the browser is closed".
|
||||
* @var int|string|\DateTimeInterface|null the timestamp or date at which the cookie expires. This is the server timestamp.
|
||||
* Defaults to 0, meaning "until the browser is closed" (the same applies to `null`).
|
||||
*/
|
||||
public $expire = 0;
|
||||
/**
|
||||
|
||||
@ -51,7 +51,7 @@ class CookieCollection extends BaseObject implements \IteratorAggregate, \ArrayA
|
||||
* Returns an iterator for traversing the cookies in the collection.
|
||||
* This method is required by the SPL interface [[\IteratorAggregate]].
|
||||
* It will be implicitly called when you use `foreach` to traverse the collection.
|
||||
* @return ArrayIterator an iterator for traversing the cookies in the collection.
|
||||
* @return ArrayIterator<string, Cookie> an iterator for traversing the cookies in the collection.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
@ -113,7 +113,18 @@ class CookieCollection extends BaseObject implements \IteratorAggregate, \ArrayA
|
||||
public function has($name)
|
||||
{
|
||||
return isset($this->_cookies[$name]) && $this->_cookies[$name]->value !== ''
|
||||
&& ($this->_cookies[$name]->expire === null || $this->_cookies[$name]->expire === 0 || $this->_cookies[$name]->expire >= time());
|
||||
&& ($this->_cookies[$name]->expire === null
|
||||
|| $this->_cookies[$name]->expire === 0
|
||||
|| (
|
||||
(is_string($this->_cookies[$name]->expire) && strtotime($this->_cookies[$name]->expire) >= time())
|
||||
|| (
|
||||
interface_exists('\\DateTimeInterface')
|
||||
&& $this->_cookies[$name]->expire instanceof \DateTimeInterface
|
||||
&& $this->_cookies[$name]->expire->getTimestamp() >= time()
|
||||
)
|
||||
|| $this->_cookies[$name]->expire >= time()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +185,7 @@ class CookieCollection extends BaseObject implements \IteratorAggregate, \ArrayA
|
||||
|
||||
/**
|
||||
* Returns the collection as a PHP array.
|
||||
* @return array the array representation of the collection.
|
||||
* @return Cookie[] the array representation of the collection.
|
||||
* The array keys are cookie names, and the array values are the corresponding cookie objects.
|
||||
*/
|
||||
public function toArray()
|
||||
|
||||
@ -401,12 +401,21 @@ class Response extends \yii\base\Response
|
||||
}
|
||||
foreach ($this->getCookies() as $cookie) {
|
||||
$value = $cookie->value;
|
||||
if ($cookie->expire != 1 && isset($validationKey)) {
|
||||
$expire = $cookie->expire;
|
||||
if (is_string($expire)) {
|
||||
$expire = strtotime($expire);
|
||||
} elseif (interface_exists('\\DateTimeInterface') && $expire instanceof \DateTimeInterface) {
|
||||
$expire = $expire->getTimestamp();
|
||||
}
|
||||
if ($expire === null || $expire === false) {
|
||||
$expire = 0;
|
||||
}
|
||||
if ($expire != 1 && isset($validationKey)) {
|
||||
$value = Yii::$app->getSecurity()->hashData(serialize([$cookie->name, $value]), $validationKey);
|
||||
}
|
||||
if (PHP_VERSION_ID >= 70300) {
|
||||
setcookie($cookie->name, $value, [
|
||||
'expires' => $cookie->expire,
|
||||
'expires' => $expire,
|
||||
'path' => $cookie->path,
|
||||
'domain' => $cookie->domain,
|
||||
'secure' => $cookie->secure,
|
||||
@ -420,7 +429,7 @@ class Response extends \yii\base\Response
|
||||
if (!is_null($cookie->sameSite)) {
|
||||
$cookiePath .= '; samesite=' . $cookie->sameSite;
|
||||
}
|
||||
setcookie($cookie->name, $value, $cookie->expire, $cookiePath, $cookie->domain, $cookie->secure, $cookie->httpOnly);
|
||||
setcookie($cookie->name, $value, $expire, $cookiePath, $cookie->domain, $cookie->secure, $cookie->httpOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user