Open Swader opened 8 years ago
<Rubberduck mode on>
Rauth could have a handleMode
method which accepts the mode extracted from the auth block, the rest of auth block itself (free of bans), and the attributes array. All arrays can be passed by reference since they're only being compared, not changed.
The handleMode
method should then somehow invoke the mode handlers, each of which can throw an AuthException if needed.
This, however, smells like it would need a ModeHandlerFactory or something similarly convoluted, which would help with testing but throw off users - more configuration will discourage people who just want to get things done (see Symfony).
One way around this is to give Rauth a registerMode
method like this:
public function registerModes(string $mode, callable $callable) {
...
}
Or instead of callable, an instance of Mode (interface would only have the __invoke
method).
public function registerModes(string $mode, Mode $callable) {
...
}
That way, the handleMode
method could invoke the custom added mode like so:
public function handleMode(string $mode, &$auth, &$attributes) {
return $this->modes[$mode]($auth, $attr);
}
... or something like this...
In essence, this would allow for the registration of custom modes at bootstrap time, and bypass the need for any kind of factory.
Possible fix for #5 would be adding separate mode handlers. Those would be invoked as per defined mode, and since an exception would be thrown for fail authorizations as per #1, they could operate independently.
What's more, this would open the door to extending Rauth with custom modes and mode handlers.