1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ariadne Component Library. |
5
|
|
|
* |
6
|
|
|
* (c) Muze <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace arc; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @package arc-grants |
16
|
|
|
* @requires \arc\path; |
17
|
|
|
* @requires \arc\tree; |
18
|
|
|
* @requires \arc\context; |
19
|
|
|
* @method static GrantsTree cd(string $path) |
20
|
|
|
* @method static GrantsTree switchUser(string $user, array $groups) |
21
|
|
|
* @method static GrantsTree setUserGrants(string $grants) |
22
|
|
|
* @method static GrantsTree setGroupGrants(string $group, string $grants) |
23
|
|
|
* @method static bool check(string $grant) |
24
|
|
|
* @method static array ls() |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
final class grants |
28
|
|
|
{ |
29
|
2 |
|
public static function getGrantsTree() |
30
|
|
|
{ |
31
|
2 |
|
$context = \arc\context::$context; |
32
|
2 |
|
if (!$context->arcUser) { |
33
|
1 |
|
$context->arcUser = 'public'; |
34
|
1 |
|
} |
35
|
2 |
|
if (!$context->arcGroups) { |
36
|
1 |
|
$context->arcGroups = [ 'public' ]; |
37
|
1 |
|
} |
38
|
2 |
|
if (!$context->arcGrants) { |
39
|
1 |
|
$context->arcGrants = new grants\GrantsTree( \arc\tree::expand()->cd( $context->arcPath ), $context->arcUser, $context->arcGroups ); |
40
|
1 |
|
} |
41
|
|
|
|
42
|
2 |
|
return $context->arcGrants; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public static function cd($path=null) { |
46
|
1 |
|
\arc\context::$context->arcGrants = self::getGrantsTree()->cd($path); |
47
|
1 |
|
return \arc\context::$context->arcGrants; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public static function switchUser($user) { |
51
|
1 |
|
\arc\context::$context->arcGrants = self::getGrantsTree()->switchUser($user); |
52
|
1 |
|
return \arc\context::$context->arcGrants; |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public static function __callStatic($name, $params) { |
56
|
2 |
|
return call_user_func_array( [self::getGrantsTree(), $name], $params ); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|