1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Raystech\StarterKit\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\Htmlable; |
6
|
|
|
use Illuminate\Contracts\Support\Responsable; |
7
|
|
|
// use Raystech\MediaManager\Utils\File; |
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
9
|
|
|
use Raystech\MediaManager\Models\Traits\CustomMediaProperties; |
|
|
|
|
10
|
|
|
use Raystech\MediaManager\UrlGenerator\UrlGeneratorFactory; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class Media extends Model implements Responsable, Htmlable |
13
|
|
|
{ |
14
|
|
|
use CustomMediaProperties; |
15
|
|
|
|
16
|
|
|
protected $casts = [ |
17
|
|
|
'custom_properties' => 'array', // Will convarted to (Array) |
18
|
|
|
]; |
19
|
|
|
public function toResponse($request) |
20
|
|
|
{ |
21
|
|
|
$downloadHeaders = [ |
22
|
|
|
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
23
|
|
|
'Content-Type' => $this->mime_type, |
|
|
|
|
24
|
|
|
'Content-Length' => $this->size, |
|
|
|
|
25
|
|
|
'Content-Disposition' => 'attachment; filename="' . $this->file_name . '"', |
|
|
|
|
26
|
|
|
'Pragma' => 'public', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
return response()->stream(function () { |
|
|
|
|
30
|
|
|
$stream = $this->stream(); |
31
|
|
|
|
32
|
|
|
fpassthru($stream); |
33
|
|
|
|
34
|
|
|
if (is_resource($stream)) { |
35
|
|
|
fclose($stream); |
36
|
|
|
} |
37
|
|
|
}, 200, $downloadHeaders); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function toHtml() |
41
|
|
|
{ |
42
|
|
|
return $this->img(); |
43
|
|
|
} |
44
|
|
|
public function img($conversion = '', array $extraAttributes = []): string |
45
|
|
|
{ |
46
|
|
|
// if (! (new Image())->canHandleMime($this->mime_type)) { |
47
|
|
|
// return ''; |
48
|
|
|
// } |
49
|
|
|
|
50
|
|
|
// if (is_array($conversion)) { |
51
|
|
|
// $attributes = $conversion; |
52
|
|
|
|
53
|
|
|
// $conversion = $attributes['conversion'] ?? ''; |
54
|
|
|
|
55
|
|
|
// unset($attributes['conversion']); |
56
|
|
|
|
57
|
|
|
// $extraAttributes = array_merge($attributes, $extraAttributes); |
58
|
|
|
// } |
59
|
|
|
|
60
|
|
|
// $attributeString = collect($extraAttributes) |
61
|
|
|
// ->map(function ($value, $name) { |
62
|
|
|
// return $name.'="'.$value.'"'; |
63
|
|
|
// })->implode(' '); |
64
|
|
|
|
65
|
|
|
// if (strlen($attributeString)) { |
66
|
|
|
// $attributeString = ' '.$attributeString; |
67
|
|
|
// } |
68
|
|
|
|
69
|
|
|
// $media = $this; |
70
|
|
|
|
71
|
|
|
// $viewName = 'image'; |
72
|
|
|
|
73
|
|
|
// $width = ''; |
74
|
|
|
|
75
|
|
|
// if ($this->hasResponsiveImages($conversion)) { |
76
|
|
|
// $viewName = config('medialibrary.responsive_images.use_tiny_placeholders') |
77
|
|
|
// ? 'responsiveImageWithPlaceholder' |
78
|
|
|
// : 'responsiveImage'; |
79
|
|
|
|
80
|
|
|
// $width = $this->responsiveImages($conversion)->files->first()->width(); |
81
|
|
|
// } |
82
|
|
|
|
83
|
|
|
// return view("medialibrary::{$viewName}", compact( |
84
|
|
|
// 'media', |
85
|
|
|
// 'conversion', |
86
|
|
|
// 'attributeString', |
87
|
|
|
// 'width' |
88
|
|
|
// )); |
89
|
|
|
} |
|
|
|
|
90
|
|
|
|
91
|
|
|
public function getCustomProperty(string $propertyName, $default = null) |
92
|
|
|
{ |
93
|
|
|
return array_get($this->custom_properties, $propertyName, $default); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $name |
98
|
|
|
* @param mixed $value |
99
|
|
|
* |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function setCustomProperty(string $name, $value): self |
103
|
|
|
{ |
104
|
|
|
$customProperties = $this->custom_properties; |
105
|
|
|
|
106
|
|
|
array_set($customProperties, $name, $value); |
107
|
|
|
|
108
|
|
|
$this->custom_properties = $customProperties; |
|
|
|
|
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
public function getDiskDriverName(): string |
113
|
|
|
{ |
114
|
|
|
return strtolower(config("filesystems.disks.{$this->disk}.driver")); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getFullUrl(string $conversionName = ''): string |
118
|
|
|
{ |
119
|
|
|
return url($this->getUrl($conversionName)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/* |
123
|
|
|
* Get the url to a original media file. |
124
|
|
|
*/ |
125
|
|
|
public function getUrl(string $conversionName = ''): string |
126
|
|
|
{ |
127
|
|
|
$urlGenerator = UrlGeneratorFactory::createForMedia($this, $conversionName); |
128
|
|
|
return $urlGenerator->getUrl(); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths