Skip to content

Commit fdc5a12

Browse files
author
Niels Oostindiër
committed
Fix isDirty marking for L7. This breaks compatibility with L6 and lower.
1 parent 05c6da2 commit fdc5a12

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@
5555
},
5656
"require": {
5757
"php": ">=7.1.0",
58-
"laravel/framework": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0"
58+
"laravel/framework": "^7.0"
5959
},
6060
"require-dev": {
61-
"codeclimate/php-test-reporter": "dev-master",
6261
"phpunit/phpunit": "^6.0|^7.0|^8.0",
63-
"orchestra/testbench": "^3.5|^4.0"
62+
"orchestra/testbench": "^5.0|^6.0"
6463
},
6564
"autoload": {
6665
"psr-4": {

src/Traits/HasEncryptedAttributes.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use AustinHeap\Database\Encryption\EncryptionFacade as DatabaseEncryption;
1313
use Illuminate\Contracts\Encryption\DecryptException;
1414
use Illuminate\Contracts\Encryption\EncryptException;
15+
use Illuminate\Support\Arr;
1516
use Illuminate\Support\Facades\Crypt;
1617
use Illuminate\Support\Facades\Log;
1718

@@ -286,6 +287,48 @@ public function getDirty()
286287
return $dirty;
287288
}
288289

290+
/**
291+
* Determine if the new and old values for a given key are equivalent.
292+
*
293+
* @param string $key
294+
* @return bool
295+
*/
296+
public function originalIsEquivalent($key)
297+
{
298+
if (! array_key_exists($key, $this->original)) {
299+
return false;
300+
}
301+
302+
// Unfortunately this method isn't single responsibility, it retrieves and compares attributes,
303+
// therefore we have to copy the whole thing just to change the behaviour of one of its responsibilities.
304+
$attribute = $this->doDecryptAttribute($key, Arr::get($this->attributes, $key));
305+
$original = Arr::get($this->original, $key);
306+
307+
if ($attribute === $original) {
308+
return true;
309+
} elseif (is_null($attribute)) {
310+
return false;
311+
} elseif ($this->isDateAttribute($key)) {
312+
return $this->fromDateTime($attribute) ===
313+
$this->fromDateTime($original);
314+
} elseif ($this->hasCast($key, ['object', 'collection'])) {
315+
return $this->castAttribute($key, $attribute) ==
316+
$this->castAttribute($key, $original);
317+
} elseif ($this->hasCast($key, ['real', 'float', 'double'])) {
318+
if (($attribute === null && $original !== null) || ($attribute !== null && $original === null)) {
319+
return false;
320+
}
321+
322+
return abs($this->castAttribute($key, $attribute) - $this->castAttribute($key, $original)) < PHP_FLOAT_EPSILON * 4;
323+
} elseif ($this->hasCast($key, static::$primitiveCastTypes)) {
324+
return $this->castAttribute($key, $attribute) ===
325+
$this->castAttribute($key, $original);
326+
}
327+
328+
return is_numeric($attribute) && is_numeric($original)
329+
&& strcmp((string) $attribute, (string) $original) === 0;
330+
}
331+
289332
/**
290333
* Set a given attribute on the model.
291334
*

0 commit comments

Comments
 (0)