-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileStorage.php
More file actions
102 lines (90 loc) · 2.21 KB
/
FileStorage.php
File metadata and controls
102 lines (90 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types = 1);
namespace Burzum\FileStorage\Model\Entity;
use Cake\ORM\Entity;
/**
* FileStorage Entity.
*
* @author Florian Krämer
* @copyright 2012 - 2020 Florian Krämer
* @license MIT
*
* @property array $variants
* @property array $metadata
* @property int $id
* @property int|null $user_id
* @property int|null $foreign_key
* @property string|null $model
* @property string|null $filename
* @property int|null $filesize
* @property string|null $mime_type
* @property string|null $extension
* @property string|null $hash
* @property string|null $path
* @property string|null $adapter
* @property \Cake\I18n\FrozenTime $created
* @property \Cake\I18n\FrozenTime $modified
* @property string|null $collection
* @property array $variant_urls
*/
class FileStorage extends Entity implements FileStorageEntityInterface
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
'*' => true,
];
/**
* @var array
*/
protected $_virtual = [
'variantUrls',
];
/**
* @param string $variant Variant
*
* @return string|null
*/
public function getVariantUrl(string $variant): ?string
{
$variants = (array)$this->get('variants');
if (!isset($variants[$variant]['url'])) {
return null;
}
return $variants[$variant]['url'];
}
/**
* @param string $variant Variant
*
* @return string|null
*/
public function getVariantPath(string $variant): ?string
{
$variants = (array)$this->get('variants');
if (!isset($variants[$variant]['path'])) {
return null;
}
return $variants[$variant]['path'];
}
/**
* Making it backward compatible
*
* @return array
*/
protected function _getVariantUrls()
{
$variants = (array)$this->get('variants');
$list = [
'original' => $this->get('url'),
];
foreach ($variants as $name => $data) {
if (!empty($data['url'])) {
$list[$name] = $data['url'];
}
}
return $list;
}
}