Download the PHP package cdoebler/php-generic-user-switcher without Composer
On this page you can find all versions of the php package cdoebler/php-generic-user-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cdoebler/php-generic-user-switcher
More information about cdoebler/php-generic-user-switcher
Files in cdoebler/php-generic-user-switcher
Package php-generic-user-switcher
Short Description A framework-agnostic PHP package for user switching with a frontend component.
License MIT
Informations about the package php-generic-user-switcher
PHP Generic User Switcher
A framework-agnostic PHP package for user switching with an integrated frontend component. Perfect for development and debugging, allowing seamless impersonation of different users without logging in and out.
Features
- Framework-Agnostic: Works with any PHP application or framework
- Clean Interface-Based Design: Easy to extend and customize
- Session-Based Impersonation: Non-destructive user switching with preserved original user identity
- Visual UI Component: Beautiful, searchable dropdown widget for quick user switching
- Type-Safe: Built with PHP 8.2+ strict types and PHPStan level 10 validation
- Zero Dependencies: No external production dependencies
- Fully Tested: Comprehensive test coverage with Pest
Requirements
- PHP 8.2 or higher
- Session support (for default
SessionImpersonator)
Installation
Install via Composer:
Quick Start
Basic Usage
Handling User Switching
In your application's bootstrap or middleware, handle the switch request:
Usage Examples
Example 1: Simple In-Memory Users
Example 2: Custom Position and Styling
Example 3: Custom Session Key
Example 4: Database User Provider
Create a custom provider that loads users from your database:
Example 5: Custom User Implementation
Implement the UserInterface for your existing user models:
Example 6: Laravel Integration
Example 7: Symfony Integration
Configuration Options
Renderer Options
The UserSwitcherRenderer::render() method accepts an array of options:
| Option | Type | Default | Description |
|---|---|---|---|
position |
string |
'bottom-right' |
Widget position: top-left, top-right, bottom-left, bottom-right |
z_index |
int |
9999 |
CSS z-index value for the floating widget |
param_name |
string |
'_switch_user' |
URL query parameter name used for switching users |
SessionImpersonator Options
Interface Reference
UserInterface
UserProviderInterface
ImpersonatorInterface
Security Considerations
This package is designed for development and debugging purposes only.
Important security notes:
- Never enable in production - User switching should only be available in development/staging environments
- Add authorization checks - Ensure only authorized users (admins, developers) can switch users
-
Environment gating - Use environment checks to disable in production:
- Audit logging - Consider logging all impersonation events for security auditing
Example: Implementing Audit Logging
The package supports optional audit logging to track all impersonation events:
Development
Running Tests
Code Quality
This package maintains high code quality standards:
- PHPStan Level 10: Maximum static analysis strictness
- Pest Testing: Modern PHP testing with comprehensive coverage
- Rector: Automated code modernization and consistency
- Architecture Tests: Enforces coding standards and best practices
Architecture
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
composer test) - Code follows PSR-12 standards
- PHPStan level 10 passes
- New features include tests
License
MIT License. See LICENSE.md file for details.
Author
Christian Doebler
- Email: [email protected]
- GitHub: @cdoebler
Changelog
1.0.0 (Current)
- Initial release
- Framework-agnostic user switching
- Session-based impersonation
- Frontend UI component
- In-memory user provider
- Generic user implementation
- Full test coverage