PHP code example of codevia / permission-middleware
1. Go to this page and download the library: Download codevia/permission-middleware 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/ */
codevia / permission-middleware example snippets
// src/Permission.php
namespace App;
use Codevia\PermissionMiddleware\PermissionList;
class Permission extends PermissionList
{
public const GUEST = 1;
public const USER = 2;
public const ADMIN = 4;
}
use App\Permission;
use Codevia\PermissionMiddleware\PermissionMiddleware;
$_SESSION[PermissionMiddleware::SESSION_PERMISSION] = Permission::USER;
// public/index.php
;
use Codevia\PermissionMiddleware\PermissionMiddleware;
use Slim\Factory\AppFactory;
$app = AppFactory::create();
$app->addMiddleware(new PermissionMiddleware(
new Permission(Permission::GUEST) // Permission::GUEST is your default
));
use App\Permission as P;
$app->get('/test', [TestController::class, 'testMethod', P::USER | P::ADMIN]);
$app->get('/public', [TestController::class, 'publicMethod', P::GUEST]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.