定制 99designs/moa 二次开发

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

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

99designs/moa

Composer 安装命令:

composer require 99designs/moa

包简介

The rightweight data mapper for mongoDB and PHP 5.3+

README 文档

README

Moa is an Object - Document Mapper, built to persist business domain objects in mongoDB.

Build Status

Why?

  • Does the bare minimum to be useful
  • Mongo query methods are already pretty good, all that's missing is some validation and typed de/serialisation
  • Built to integrate easily into existing applications
  • Zero dependencies
  • Well tested
  • Easy to create custom types with de/serialisation behaviours and validation rules

Installation

Getting Started

In your app start up code, add something that looks like the following:

<?php

$connection = new Mongo(); // or whatever
Moa::setup($connection->mydatabase);

Optionally, a callback can be provided to lazily connect on demand:

<?php

Moa::setup(function() {
    $connection = new Mongo();
    return $connection->someDb; 
});

Also, extra databases can be configured:

<?php

$connection = new Mongo(); // or whatever
Moa::setup($connection->mydatabase);
Moa::instance()->addDatabase('anotherDb', $connection->differentDb); // also takes a callback

Defining Models

Model classes can be defined like so:

<?php

class TestDocument extends Moa\DomainObject
{
    public function properties()
    {
        return array(
            'myInt' => new Moa\Types\IntegerField(array('required' => true)),            
            'myString' => new Moa\Types\StringField(),
            'myArray' => new Moa\Types\ArrayField(),
            'myOwnSelf' => new Moa\Types\EmbeddedDocumentField(array('type'=>'TestDocument')),
        );
    }
}
  • For a full list of field types and their behaviours, see the Moa\Types namespace
  • Indexes may also be defined (override DomainObject::indexes())
  • Domain objects can also specify the database they want to persist to (override DomainObject::getDatabaseName())

Querying

The query syntax is the same as the default PHP mongo driver, but accessed statically from the domain object you hope to query, eg

<?php

$docs = TestDocument::find(array('myString'=>'value'));

// it is also possible to use cursor methods
$docs = TestDocument::find(array('myString'=>'value'))->skip(20)->limit(10);

// findOne also works
$doc = TestDocument::findOne(array('myString'=>'value')); // this could except

// Documents may be saved via a call to save()
$doc->myInt = 123;
$doc->save();

// Documents can be deleted
TestDocument::remove(array('myString' => 'value')); // Deletes all documents with a field 'myString' with value of 'value'

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 28
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-09-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固