1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace LeadThread\Viddler\Upload\Models;
|
4
|
|
|
|
5
|
|
|
use Exception;
|
6
|
|
|
use Illuminate\Database\Eloquent\Model;
|
7
|
|
|
use LeadThread\Viddler\Upload\Traits\CanLog;
|
8
|
|
|
use LeadThread\Viddler\Upload\Components\ViddlerClient;
|
9
|
|
|
use LeadThread\Viddler\Upload\Components\VideoFile;
|
10
|
|
|
use LeadThread\Viddler\Upload\Events\ViddlerError;
|
11
|
|
|
use LeadThread\Viddler\Upload\Events\ViddlerFinished;
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* @property boolean $uploaded
|
15
|
|
|
* @property string $disk
|
16
|
|
|
* @property string $extension
|
17
|
|
|
* @property string $filename
|
18
|
|
|
* @property string $mime
|
19
|
|
|
* @property string $path
|
20
|
|
|
* @property string $status
|
21
|
|
|
* @property string $title
|
22
|
|
|
* @property string $viddler_id
|
23
|
|
|
*/
|
24
|
|
|
class Viddler extends Model
|
25
|
|
|
{
|
26
|
|
|
use CanLog;
|
27
|
|
|
|
28
|
|
|
protected $guarded = ['id'];
|
29
|
|
|
protected $table;
|
30
|
|
|
protected $client;
|
31
|
|
|
public $file;
|
32
|
|
|
|
33
|
18 |
|
public function __construct(array $attributes = [])
|
34
|
|
|
{
|
35
|
18 |
|
if (empty($this->table)) {
|
36
|
18 |
|
$this->table = config('viddler.table');
|
37
|
18 |
|
}
|
38
|
18 |
|
parent::__construct($attributes);
|
39
|
|
|
|
40
|
18 |
|
$this->file = new VideoFile($this);
|
41
|
|
|
|
42
|
18 |
|
$this->client = $this->getClient();
|
43
|
18 |
|
}
|
44
|
|
|
|
45
|
18 |
|
public function __toString()
|
46
|
18 |
|
{
|
47
|
18 |
|
return "Viddler #{$this->id}";
|
|
|
|
|
48
|
|
|
}
|
49
|
|
|
|
50
|
18 |
|
public function convert()
|
51
|
|
|
{
|
52
|
|
|
try {
|
53
|
18 |
|
$this->file->convert();
|
54
|
18 |
|
} catch (Exception $e) {
|
55
|
|
|
$this->handleError($e);
|
56
|
|
|
throw $e;
|
57
|
|
|
}
|
58
|
18 |
|
return $this;
|
59
|
|
|
}
|
60
|
|
|
|
61
|
18 |
|
public function upload()
|
62
|
|
|
{
|
63
|
|
|
try {
|
64
|
18 |
|
$this->client->upload($this);
|
65
|
18 |
|
} catch (Exception $e) {
|
66
|
3 |
|
$this->handleError($e);
|
67
|
3 |
|
throw $e;
|
68
|
|
|
}
|
69
|
15 |
|
return $this;
|
70
|
|
|
}
|
71
|
|
|
|
72
|
6 |
|
public function check()
|
73
|
|
|
{
|
74
|
|
|
try {
|
75
|
6 |
|
$this->client->check($this);
|
76
|
6 |
|
} catch (Exception $e) {
|
77
|
3 |
|
$this->handleError($e);
|
78
|
3 |
|
throw $e;
|
79
|
|
|
}
|
80
|
3 |
|
return $this;
|
81
|
|
|
}
|
82
|
|
|
|
83
|
18 |
|
public function getFile()
|
84
|
|
|
{
|
85
|
18 |
|
return $this->file;
|
86
|
6 |
|
}
|
87
|
|
|
|
88
|
18 |
|
public function updateStatusTo($status)
|
89
|
|
|
{
|
90
|
18 |
|
$this->file->moveTo($status);
|
91
|
18 |
|
$this->status = $status;
|
92
|
|
|
|
93
|
18 |
|
$this->save();
|
94
|
|
|
|
95
|
18 |
|
if ($this->status === "finished") {
|
96
|
3 |
|
event(new ViddlerFinished($this));
|
97
|
9 |
|
}
|
98
|
|
|
|
99
|
18 |
|
return $this;
|
100
|
|
|
}
|
101
|
|
|
|
102
|
18 |
|
public function isResolved()
|
103
|
|
|
{
|
104
|
18 |
|
return $this->status === "finished" || $this->status === "error";
|
105
|
|
|
}
|
106
|
|
|
|
107
|
18 |
|
public function isNotResolved()
|
108
|
|
|
{
|
109
|
18 |
|
return !$this->isResolved();
|
110
|
6 |
|
}
|
111
|
|
|
|
112
|
18 |
|
public function setClient(ViddlerClient $client)
|
113
|
6 |
|
{
|
114
|
18 |
|
$this->client = $client;
|
115
|
18 |
|
}
|
116
|
|
|
|
117
|
18 |
|
public function getClient()
|
118
|
|
|
{
|
119
|
18 |
|
if (empty($this->client)) {
|
120
|
18 |
|
$this->client = new ViddlerClient();
|
121
|
18 |
|
}
|
122
|
18 |
|
return $this->client;
|
123
|
|
|
}
|
124
|
|
|
|
125
|
18 |
|
protected function handleError(Exception $e)
|
126
|
|
|
{
|
127
|
6 |
|
$this->file->removeFile();
|
128
|
|
|
|
129
|
6 |
|
$this->status = "error";
|
130
|
6 |
|
$this->path = null;
|
131
|
6 |
|
$this->filename = null;
|
132
|
6 |
|
$this->disk = null;
|
133
|
6 |
|
$this->extension = null;
|
134
|
6 |
|
$this->mime = null;
|
135
|
18 |
|
$this->save();
|
136
|
|
|
|
137
|
6 |
|
$this->error("{$this} Error Occurred! ".$e->getMessage());
|
138
|
|
|
|
139
|
6 |
|
event(new ViddlerError($this, $e->getMessage()));
|
140
|
6 |
|
}
|
141
|
|
|
}
|
142
|
|
|
|
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.