vima / core
Framework-agnostic RBAC + ABAC access control engine with pluggable storage backends and a built-in CLI.
Requires
- php: >=8.1
- symfony/console: ^7.3
Requires (Dev)
- pestphp/pest: ^4.1
This package is not auto-updated.
Last update: 2025-09-19 05:15:39 UTC
README
Vima Core is a framework-independent authorization library that provides a clean foundation for RBAC (Role-Based Access Control) and ABAC (Attribute-Based Access Control).
It is designed to be extended by framework-specific packages (e.g. vima/laravel
, vima/symfony
) while staying lightweight and testable at the core.
โจ Features
-
๐ Entities:
User
,Role
,Permission
-
๐ Contracts: Interfaces for storage & access logic
-
๐ Storage: In-memory repositories for testing & prototyping
-
โ๏ธ Services:
AccessManager
โ RBAC & ABAC evaluationPolicyRegistry
โ central registry for ABAC rules
-
๐ Framework Agnostic: Works in any PHP project
-
๐งช Pest tests included (100% coverage)
๐ฆ Installation
composer require vima/core
๐ง Basic Usage
1. Define Roles & Permissions
use Vima\Core\Entities\Role; use Vima\Core\Entities\Permission; $admin = Role::define('admin'); $editor = Role::define('editor'); $updatePosts = Permission::define('posts.update'); $deletePosts = Permission::define('posts.delete'); $admin->addPermission($updatePosts)->addPermission($deletePosts); $editor->addPermission($updatePosts);
2. Create Users & Assign Roles
use Vima\Core\Entities\User; $alice = new User(1); $alice->assignRole($admin); $bob = new User(2); $bob->assignRole($editor);
3. RBAC โ Check Access
use Vima\Core\Services\AccessManager; $manager = new AccessManager(); $manager->can($alice, 'posts.delete'); // true $manager->can($bob, 'posts.delete'); // false
4. ABAC โ Define Policies
use Vima\Core\Services\PolicyRegistry; $policies = PolicyRegistry::define([ 'posts.update' => fn(User $user, $post) => $user->getId() === $post->ownerId, ]); $manager = new AccessManager($policies); $post = (object) ['ownerId' => 2]; $manager->evaluatePolicy($bob, 'posts.update', $post); // true (owner matches) $manager->evaluatePolicy($alice, 'posts.update', $post); // false
๐ CLI
The package ships with a lightweight CLI (via Symfony Console).
php vendor/bin/vima
Example commands:
php vendor/bin/vima list php vendor/bin/vima make:role admin php vendor/bin/vima make:permission posts.update
๐งช Testing
This package uses Pest for testing.
Run the test suite:
composer test
With coverage:
composer test-coverage
Expected: 100% code coverage โ
๐ Package Structure
src/
โโโ Contracts/ # Interfaces
โโโ Entities/ # User, Role, Permission
โโโ Exceptions/ # Domain-specific exceptions
โโโ Services/ # AccessManager, PolicyRegistry
โโโ Storage/ # InMemory repositories
โโโ Console/ # CLI entrypoint
tests/ # Pest tests
๐ฎ Roadmap
- Add persistence adapters (DB, cache, file storage)
- Framework integrations (Laravel, Symfony, CI4)
- Policy composition (
can
+evaluatePolicy
) - Middleware support for HTTP frameworks
๐ License
MIT License. Do whatever you want, just donโt blame us if you lock yourself out. ๐