-
Notifications
You must be signed in to change notification settings - Fork 452
/
JavascriptLocalizedAsset.php
71 lines (61 loc) · 1.61 KB
/
JavascriptLocalizedAsset.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
<?php
namespace Concrete\Core\Asset;
use Concrete\Core\Support\Facade\Application;
use Localization;
use URL;
class JavascriptLocalizedAsset extends JavascriptAsset
{
/**
* @var bool
*/
protected $assetSupportsMinification = false;
/**
* @return string
*/
public function getAssetType()
{
return 'javascript-localized';
}
public function getOutputAssetType()
{
return 'javascript';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Asset\Asset::mapAssetLocation()
*/
public function mapAssetLocation($path)
{
$url = URL::to('/' . ltrim($path, '/'))->getRelativeUrl();
$this->setAssetURL($url);
}
/**
* @return string
*/
public function getAssetHashKey()
{
return $this->assetURL . '::' . Localization::activeLocale() . '::' . sha1($this->getAssetContents());
}
public function isAssetLocal()
{
return false;
}
/**
* @return string|null
*/
public function getAssetContents()
{
$app = Application::getFacadeApplication();
$assetRoute = $this->getAssetURL();
$relativePath = $app->make('app_relative_path');
if ($relativePath !== '' && strpos($assetRoute, $relativePath . '/') === 0) {
$assetRoute = substr($assetRoute, strlen($relativePath));
}
$prefix = '/' . DISPATCHER_FILENAME . '/';
if (strpos($assetRoute, $prefix) === 0) {
$assetRoute = substr($assetRoute, strlen($prefix) - 1);
}
return parent::getAssetContentsByRoute($assetRoute);
}
}