eman-development-design / leaf-orm
1.0.1
2018-04-25 03:10 UTC
Requires
- php: >=7.1.0
- mongodb/mongodb: ^1.1
This package is auto-updated.
Last update: 2022-02-01 13:12:56 UTC
README
一个轻量级的 ORM 风格库,用于使用 PHP 与 MongoDB
此包已被弃用,新的库是 MongoDB Helpers
要求
- PHP 7.1 或更高版本
- MongoDB 扩展 1.1 或更高版本
安装
composer require eman-development-design/Leaf-Orm
使用
有两个简单的组件,一个模型和一个仓库对象。
模型
以下是一个示例
use MongoDB\BSON\Serializable; use MongoDB\Model\BSONDocument; use Leaf\Model\MongoModel class User implements Serializable, MongoModel { public $userGuid; public $email; public $firstName; public $lastName; public function bsonSerialize() : array { return [ 'UserGuid' => $this->userGuid, 'Email' => $this->email, 'FirstName' => $this->firstName, 'LastName' => $this->lastName ]; } public function map(BSONDocument $document) { $this->userGuid = $document['UserGuid']; $this->email = $document['Email']; $this->firstName = $document['FirstName']; $this->lastName = $document['LastName']; } public function toArray() : array { return [ 'UserGuid' => $this->userGuid, 'Email' => $this->email, 'FirstName' => $this->firstName, 'LastName' => $this->lastName ]; } }
map
将从 BSON 文档中读取并填充模型。
toArray
将模型转换为数组。
仓库
MongoRepository
用于仓库层,它只有一个方法,用于获取集合。
错误、建议
填写问题票据报告任何问题或提出改进此库的建议。
贡献
欢迎希望为此项目做出贡献的人,只需创建一个 pull request,我将对所有更改进行审查。