Skip to content

Commit ca70622

Browse files
committed
Proxy: Add method for generate proxy URL.
1 parent aa42656 commit ca70622

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Proxy/Proxy.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Baraja\Cms\Context;
1010
use Baraja\Cms\Helpers;
1111
use Baraja\Plugin\Plugin;
12+
use Baraja\Url\Url;
1213

1314
/**
1415
* Smart proxy service for render all plugin components to single javascript.
@@ -36,6 +37,23 @@ public function __construct(
3637
}
3738

3839

40+
public static function getUrl(string $file): string
41+
{
42+
if (str_contains($file, '..')) {
43+
throw new \LogicException('File path "' . $file . '" is not safe.');
44+
}
45+
$diskPath = __DIR__ . '/../../template/assets/' . $file;
46+
if (is_file($diskPath) === false) {
47+
throw new \InvalidArgumentException(
48+
'Static file "' . $file . '" does not exist. '
49+
. 'Path "' . $diskPath . '" given.',
50+
);
51+
}
52+
53+
return Url::get()->getBaseUrl() . '/admin/assets/' . $file;
54+
}
55+
56+
3957
/**
4058
* Render dynamic Vue components to requested file.
4159
*/

0 commit comments

Comments
 (0)