1 | <?php |
||
14 | class ActivityLogger |
||
15 | { |
||
16 | use Macroable; |
||
17 | |||
18 | /** @var \Illuminate\Auth\AuthManager */ |
||
19 | protected $auth; |
||
20 | |||
21 | protected $defaultLogName = ''; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $authDriver; |
||
25 | |||
26 | /** @var \Spatie\Activitylog\ActivityLogStatus */ |
||
27 | protected $logStatus; |
||
28 | |||
29 | /** @var \Spatie\Activitylog\Contracts\Activity */ |
||
30 | protected $activity; |
||
31 | |||
32 | 132 | public function __construct(AuthManager $auth, Repository $config, ActivityLogStatus $logStatus) |
|
42 | |||
43 | 132 | public function setLogStatus(ActivityLogStatus $logStatus) |
|
49 | |||
50 | 24 | public function performedOn(Model $model) |
|
56 | |||
57 | 16 | public function on(Model $model) |
|
61 | |||
62 | 132 | public function causedBy($modelOrId) |
|
74 | |||
75 | 20 | public function by($modelOrId) |
|
79 | |||
80 | 8 | public function causedByAnonymous() |
|
87 | |||
88 | 4 | public function byAnonymous() |
|
92 | |||
93 | 132 | public function withProperties($properties) |
|
99 | |||
100 | 4 | public function withProperty(string $key, $value) |
|
101 | { |
||
102 | 4 | $this->getActivity()->properties = $this->getActivity()->properties->put($key, $value); |
|
103 | |||
104 | 4 | return $this; |
|
105 | } |
||
106 | |||
107 | 132 | public function useLog(string $logName) |
|
108 | { |
||
109 | 132 | $this->getActivity()->log_name = $logName; |
|
110 | |||
111 | 132 | return $this; |
|
112 | } |
||
113 | |||
114 | public function inLog(string $logName) |
||
115 | { |
||
116 | return $this->useLog($logName); |
||
117 | } |
||
118 | |||
119 | 4 | public function tap(callable $callback, string $eventName = null) |
|
125 | |||
126 | 4 | public function enableLogging() |
|
132 | |||
133 | 4 | public function disableLogging() |
|
134 | { |
||
135 | 4 | $this->logStatus->disable(); |
|
139 | |||
140 | 132 | public function log(string $description) |
|
159 | |||
160 | 40 | protected function normalizeCauser($modelOrId): Model |
|
176 | |||
177 | 124 | protected function replacePlaceholders(string $description, ActivityContract $activity): string |
|
178 | { |
||
179 | return preg_replace_callback('/:[a-z0-9._-]+/i', function ($match) use ($activity) { |
||
180 | 8 | $match = $match[0]; |
|
181 | |||
182 | 8 | $attribute = (string) (new Str($match))->between(':', '.'); |
|
183 | |||
184 | 8 | if (! in_array($attribute, ['subject', 'causer', 'properties'])) { |
|
185 | 4 | return $match; |
|
186 | } |
||
187 | |||
188 | 4 | $propertyName = substr($match, strpos($match, '.') + 1); |
|
189 | |||
190 | 4 | $attributeValue = $activity->$attribute; |
|
191 | |||
192 | 4 | if (is_null($attributeValue)) { |
|
193 | return $match; |
||
194 | } |
||
195 | |||
196 | 4 | $attributeValue = $attributeValue->toArray(); |
|
197 | |||
198 | 4 | return Arr::get($attributeValue, $propertyName, $match); |
|
199 | 124 | }, $description); |
|
200 | } |
||
201 | |||
202 | 132 | protected function getActivity(): ActivityContract |
|
214 | } |
||
215 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: