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: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117:
<?php
trait FilesystemPathTrait
{
protected $site;
protected function bindPathContext(\Auth_Info_User $auth): void
{
$this->site = $auth->site;
}
protected function domain_fs_path(string $subpath = null): string
{
\assert(null !== $this->site || !empty($_SESSION['site_id']));
return FILESYSTEM_VIRTBASE . '/' . ($this->site ?? ('site' . $_SESSION['site_id']))
. '/fst' . ($subpath ? ($subpath[0] === '/' ? '' : '/') . $subpath : '');
}
protected function freshen_domain_fs_path(string $subpath = null): string
{
$path = $this->domain_fs_path($subpath);
clearstatcache(true, $path);
return $path;
}
protected function domain_info_path(string $subpath = null): string
{
\assert(null !== $this->site || !empty($_SESSION['site_id']));
return FILESYSTEM_VIRTBASE . '/' . ($this->site ?? ('site' . $_SESSION['site_id']))
. '/info' . ($subpath ? ($subpath[0] === '/' ? '' : '/') . $subpath : '');
}
protected function domain_shadow_path(string $subpath = null): string
{
\assert(null !== $this->site || !empty($_SESSION['site_id']));
return FILESYSTEM_VIRTBASE . '/' . ($this->site ?? ('site' . $_SESSION['site_id']))
. '/shadow' . ($subpath ? ($subpath[0] === '/' ? '' : '/') . $subpath : '');
}
protected function make_domain_fs_path($domain = null): string
{
if (!$domain) {
return '/';
}
$siteid = \Auth::get_site_id_from_domain($domain);
if (!$siteid) {
fatal("cannot make domain fs path, unknown domain `%s'", $domain);
}
return FILESYSTEM_VIRTBASE . '/site' . $siteid . '/fst';
}
protected function service_template_path($service = null): string
{
$path = FILESYSTEM_TEMPLATE;
if ($service) {
return $path . '/' . $service;
}
return $path;
}
}