-
Notifications
You must be signed in to change notification settings - Fork 645
/
Copy pathFs.php
105 lines (91 loc) · 2.25 KB
/
Fs.php
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
103
104
105
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\base;
use Craft;
use craft\helpers\App;
use craft\validators\HandleValidator;
/**
* Field is the base class for classes representing filesystems in terms of objects.
*
* @property-read null|string $rootUrl
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 4.0.0
*/
abstract class Fs extends SavableComponent implements FsInterface
{
use FsTrait;
public const CONFIG_MIMETYPE = 'mimetype';
public const CONFIG_VISIBILITY = 'visibility';
public const VISIBILITY_DEFAULT = 'default';
public const VISIBILITY_HIDDEN = 'hidden';
public const VISIBILITY_PUBLIC = 'public';
/**
* @inheritdoc
*/
public function getRootUrl(): ?string
{
if (!$this->hasUrls) {
return null;
}
$url = App::parseEnv($this->url);
if (is_string($url)) {
$url = rtrim($url, '/');
}
return $url ? "$url/" : null;
}
/**
* @inheritdoc
*/
public function attributeLabels(): array
{
return [
'handle' => Craft::t('app', 'Handle'),
'name' => Craft::t('app', 'Name'),
'url' => Craft::t('app', 'Base URL'),
];
}
/**
* @inheritdoc
*/
public function getShowHasUrlSetting(): bool
{
return static::$showHasUrlSetting;
}
/**
* @inheritdoc
*/
public function getShowUrlSetting(): bool
{
return static::$showUrlSetting;
}
/**
* @inheritdoc
*/
protected function defineRules(): array
{
$rules = parent::defineRules();
$rules[] = [['name', 'handle'], 'required'];
$rules[] = [
'url',
'required',
'when' => fn(self $fs) => $fs->hasUrls && $this->getShowUrlSetting(),
];
$rules[] = [
['handle'],
HandleValidator::class,
'reservedWords' => [
'dateCreated',
'dateUpdated',
'edit',
'id',
'title',
'uid',
],
];
return $rules;
}
}