mtrbean/mongo-json 问题修复 & 功能扩展

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

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

mtrbean/mongo-json

Composer 安装命令:

composer require mtrbean/mongo-json

包简介

A helper library for serializing MongoDB types to JSON string

README 文档

README

A small library that JSON encode an Mongo document that contains MongoDB-specific types (e.g. MongoDate).

If you just use json_encode(), you will get some PHP specific results that makes it very difficult to interface with other part of your program. This library attempts to implement the 'strict mode' and also the 'javascript (JSONP) mode' defined in http://docs.mongodb.org/manual/reference/mongodb-extended-json/

Installation using Composer

Create a composer.json file in your project root:

{
    "require": {
        "mtrbean/mongo-json": "1.*"
    }
}

Install via composer:

php composer.phar install

P.S. If you haven't already been using composer for managing your dependency, you can install it via:

curl -sS https://getcomposer.org/installer | php

Autoload

You can have the class MongoJson autoloaded using the mechanism provided by composer:

require 'vendor/autoload.php';

Usage

Strict Mode

$doc = array("dt" => new MongoDate);
echo MongoJson::strict($doc);

will print:

{"dt":{"$date":1371525158000}}

Extended Mode

$doc = array("dt" => new MongoDate);
echo MongoJson::extended($doc);

will print:

{"dt":new Date(1371525158000)}

Options

You can pass extra options that you can normally use with json_encode()

$doc = array("_id" => new MongoId, "regex" => new MongoRegex('/^acme.*corp/i'));
echo MongoJson::extended($doc, JSON_PRETTY_PRINT); // will prettify the JSON string

will print:

{
    "_id": {
        "$oid": "51bfcdd71ede01d61a000000"
    },
    "regex": /^acme.*corp/i
}

License

MIT

Contribute

Feel free to fork and submit pull requests!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固