1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Famdirksen\LaravelModelEncryption; |
4
|
|
|
|
5
|
|
|
trait GDPRRegistration |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @param $key |
9
|
|
|
* |
10
|
|
|
* @return bool |
11
|
|
|
*/ |
12
|
|
|
public function isEncryptable($key) |
13
|
|
|
{ |
14
|
|
|
return in_array($key, $this->encryptable); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Decrypt a value. |
19
|
|
|
* |
20
|
|
|
* @param $value |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
protected function decryptAttribute($value) |
25
|
|
|
{ |
26
|
|
|
if ($value) { |
27
|
|
|
$value = decrypt($value); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $value; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Encrypt a value. |
35
|
|
|
* |
36
|
|
|
* @param $value |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
protected function encryptAttribute($value) |
41
|
|
|
{ |
42
|
|
|
if ($value) { |
43
|
|
|
$value = encrypt($value); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $value; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Extend the Eloquent method so properties present in |
51
|
|
|
* $encrypt are decrypted when directly accessed. |
52
|
|
|
* |
53
|
|
|
* @param $key The attribute key |
|
|
|
|
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getAttribute($key) |
58
|
|
|
{ |
59
|
|
|
$value = parent::getAttribute($key); |
60
|
|
|
|
61
|
|
|
if ($this->isEncryptable($key)) { |
62
|
|
|
$value = $this->decryptAttribute($value); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $value; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Extend the Eloquent method so properties present in |
70
|
|
|
* $encrypt are encrypted whenever they are set. |
71
|
|
|
* |
72
|
|
|
* @param $key The attribute key |
73
|
|
|
* @param $value Attribute value to set |
|
|
|
|
74
|
|
|
* |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public function setAttribute($key, $value) |
78
|
|
|
{ |
79
|
|
|
if ($this->isEncryptable($key)) { |
80
|
|
|
$value = $this->encryptAttribute($value); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return parent::setAttribute($key, $value); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Extend the Eloquent method so properties in |
88
|
|
|
* $encrypt are decrypted when toArray() |
89
|
|
|
* or toJson() is called. |
90
|
|
|
* |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function getArrayableAttributes() |
94
|
|
|
{ |
95
|
|
|
$attributes = parent::getArrayableAttributes(); |
96
|
|
|
|
97
|
|
|
foreach ($attributes as $key => $attribute) { |
98
|
|
|
if ($this->isEncryptable($key)) { |
99
|
|
|
$attributes[$key] = $this->decryptAttribute($attribute); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $attributes; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths