-
Notifications
You must be signed in to change notification settings - Fork 68
/
ProtectedAssetAdapter.php
60 lines (51 loc) · 1.67 KB
/
ProtectedAssetAdapter.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
<?php
namespace SilverStripe\Assets\Flysystem;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Environment;
class ProtectedAssetAdapter extends AssetAdapter implements ProtectedAdapter
{
/**
* Name of default folder to save secure assets in under ASSETS_PATH.
* This can be bypassed by specifying an absolute filesystem path via
* the SS_PROTECTED_ASSETS_PATH environment definition.
*
* @config
* @var string
*/
private static $secure_folder = '.protected';
private static $server_configuration = [
'apache' => [
'.htaccess' => self::class . '_HTAccess'
],
'microsoft-iis' => [
'web.config' => self::class . '_WebConfig'
]
];
protected function findRoot($root)
{
// Use explicitly defined path
if ($root) {
return parent::findRoot($root);
}
// Use environment defined path or default location is under assets
if ($path = Environment::getEnv('SS_PROTECTED_ASSETS_PATH')) {
return $path;
}
// Default location
return ASSETS_PATH . '/' . Config::inst()->get(__CLASS__, 'secure_folder');
}
/**
* Provide secure downloadable
*
* @param string $path
* @return string|null
*/
public function getProtectedUrl($path)
{
// Public URLs are handled via a request handler within /assets.
// If assets are stored locally, then asset paths of protected files should be equivalent.
return Controller::join_links(Director::baseURL(), ASSETS_DIR, $path);
}
}