定制 comphp/drivers 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

comphp/drivers

最新稳定版本:v0.1.1

Composer 安装命令:

composer require comphp/drivers

包简介

Allows for drivers to be dynamically managed

README 文档

README

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:

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

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:

$driverManager->enable(YourDriverClass::class);

Utilize an Enabled Driver

Retrieve and use an enabled driver:

$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 for details.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-17