1 | <?php |
||
7 | class Enforcer |
||
8 | { |
||
9 | private $config = array(); |
||
10 | private $fail = false; |
||
|
|||
11 | private $error = 'There was an error!'; |
||
12 | |||
13 | private $options = array( |
||
14 | 'protected' => 'resource.isProtected', |
||
15 | 'groups' => 'user.hasGroup', |
||
16 | 'permissions' => 'user.hasPermission', |
||
17 | 'methods' => 'resource.hasMethod', |
||
18 | 'params' => 'route.hasParameters', |
||
19 | 'callback' => 'object.callback', |
||
20 | 'inherit' => 'internal.inherit' |
||
21 | ); |
||
22 | |||
23 | private $matches = []; |
||
24 | |||
25 | public function __construct($configPath) |
||
29 | |||
30 | /** |
||
31 | * Load the configuration from the given path |
||
32 | * |
||
33 | * @param string $configPath Path to YAML configuration file |
||
34 | * @return array Configuration data set |
||
35 | */ |
||
36 | public function loadConfig($configPath) |
||
49 | |||
50 | /** |
||
51 | * Return the current config |
||
52 | * |
||
53 | * @return array Current configuration values |
||
54 | */ |
||
55 | public function getConfig() |
||
59 | |||
60 | /** |
||
61 | * Set the current configuration data |
||
62 | * |
||
63 | * @param array $config Configuration data |
||
64 | */ |
||
65 | public function setConfig(array $config) |
||
69 | |||
70 | /** |
||
71 | * Get the current error message |
||
72 | * |
||
73 | * @return string Error message |
||
74 | */ |
||
75 | public function getError() |
||
79 | |||
80 | /** |
||
81 | * Set the current error mesasge |
||
82 | * |
||
83 | * @param string $error Error message |
||
84 | */ |
||
85 | public function setError($error) |
||
89 | |||
90 | /** |
||
91 | * Try to find a route match in the current config set |
||
92 | * |
||
93 | * @param string $uri URI to evaluate |
||
94 | * @param array $config Current route configuration |
||
95 | * @return \Psecio\Invoke\RouteContainer|null Route if found, null if not |
||
96 | */ |
||
97 | public function findRouteMatch($uri, array $config) |
||
109 | |||
110 | public function addMatch(\Psecio\Invoke\RouteContainer $route) |
||
123 | |||
124 | public function isValidOption($option) |
||
128 | |||
129 | /** |
||
130 | * Check to see if the request is authorized |
||
131 | * By default, fails closed |
||
132 | * |
||
133 | * @param \Psecio\Invoke\UserInterface $user User instance |
||
134 | * @param \Psecio\Invoke\Resource $resource Resource instance |
||
135 | * @param array $matches Additional matches to add manually for evaluation |
||
136 | * @return boolean Pass/fail of authorization |
||
137 | */ |
||
138 | public function isAuthorized( |
||
171 | |||
172 | /** |
||
173 | * Get the match type of the given object instance |
||
174 | * |
||
175 | * @param object $match Match object instance |
||
176 | * @return string Match type |
||
177 | */ |
||
178 | public function getMatchType($match) |
||
183 | |||
184 | /** |
||
185 | * Check to ensure the route exists in the current configuration |
||
186 | * One to one string match, not a regex match |
||
187 | * |
||
188 | * @param string $route Route to match |
||
189 | * @return boolean Match found/no match |
||
190 | */ |
||
191 | public function routeExists($route) |
||
195 | |||
196 | /** |
||
197 | * Evaluate if the endpoint has protection turned on |
||
198 | * |
||
199 | * @param \Psecio\RouteContainer $route Route instance |
||
200 | * @return boolean On/off status of protection |
||
201 | */ |
||
202 | public function isProtected($route) |
||
207 | } |
This check marks private properties in classes that are never used. Those properties can be removed.