|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the package lns/digital-asset-management. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace TYPO3\CMS\DigitalAssetManagement\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use TYPO3\CMS\Core\Resource\ResourceStorage; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Immutable file mount object, used by getStoragesAndMountsAction() for non-admin users. |
|
17
|
|
|
* Combines info of file mount and its storage. |
|
18
|
|
|
* |
|
19
|
|
|
* @see Storage |
|
20
|
|
|
*/ |
|
21
|
|
|
class FileMount implements \JsonSerializable |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string Always set to "mount" |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $type = 'mount'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var int FAL identifier, eg. "42:/path/to/mount" |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $identifier; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string Speaking name of file mount |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $name; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string Speaking name of storage, eg. "Some storage" |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $storageName; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string Storage driver, eg. "Local" |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $storageType; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var bool True if storage is online |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $storageOnline; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string Markup of the storage icon |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $icon; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param ResourceStorage $storage |
|
60
|
|
|
* @param array $fileMount |
|
61
|
|
|
*/ |
|
62
|
|
|
public function __construct(ResourceStorage $storage, array $fileMount) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->identifier = $storage->getUid() . ':' . $fileMount['path']; |
|
|
|
|
|
|
65
|
|
|
$this->name = $fileMount['title']; |
|
66
|
|
|
$this->storageName = $storage->getName(); |
|
67
|
|
|
$this->storageType = $storage->getDriverType(); |
|
68
|
|
|
$this->storageOnline = $storage->isOnline(); |
|
69
|
|
|
$this->icon = 'apps-filetree-mount'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function jsonSerialize() |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
|
|
'type' => $this->type, |
|
76
|
|
|
'identifier' => $this->identifier, |
|
77
|
|
|
'name' => $this->name, |
|
78
|
|
|
'storageName' => $this->storageName, |
|
79
|
|
|
'storageType' => $this->storageType, |
|
80
|
|
|
'storageOnline' => $this->storageOnline, |
|
81
|
|
|
'icon' => $this->icon |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.