Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/commonphp/drivers
Provides a robust framework for managing driver implementations in PHP applications. By leveraging attributes and contracts, it offers a flexible system to register, enable, and utilize various drivers seamlessly within your projects.
https://github.com/commonphp/drivers
commonphp driver-management modular modular-architecture open-source php
Last synced: about 2 months ago
JSON representation
Provides a robust framework for managing driver implementations in PHP applications. By leveraging attributes and contracts, it offers a flexible system to register, enable, and utilize various drivers seamlessly within your projects.
- Host: GitHub
- URL: https://github.com/commonphp/drivers
- Owner: commonphp
- License: mit
- Created: 2024-02-17T05:01:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-02-17T17:30:57.000Z (11 months ago)
- Last Synced: 2024-11-18T21:05:28.440Z (2 months ago)
- Topics: commonphp, driver-management, modular, modular-architecture, open-source, php
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# CommonPHP Driver Management Library
The CommonPHP Driver Management Library provides a robust framework for managing driver implementations in PHP applications. By leveraging attributes and contracts, it offers a flexible system to register, enable, and utilize various drivers seamlessly within your projects.
## Features
- **Flexible Driver Configuration**: Configure drivers using PHP 8 Attributes or by specifying driver contracts.
- **Dynamic Driver Support Checking**: Determine if a class is supported as a driver based on its configuration.
- **Driver Instantiation**: On-demand driver instantiation managed by the CommonPHP Service Management framework, ensuring dependency injection and singleton management.
- **Comprehensive Exception Handling**: Detailed exception handling for configuration errors, unsupported drivers, and instantiation issues.## Installation
Use Composer to integrate the Driver Management Library into your project:
```bash
composer require comphp/drivers
```## Configuration
### Define Driver Contracts or Attributes
Implement `DriverContract` for interface/abstract class-based drivers or use `DriverAttributeContract` to mark drivers with attributes.
### Register and Configure DriverManager
```php
use CommonPHP\Drivers\DriverManager;
use CommonPHP\Drivers\ServiceProviders\DriverManagerServiceProvider;
use CommonPHP\ServiceManagement\ServiceManager;// Initialize ServiceManager and register DriverManagerServiceProvider
$serviceManager = new ServiceManager();
$serviceManager->providers->registerProvider(DriverManagerServiceProvider::class);// Retrieve an instance of DriverManager
$driverManager = $serviceManager->get(DriverManager::class);// Configure DriverManager with an attribute or contract class
$driverManager->configure(
attributeClass: YourDriverAttribute::class,
contractClass: YourDriverContract::class
);
```## Usage
### Enable a Driver
Once a driver meets the configured criteria (attribute or contract), enable it using:
```php
$driverManager->enable(YourDriverClass::class);
```### Utilize an Enabled Driver
Retrieve and use an enabled driver:
```php
$driver = $driverManager->get(YourDriverClass::class);
$driver->performAction();
```## Contributing
Contributions to the CommonPHP Driver Management Library are welcome. Please follow the contribution guidelines provided in the repository for submitting pull requests or issues.
## License
This library is released under the MIT license. See [LICENSE](LICENSE) for details.