1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MaksimM\CompositePrimaryKeys\Http\Traits; |
4
|
|
|
|
5
|
|
|
trait OptionalBinaryTransformation |
6
|
|
|
{ |
7
|
|
|
protected $hexBinaryColumns = false; |
8
|
|
|
|
9
|
|
|
private $shouldMutate = true; |
10
|
|
|
|
11
|
|
|
public function hexBinaryColumns() |
12
|
|
|
{ |
13
|
|
|
return $this->hexBinaryColumns; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function disableBinaryMutators() |
17
|
|
|
{ |
18
|
|
|
$this->shouldMutate = false; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function enableBinaryMutators() |
22
|
|
|
{ |
23
|
|
|
$this->shouldMutate = true; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function isAllowedToMutateBinaryAttributes() |
27
|
|
|
{ |
28
|
|
|
return $this->shouldMutate; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private function shouldProcessBinaryAttribute($key) |
32
|
|
|
{ |
33
|
|
|
return $this->hexBinaryColumns() && in_array($key, $this->getBinaryColumns()); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function hasGetMutator($key) |
37
|
|
|
{ |
38
|
|
|
if ($this->shouldProcessBinaryAttribute($key) && isset($this->{$key}) && $this->isAllowedToMutateBinaryAttributes()) { |
39
|
|
|
return true; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return parent::hasGetMutator($key); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function mutateAttribute($key, $value) |
46
|
|
|
{ |
47
|
|
|
if ($this->shouldProcessBinaryAttribute($key)) { |
48
|
|
|
return strtoupper(bin2hex($value)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return parent::mutateAttribute($key, $value); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function hasSetMutator($key) |
55
|
|
|
{ |
56
|
|
|
if ($this->shouldProcessBinaryAttribute($key) && $this->isAllowedToMutateBinaryAttributes()) { |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return parent::hasSetMutator($key); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setMutatedAttributeValue($key, $value) |
64
|
|
|
{ |
65
|
|
|
if ($this->shouldProcessBinaryAttribute($key)) { |
66
|
|
|
$value = hex2bin($value); |
67
|
|
|
$this->attributes[$key] = $value; |
|
|
|
|
68
|
|
|
|
69
|
|
|
return $value; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return parent::setMutatedAttributeValue($key, $value); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.