1 | <?php |
||
11 | class Media extends Model |
||
12 | { |
||
13 | use SortableTrait; |
||
14 | |||
15 | const TYPE_OTHER = 'other'; |
||
16 | const TYPE_IMAGE = 'image'; |
||
17 | const TYPE_PDF = 'pdf'; |
||
18 | |||
19 | protected $guarded = ['id', 'disk', 'file_name', 'size', 'model_type', 'model_id']; |
||
20 | |||
21 | /** |
||
22 | * The attributes that should be casted to native types. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $casts = [ |
||
27 | 'manipulations' => 'array', |
||
28 | 'custom_properties' => 'array', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Create the polymorphic relation. |
||
33 | * |
||
34 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
35 | */ |
||
36 | public function model() |
||
37 | { |
||
38 | return $this->morphTo(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get the original Url to a media-file. |
||
43 | * |
||
44 | * @param string $conversionName |
||
45 | * |
||
46 | * @return string |
||
47 | * |
||
48 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
49 | */ |
||
50 | public function getUrl(string $conversionName = '') : string |
||
51 | { |
||
52 | $urlGenerator = UrlGeneratorFactory::createForMedia($this); |
||
53 | |||
54 | if ($conversionName !== '') { |
||
55 | $urlGenerator->setConversion(ConversionCollection::createForMedia($this)->getByName($conversionName)); |
||
56 | } |
||
57 | |||
58 | return $urlGenerator->getUrl(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get the original path to a media-file. |
||
63 | * |
||
64 | * @param string $conversionName |
||
65 | * |
||
66 | * @return string |
||
67 | * |
||
68 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
69 | */ |
||
70 | public function getPath(string $conversionName = '') : string |
||
71 | { |
||
72 | $urlGenerator = UrlGeneratorFactory::createForMedia($this); |
||
73 | |||
74 | if ($conversionName != '') { |
||
75 | $urlGenerator->setConversion(ConversionCollection::createForMedia($this)->getByName($conversionName)); |
||
76 | } |
||
77 | |||
78 | return $urlGenerator->getPath(); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Determine the type of a file. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getTypeAttribute() |
||
95 | |||
96 | /** |
||
97 | * Determine the type of a file from its file extension. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getTypeFromExtensionAttribute() |
||
117 | |||
118 | /* |
||
119 | * Determine the type of a file from its mime type |
||
120 | */ |
||
121 | public function getTypeFromMimeAttribute() : string |
||
141 | |||
142 | public function getExtensionAttribute() : string |
||
146 | |||
147 | public function getHumanReadableSizeAttribute() : string |
||
151 | |||
152 | public function getDiskDriverName() : string |
||
156 | |||
157 | /* |
||
158 | * Determine if the media item has a custom property with the given name. |
||
159 | */ |
||
160 | public function hasCustomProperty(string $propertyName) : bool |
||
164 | |||
165 | /** |
||
166 | * Get if the value of custom property with the given name. |
||
167 | * |
||
168 | * @param string $propertyName |
||
169 | * @param mixed $default |
||
170 | * |
||
171 | * @return mixed |
||
172 | */ |
||
173 | public function getCustomProperty(string $propertyName, $default = null) |
||
177 | |||
178 | /** |
||
179 | * @param string $name |
||
180 | * @param mixed $value |
||
181 | */ |
||
182 | public function setCustomProperty(string $name, $value) |
||
186 | |||
187 | /* |
||
188 | * Get all the names of the registered media conversions. |
||
189 | */ |
||
190 | public function getMediaConversionNames() : array |
||
198 | } |
||
199 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.