-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetManager.php
More file actions
61 lines (49 loc) · 1.67 KB
/
AssetManager.php
File metadata and controls
61 lines (49 loc) · 1.67 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
<?php
namespace craft\cloud\web;
use Craft;
use craft\cloud\fs\CpResourcesFs;
use craft\cloud\Helper;
use craft\helpers\FileHelper;
use craft\helpers\StringHelper;
use League\Uri\Components\HierarchicalPath;
use League\Uri\Modifier;
class AssetManager extends \craft\web\AssetManager
{
public bool $cacheSourcePaths = false;
public function init(): void
{
$this->preparePaths();
parent::init();
}
public function publish($path, $options = []): array
{
$this->preparePaths();
return parent::publish($path, $options);
}
protected function preparePaths(): void
{
$this->basePath = Craft::getAlias($this->basePath);
if (!Helper::isCraftCloud()) {
FileHelper::createDirectory($this->basePath);
}
$this->baseUrl = Modifier::wrap((new CpResourcesFs())->createUrl())->removeTrailingSlash();
}
protected function hash($path): string
{
$dir = is_file($path) ? dirname($path) : $path;
$rebrandPath = Craft::$app->getPath()->getRebrandPath();
// Account for rebrand, as it lives in @storage by default,
// which will be different in Cloud runtime vs. Cloud build.
if (str_starts_with($dir, $rebrandPath)) {
return HierarchicalPath::new(StringHelper::removeLeft($dir, $rebrandPath))
->prepend('rebrand')
->withoutTrailingSlash()
->toString();
}
$pathFromRoot = StringHelper::removeLeft($dir, Craft::getAlias('@root/'));
return FileHelper::sanitizeFilename(
preg_replace('/\/|@/', '-', $pathFromRoot),
['asciiOnly' => true]
);
}
}