1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Helpers; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Http\RedirectResponse; |
8
|
|
|
use Illuminate\Http\UploadedFile; |
9
|
|
|
use Mostafaznv\Larupload\LaruploadEnum; |
10
|
|
|
use Mostafaznv\Larupload\UploadEntities; |
11
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
12
|
|
|
|
13
|
|
|
trait LaraStandalone |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param string $style |
17
|
|
|
* @return null|string |
18
|
|
|
* @throws Exception |
19
|
|
|
* @internal |
20
|
|
|
*/ |
21
|
|
|
public function url(string $style = LaruploadEnum::ORIGINAL_FOLDER): ?string |
22
|
|
|
{ |
23
|
|
|
if ($this->internalFunctionIsCallable) { |
24
|
|
|
return parent::url($style); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
self::internalException(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string|null $key |
32
|
|
|
* @return object|string|integer|null |
33
|
|
|
* @throws Exception |
34
|
|
|
* @internal |
35
|
|
|
*/ |
36
|
|
|
public function meta(string $key = null) |
37
|
|
|
{ |
38
|
|
|
if ($this->internalFunctionIsCallable) { |
39
|
|
|
return parent::meta($key); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
self::internalException(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return object |
47
|
|
|
* @throws Exception |
48
|
|
|
* @internal |
49
|
|
|
*/ |
50
|
|
|
public function urls(): object |
51
|
|
|
{ |
52
|
|
|
if ($this->internalFunctionIsCallable) { |
53
|
|
|
return parent::urls(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
self::internalException(); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param bool $isLastOne |
61
|
|
|
* @throws Exception |
62
|
|
|
* @internal |
63
|
|
|
*/ |
64
|
|
|
public function handleFFMpegQueue(bool $isLastOne = false): void |
65
|
|
|
{ |
66
|
|
|
if ($this->internalFunctionIsCallable) { |
67
|
|
|
parent::handleFFMpegQueue($isLastOne); |
68
|
|
|
} |
69
|
|
|
else { |
70
|
|
|
self::internalException(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param UploadedFile $file |
76
|
|
|
* @return bool |
77
|
|
|
* @throws Exception |
78
|
|
|
* @internal |
79
|
|
|
*/ |
80
|
|
|
public function updateCover(UploadedFile $file): bool |
81
|
|
|
{ |
82
|
|
|
if ($this->internalFunctionIsCallable) { |
83
|
|
|
return parent::updateCover($file); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
self::internalException(); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return bool |
91
|
|
|
* @throws Exception |
92
|
|
|
* @internal |
93
|
|
|
*/ |
94
|
|
|
public function detachCover(): bool |
95
|
|
|
{ |
96
|
|
|
if ($this->internalFunctionIsCallable) { |
97
|
|
|
return parent::detachCover(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
self::internalException(); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/****** not call callable ******************************************************************************************/ |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $name |
107
|
|
|
* @param string $mode |
108
|
|
|
* @return UploadEntities |
109
|
|
|
* @throws Exception |
110
|
|
|
* @internal |
111
|
|
|
*/ |
112
|
|
|
public static function make(string $name, string $mode = LaruploadEnum::HEAVY_MODE): UploadEntities |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
self::internalException(); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param Model $model |
119
|
|
|
* @return Model |
120
|
|
|
* @throws Exception |
121
|
|
|
* @internal |
122
|
|
|
*/ |
123
|
|
|
public function saved(Model $model): Model |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
self::internalException(); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param Model $model |
130
|
|
|
* @throws Exception |
131
|
|
|
* @internal |
132
|
|
|
*/ |
133
|
|
|
public function deleted(Model $model): void |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
self::internalException(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $style |
140
|
|
|
* @return RedirectResponse|StreamedResponse|null |
141
|
|
|
* @throws Exception |
142
|
|
|
* @internal |
143
|
|
|
*/ |
144
|
|
|
public function download(string $style = 'original') |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
self::internalException(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param Model $model |
151
|
|
|
* @throws Exception |
152
|
|
|
* @internal |
153
|
|
|
*/ |
154
|
|
|
public function setOutput(Model $model) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
self::internalException(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Throw exception for internal functions |
161
|
|
|
* |
162
|
|
|
* @throws Exception |
163
|
|
|
*/ |
164
|
|
|
protected static function internalException() |
165
|
|
|
{ |
166
|
|
|
throw new Exception('This function flagged as @internal and is not available on standalone uploader.'); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: