peekandpoke/slumber-data 问题修复 & 功能扩展

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

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

peekandpoke/slumber-data

Composer 安装命令:

composer require peekandpoke/slumber-data

包简介

ODM on top of the Slumber serialization library

README 文档

README

Code Coverage Scrutinizer Code Quality Build Status

Slumber-Data

Slumber-data is a Object-Document-Maooer (ODM) built on top of Slumber. It uses to serializing / unserializing mechanism of Slumber under the hood.

Currently only a MongoDB storage driver is implemented.
In theory it is possible to implement new drivers for other document databases, e.g. CouchDB.

Annotations

Slumber-Data uses annotations as well as Slumber does. Here are some examples

/**
 *
 * Define a compound index on multiple fields 
 *
 * @Slumber\Store\CompoundIndex(
 *   background = true,
 *   def = { "email" : 1, "type" : 1 },
 *   unique = true,
 *   dropDups = true
 * )
 */

class MyClass {

    /**
     * @Slumber\AsString()
     * @Slumber\Store\Indexed(unique = true)
     */
    private $id;
   
    /**
     * @Slumber\AsString()
     * @Slumber\Store\Indexed(unique = true)
     */
    private $email;

    /**
     * @Slumber\AsString()
     */
    private $type;
    
    /* ... */
}

Getting started

In order to used the Slumber storage some things need to be set up in the begging:

// we need a PSR-11 ContainerInterface ... it must be found somewhere in your application
$di = ...; 

// we need a PSR-3 logger ... probably this is present in your application already
$logger = ...; 

// We need a doctrine cache for caching the annotations
// ... otherwise annotations will need to be parsed on each request, which is slow 
// ... ideally APCU as it is the fastest for our purpose
$cache = new ApcuCache();

// we need a doctrine annotation reader
$annotationReader = new CachedReader(new AnnotationReader(), $cache, true);

// SLUMBER: we need an instance of the entity config reader (the one that reads the Slumber annotations) 
$configReader = new MongoDbEntityConfigReaderCached(
    new MongoDbEntityConfigReaderImpl(
        new AnnotatedEntityConfigReader($di, $annotationReader, new MongoDbPropertyMarkerToMapper())
    ),
    $cache,
    'test',  // the cache-prefix
    true     // debug mode
)

// SLUMBER: we need the codec set for serializing / unserializing
$codecSet = new MongoDbCodecSet($di, $configReader, $pool, $storage, $logger)

// SLUMBER: we need a storage instance
$storage  = new StorageImpl($entityPool, $registry);

// we need a mongo db connection
$dbClient = new MongoDB\Client('mongodb://localhost:27017', ['connect' => false]);
$database = $dbClient->selectDatabase("my-database");


// then we need to register repository providers on the storage

$registry->registerProvider(
  // the name in the registry
  "users",                                    
  // FQCNs of all classes stored in this collection
  "[User::class, AdvancedUser::class],                   
  // callback that creates the repository class
  function () use ($entityPool, $codecSet, $database) {   

    // get the collection from the database
    $collection = $database->selectCollection("users");
    // get a reflection of the main class stored in the collection
    $reflect    = new \ReflectionClass(User::class);

    return new EntityRepository(
      "users", 
      new MongoDbStorageDriver($entityPool, $codecSet, $collection, $reflect)
    );
});

Core concepts

Entity pooling

RepositoryRegistry

Storage Drivers

Index builder

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固