|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Modules\Media\Entities; |
|
4
|
|
|
|
|
5
|
|
|
use Dimsav\Translatable\Translatable; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
use Modules\Media\Helpers\FileHelper; |
|
8
|
|
|
use Modules\Media\Image\Facade\Imagy; |
|
9
|
|
|
use Modules\Media\ValueObjects\MediaPath; |
|
10
|
|
|
use Modules\Tag\Contracts\TaggableInterface; |
|
11
|
|
|
use Modules\Tag\Traits\NamespacedEntity; |
|
12
|
|
|
use Modules\Tag\Traits\TaggableTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class File |
|
16
|
|
|
* @package Modules\Media\Entities |
|
17
|
|
|
* @property \Modules\Media\ValueObjects\MediaPath path |
|
18
|
|
|
*/ |
|
19
|
|
|
class File extends Model implements TaggableInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use Translatable, NamespacedEntity, TaggableTrait; |
|
22
|
|
|
/** |
|
23
|
|
|
* All the different images types where thumbnails should be created |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $imageExtensions = ['jpg', 'png', 'jpeg', 'gif']; |
|
27
|
|
|
|
|
28
|
|
|
protected $table = 'media__files'; |
|
29
|
|
|
public $translatedAttributes = ['description', 'alt_attribute', 'keywords']; |
|
30
|
|
|
protected $fillable = [ |
|
31
|
|
|
'description', |
|
32
|
|
|
'alt_attribute', |
|
33
|
|
|
'keywords', |
|
34
|
|
|
'filename', |
|
35
|
|
|
'path', |
|
36
|
|
|
'extension', |
|
37
|
|
|
'mimetype', |
|
38
|
|
|
'width', |
|
39
|
|
|
'height', |
|
40
|
|
|
'filesize', |
|
41
|
|
|
'folder_id', |
|
42
|
|
|
]; |
|
43
|
|
|
protected $appends = ['path_string', 'media_type']; |
|
44
|
|
|
protected static $entityNamespace = 'asgardcms/media'; |
|
45
|
|
|
|
|
46
|
|
|
public function getPathAttribute($value) |
|
47
|
|
|
{ |
|
48
|
|
|
return new MediaPath($value); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getPathStringAttribute() |
|
52
|
|
|
{ |
|
53
|
|
|
return (string) $this->path; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getMediaTypeAttribute() |
|
57
|
|
|
{ |
|
58
|
|
|
return FileHelper::getTypeByMimetype($this->mimetype); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function isImage() |
|
62
|
|
|
{ |
|
63
|
|
|
return in_array(pathinfo($this->path, PATHINFO_EXTENSION), $this->imageExtensions); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getThumbnail($type) |
|
67
|
|
|
{ |
|
68
|
|
|
if ($this->isImage() && $this->getKey()) { |
|
69
|
|
|
return Imagy::getThumbnail($this->path, $type); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
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@propertyannotation 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.