LaraCrafts / laravel-geo-routes

GeoLocation restricted routes for Laravel
MIT License
111 stars 5 forks source link

Configurable default callback #11

Closed axlon closed 3 years ago

axlon commented 5 years ago

Currently the default callback is set to a 401 response, it might be handy to make this configurable so an implementor won't have to add the same callback to his routes a 100 times

yak0d3 commented 5 years ago

I have worked on the default configuration implementation, the implementation is now located in the config-defaults branch. The current tests are passing, i have not added tests for the implementation but i'll be sure to add those later. The configuration now looks like this:

    'callbacks' => [
        // 'myCallback' => 'MyClass::myFunction',
    ],
    'defaults' => [

        'RULE' => 'allow', //Can be either `allow` or `deny`, anything else will set this to `deny` automatically.

        'CALLBACK' => [
            'name' => 'orUnauthorized',
            'args' => null
        ],
    ]
axlon commented 5 years ago

Adding a default rule doesn't add anything except overhead (unless I'm missing something), I think the general way of defining the default callback should be changed as well. I think we should fix the various callback issues (allowing instance methods for instance), before we tackle this issue