1 | <?php |
||
29 | class Permission |
||
30 | { |
||
31 | /** |
||
32 | * The Guard implementation. |
||
33 | * |
||
34 | * @var Guard |
||
35 | */ |
||
36 | protected $auth; |
||
37 | |||
38 | /** |
||
39 | * List of permissions that can be accessed by public users. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $publicAccess = [ |
||
44 | 'issue-view', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * Ordered list of contexts. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $contexts = [ |
||
53 | 'comment', |
||
54 | 'attachment', |
||
55 | 'issue', |
||
56 | 'project', |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * Create a new filter instance. |
||
61 | * |
||
62 | * @param Guard $auth |
||
63 | */ |
||
64 | 45 | public function __construct(Guard $auth) |
|
68 | |||
69 | /** |
||
70 | * Handle an incoming request. |
||
71 | * |
||
72 | * @param Request $request |
||
73 | * @param \Closure $next |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | 44 | public function handle(Request $request, Closure $next) |
|
88 | |||
89 | /** |
||
90 | * Whether or not the current context is in public project. |
||
91 | * |
||
92 | * @param Request $request |
||
93 | * @param string $permission |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | 44 | protected function isInPublicProjectContext(Request $request, $permission) |
|
107 | |||
108 | /** |
||
109 | * Whether or not the user can access the current context. |
||
110 | * |
||
111 | * @param Request $request |
||
112 | * @param string $permission |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | 44 | protected function canAccess(Request $request, $permission) |
|
122 | |||
123 | /** |
||
124 | * Whether or not the user has a valid permission in current context |
||
125 | * e.g. can access the issue or the project. |
||
126 | * |
||
127 | * @param User $user |
||
128 | * @param Route $route |
||
129 | * @param string $permission |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | 41 | public function canAccessContext(User $user, Route $route, $permission) |
|
149 | |||
150 | /** |
||
151 | * Return the model object of the current context. |
||
152 | * We check the lowest ( Comment ) first, to the highest ( Project ). |
||
153 | * |
||
154 | * @param Route $route |
||
155 | * |
||
156 | * @return ModelAbstract|null |
||
157 | */ |
||
158 | 10 | protected function getCurrentContext(Route $route) |
|
169 | |||
170 | /** |
||
171 | * Returns the permission defined in route action. |
||
172 | * |
||
173 | * @param Request $request |
||
174 | * |
||
175 | * @return mixed |
||
176 | */ |
||
177 | 44 | protected function getPermission(Request $request) |
|
183 | } |
||
184 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: