Git Product home page Git Product logo

commonphp / drivers Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 0.0 12 KB

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.

License: MIT License

PHP 100.00%
commonphp driver-management modular modular-architecture open-source php

drivers's Introduction

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:

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.