webcodr/mango 问题修复 & 功能扩展

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

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

webcodr/mango

Composer 安装命令:

composer require webcodr/mango

包简介

A MongoDB object document mapper for PHP

README 文档

README

Build Status

PHP version

A MongoDB object document mapper for PHP

Inspired by Mongoid for Ruby

Requirements

  • PHP 5.4
  • MongoDB driver for PHP (min. 1.2.0)
  • Composer

Setup

Add Mango to your project

$ php composer.phar require webcodr/mango:*

Create a document class

<?php

namespace Mango\Tests\Document;

use Mango\Document;
use Mango\DocumentInterface;

class User implements DocumentInterface
{
    use Document;

    private function addFields()
    {
        $this->addField('name', ['type' => 'String']);
        $this->addField('email', ['type' => 'String']);

        $this->addField(
            'created_at',
            [
                'type' => 'DateTime',
                'index' => true,
                'default' => 'now'
            ]
        );

        $this->addField(
            'updated_at',
            [
                'type' => 'DateTime',
                'index' => true,
                'default' => 'now'
            ]
        );
    }
}

You don't have to set a collection name. Mango uses the class name in lower case as collection name.

If you want to set a custom collection name, just override the method getCollectionName() in your own document classes.

There's no need to provide an id. Mango's document base class adds automatically the property '_id' with a fresh MongoId object.

Save a document

<?php

use Mango\Mango;
use Mango\DocumentManager;

use Document\User;

$mango = new Mango('mongodb://devserver:27017/galactica-actual');
$dm = new DocumentManager($mango);
$user = new User();
$user->name = 'William Adama';
$user->email 'william.adama@galactica.colonial-forces.gov';
$user->store();

Remove a document

$user->remove();

Querying

The methods find and where return a \Mango\Persistence\Cursor object or an object of the class \Collection\MutableMap. It depends on which method is called.

MutableMap is part of another WebCodr project called Collection. It provides several classes to replace PHP arrays and is much more fun to use. Check it out here.

Mango uses object hydration to automatically provide a result with document objects.

Find documents by id
One id
$user = User::find('abc')->first();
Multiple ids
$user = User::find('abc', 'def', 'ghi')->first();
Find all documents in collection
User::where()->each(function($user) {
    echo $user->name;
});
Find a document with certain field value
$user = User::where(['name' => 'William Adama']);
echo $user->count(); // result = 1
echo $user->first()->email; // result = william.adama@galactica.colonial-forces.gov

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固