1
|
|
|
<?php |
2
|
|
|
namespace STS\StorageConnect\Subscribers; |
3
|
|
|
|
4
|
|
|
use STS\StorageConnect\Events\CloudStorageDisabled; |
5
|
|
|
use STS\StorageConnect\Events\CloudStorageEnabled; |
6
|
|
|
use STS\StorageConnect\Events\CloudStorageSetup; |
7
|
|
|
use Log; |
8
|
|
|
use STS\StorageConnect\Events\UploadFailed; |
9
|
|
|
use STS\StorageConnect\Events\UploadInProgress; |
10
|
|
|
use STS\StorageConnect\Events\UploadRetrying; |
11
|
|
|
use STS\StorageConnect\Events\UploadStarted; |
12
|
|
|
use STS\StorageConnect\Events\UploadSucceeded; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class LogsActivity |
16
|
|
|
* @package STS\StorageConnect\Subscribers |
17
|
|
|
*/ |
18
|
|
|
class LogsActivity |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param $dispatcher |
22
|
|
|
*/ |
23
|
|
|
public function subscribe($dispatcher) |
24
|
|
|
{ |
25
|
|
|
$dispatcher->listen(CloudStorageSetup::class, function (CloudStorageSetup $event) { |
26
|
|
|
$this->info("New cloud storage connection", $event->storage); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
$dispatcher->listen(UploadSucceeded::class, function (UploadSucceeded $event) { |
30
|
|
|
$this->info("File uploaded to cloud storage", $event->storage, [ |
31
|
|
|
'source' => $event->sourcePath, |
32
|
|
|
'destination' => $event->destinationPath |
33
|
|
|
]); |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
$dispatcher->listen(UploadRetrying::class, function (UploadRetrying $event) { |
37
|
|
|
$this->warning($event->message, $event->storage, [ |
38
|
|
|
'source' => $event->sourcePath |
39
|
|
|
]); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$dispatcher->listen(UploadFailed::class, function (UploadFailed $event) { |
43
|
|
|
$this->error($event->message, $event->storage, [ |
44
|
|
|
'source' => $event->sourcePath |
45
|
|
|
]); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$dispatcher->listen(UploadStarted::class, function (UploadStarted $event) { |
49
|
|
|
$this->info("Async upload started", $event->storage, [ |
50
|
|
|
'source' => $event->sourcePath |
51
|
|
|
]); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$dispatcher->listen(UploadInProgress::class, function (UploadInProgress $event) { |
55
|
|
|
$this->info("Async upload in progress", $event->storage, [ |
56
|
|
|
'source' => $event->sourcePath |
57
|
|
|
]); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
$dispatcher->listen(CloudStorageDisabled::class, function (CloudStorageDisabled $event) { |
61
|
|
|
$this->warning("Connection disabled", $event->storage, [ |
62
|
|
|
'reason' => $event->storage->reason |
|
|
|
|
63
|
|
|
]); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
$dispatcher->listen(CloudStorageEnabled::class, function (CloudStorageEnabled $event) { |
67
|
|
|
$this->info("Connection enabled", $event->storage); |
68
|
|
|
}); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $message |
73
|
|
|
* @param $storage |
74
|
|
|
* @param array $context |
75
|
|
|
*/ |
76
|
|
|
protected function info($message, $storage, array $context = []) |
77
|
|
|
{ |
78
|
|
|
Log::info($message, $this->getContext($storage, $context)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $message |
83
|
|
|
* @param $storage |
84
|
|
|
* @param array $context |
85
|
|
|
*/ |
86
|
|
|
protected function warning($message, $storage, array $context = []) |
87
|
|
|
{ |
88
|
|
|
Log::warning($message, $this->getContext($storage, $context)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $message |
93
|
|
|
* @param $storage |
94
|
|
|
* @param array $context |
95
|
|
|
*/ |
96
|
|
|
protected function error($message, $storage, array $context = []) |
97
|
|
|
{ |
98
|
|
|
Log::error($message, $this->getContext($storage, $context)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param $storage |
103
|
|
|
* @param array $context |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
protected function getContext($storage, array $context = []) |
108
|
|
|
{ |
109
|
|
|
return array_merge($context, [ |
110
|
|
|
'storage' => $storage->id, |
111
|
|
|
'driver' => $storage->driver, |
112
|
|
|
'owner' => $storage->owner_description, |
113
|
|
|
]); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.