wcatron/common-db-framework 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wcatron/common-db-framework

Composer 安装命令:

composer require wcatron/common-db-framework

包简介

Common classes shared between DB Frameworks that want to link between each other.

README 文档

README

Common classes shared between DB Frameworks that want to link between each other.

Getting Started

Common DB is not a database connection itself, instead it serves as a starting point for various DB frameworks. Currently there are two:

Default Hierarchy

Any framework will need a Database class that inherits the DB class and handles the connection to the database. Then there needs to be a default object class that handles specific object related tasks unique to your database type. For example in MongoDB (a document based database) the default object class is Document all classes using that framework will inherit from that class. For MySQL the default object class is Row. These classes should also set the $dbClass static variable to your frameworks class that inherits DB. This allows for dependency injection later on. How the framework is used from this point is dependant on the framework.

LinkedObject

If setup properly there are helpful classes like LinkedObject which can be used to link a DBObject from one framework/DB to a DBObject from a different framework. Examples can be found in the MongoDB and MySQL frameworks.

Singleton vs Dependency Injection

DB instances can be accessed by using DB::getInstance() which will access a singleton instance of the DB framework. However Common DB has built in support for Dependency Injection. When in a DBObject class use static::getDBInstance() to access the DB object being used for that class. This means you can setup a TestDB class that forces a particular output and then call your default object class setDBInstance() function (i.e. Row::setDBInstance(TestDB::class)) to inject the dependency. This will setup a singleton, but it will be a new singleton and can be of any class that inherits DB.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固