Download the PHP package casbin/webman-permission without Composer
On this page you can find all versions of the php package casbin/webman-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download casbin/webman-permission
More information about casbin/webman-permission
Files in casbin/webman-permission
Package webman-permission
Short Description webman casbin permission plugin
License MIT
Informations about the package webman-permission
🐇 An Authorization Library for Webman Plugin 🐇
🐇 Webman Authorization Plugin Based on Casbin 🐇
An authorization library that supports access control models like ACL, RBAC, ABAC for Webman plugin.
Table of Contents
- Installation
- Configuration
- Dependency Injection
- Database Configuration
- Usage
- Multiple Driver Configuration
- Tutorials
- Testing
- Contributing
- Credits
- Troubleshooting
Installation
Install the package via Composer:
Configuration
Dependency Injection
Modify the config/container.php configuration file as follows:
Database Configuration
By default, the policy storage uses ThinkORM.
1. Model Configuration
The default uses ThinkORM. Modify the database configuration in config/thinkorm.php.
Note: If using Laravel database, configure as follows:
- Modify the database configuration in
config/database.php- Change the
adapterinconfig/plugin/casbin/webman-permission/permission.phpto the Laravel adapter
2. Create casbin_rule Table
Execute the following SQL to create the policy rules table:
3. Configure Redis
Configure your Redis settings in config/redis.php.
4. Restart Webman
Usage
After successful installation, you can use the library as follows:
Basic Operations
Permission Check
Multiple Driver Configuration
You can use multiple driver configurations:
For more API details, refer to the Casbin API Documentation.
Tutorials
- Casbin Permission Practice: Getting Started (Chinese)
- Casbin Permission Practice: RBAC Authorization Based on Roles (Chinese)
- Casbin Permission Practice: RESTful and Middleware Usage (Chinese)
- Casbin Permission Practice: Using Custom Matching Functions (Chinese)
- Webman Practice Tutorial: Using Casbin Permission Control (Chinese)
Testing
This project includes a comprehensive unit test suite covering the following aspects:
Test File Structure
Test Coverage
-
Basic Functionality
- Permission add, remove, check
- Role assignment, removal
- Policy management
-
Adapter Tests
- Database operations
- Filter functionality
- Batch operations
- Transaction handling
-
Edge Cases
- Null value handling
- Special characters
- Large data volumes
- Performance testing
-
Integration Tests
- Complete RBAC workflow
- Domain permission control
- Multi-driver support
- Complex business scenarios
- Error Handling
- Exception scenarios
- Invalid input
- Concurrent access
Running Tests
Requirements
- PHP >= 8.1
- PHPUnit >= 9.0
- Database connection
- Redis connection
Test Environment
The test environment automatically creates the following tables:
casbin_rule- Default policy tableother_casbin_rule- Other driver policy table
Best Practices
-
Writing New Tests
- Inherit from appropriate test base classes
- Follow naming conventions
- Add necessary assertions
-
Test Data Management
- Use
setUp()andtearDown()methods - Ensure test data isolation
- Clean up test data
- Use
- Test Coverage
- Cover normal workflows
- Test exception scenarios
- Verify boundary conditions
Contributing
Adding New Features
- Write corresponding test cases for new features
- Ensure test coverage meets requirements
- Run the complete test suite
- Check test status before submitting code
Bug Fixes
- Write reproduction tests for bugs
- Verify tests pass after fixing bugs
- Ensure existing functionality is not affected
Credits
Built on top of Casbin. For full documentation, visit the official website.
Advanced Configuration
Removing PHP-DI Dependency (Not Recommended)
1. Uninstall the DI dependency package: 2. Modify the `Casbin\WebmanPermission\Permission` file: Replace: With: > **Warning:** This approach has high coupling and is not recommended. For more information, visit: https://www.workerman.net/doc/webman/di.htmlTroubleshooting
Think-ORM 4.0 Compatibility
Error: Object not contained in WeakMap or array_search(): Argument #2 ($haystack) must be of type array, null given
Solution: This package fully supports think-orm 4.0+. If you encounter WeakMap errors:
-
Ensure you're using the latest version:
- For detailed information, see:
- Think-ORM 4.0 Fix Guide
- Think-ORM Compatibility Guide
Supported Versions:
- ✅ think-orm 2.0.53+
- ✅ think-orm 3.x
- ✅ think-orm 4.0.30+
Laravel Driver Error
Error: Call to a member function connection() on null
Solution: Check if your local database proxy is working correctly. Using Docker container host addresses like dnmp-mysql may cause this issue.
License
MIT License
All versions of webman-permission with dependencies
casbin/casbin Version ~4.0
topthink/think-orm Version ^2.0.53 || ^3.0.0 || ^4.0.30 || dev-master
php-di/php-di Version ^7.0
doctrine/annotations Version ^2.0
workerman/redis Version ^2.0