This component allows to add ACL support to your routes, or in other words, to control access to protected routes. It is a Decorator over a Mendo\Router\RequestMatcherInterface instance.
The component requires three dependencies:
- a
Mendo\Acl\AclInterfaceinstance for ACL support (acl component) - a
Mendo\Auth\CurrentUserInterfaceinstance to get the user's role (auth component) - a
Mendo\Router\RequestMatcherInterfaceinstance (router component)
Routes can be protected by specifying the required user role in order to access that route. This is done simply by adding the _role route parameter to the corresponding router.
$router = new Mendo\Router\LiteralRouter('edit-profile', '/profile/edit',
[
'_role' => 'member',
]
);$requestMatcher = new Mendo\Router\Acl\RequestAuthorizer($dic['router.requestMatcher'], $dic['acl'], $dic['auth']);The example above restricts the edit-profile route to authenticated members.
If an unauthorized user tries to access a route, a Mendo\Router\Acl\Exception\NotAuthorizedException exception will be thrown, with a 403 exception code.
You can install Mendo Router using the dependency management tool Composer. Run the require command to resolve and download the dependencies:
composer require mendoframework/router-acl