1. Go to this page and download the library: Download francerz/access-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
francerz / access-manager example snippets
use Francerz\AccessManager\UserGrantsProviderInterface;
class CurrentUserGrantsProvider implements UserGrantsProviderInterface
{
public function getUserGrants(): string
{
// Returns the current user grants.
return $_SESSION['user_grants'];
}
}
use Francerz\AccessManager\AccessMiddleware;
use Slim\Routing\RouteCollectorProxy;
$app = new \Slim\App();
// A PSR-17 ResponseFactory implemenation
$responseFactory = new \GuzzleHttp\Psr7\HttpFactory();
$userPermissionProvider = new CurrentUserGrantsProvider();
$accessMiddleware = new AccessMiddleware($userPermissionProvider, $responseFactory);
$app->get('[/]', [HomeController::class, 'indexGet'])
->addMiddleware($accessMiddleware->allow('user'));
$app->group('/admin', function(RouteCollectorProxy $route) {
// Restricted admin routes.
$route->get('[/]', [AdminController::class, 'indexGet']);
})->addMiddleware($accessMiddleware->allow('admin'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.