Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about obtaining list or urls from web file and the method type #42

Closed
mbamber1986 opened this issue Dec 19, 2021 · 7 comments
Closed

Comments

@mbamber1986
Copy link

Hello again my friend i have a question more of an issue, still loving your router heres the case of use

i am planning on building a roles, and rules system for my website and i want to base it on the url that it is currently at.

so in this case i i can pull all the array values from $url, and the current value if i was to use ROUTE anyway i need to know if there is anyway i can simply pull just the path and the type of method it is

so i can do soemthing like this in kmy admin panel

foreach($url as $path)
{
echo "Path : $path['path'] . "Add rules" . "Method type " . $path['method']
}

i litterly need to detect the url and the method post get etc

and the rest i will do via middleware

thanks in advance

@miladrahimi
Copy link
Owner

Hello. Thanks for your using the package.
Please update to the latest version if you haven't already.
Read the following section of the package README.
https://github.com/miladrahimi/phprouter#current-route
It illustrates all the available information that a route object provides.
You probably need the "path" and "method" attributes.

@mbamber1986
Copy link
Author

mbamber1986 commented Dec 20, 2021 via email

@miladrahimi
Copy link
Owner

If you mean something like $router->all() to get all the registered routes, no but I can implement it for you.
You can create a ACL middleware to check user access like this {

use MiladRahimi\PhpRouter\Routing\Route;
use Psr\Http\Message\ServerRequestInterface;

class AclMiddleware
{
    public function handle(ServerRequestInterface $request, Closure $next, Route $route)
    {
        // Find the current user => $user
        if ($user->can($route->getPath())) {
            return $next($request);
        }

        return new JsonResponse(['error' => 'ACL Error!'], 403);
    }
}

@mbamber1986
Copy link
Author

mbamber1986 commented Dec 20, 2021 via email

@miladrahimi
Copy link
Owner

@miladrahimi
Copy link
Owner

miladrahimi commented Dec 20, 2021

update to this version and you can call $router->all().
Btw, you can get the router object in your middleware and controllers using controller or middleware parameters. it injects the object automatically.

@mbamber1986
Copy link
Author

So i have checked it i can work with this you have been great and very accomadatng to this request thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants