PHPackages                             peekandpoke/slumber-data - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. peekandpoke/slumber-data

ActiveLibrary[Database &amp; ORM](/categories/database)

peekandpoke/slumber-data
========================

ODM on top of the Slumber serialization library

v0.2.2(8y ago)0656BSD-3-ClausePHPPHP &gt;=7.1

Since Feb 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/PeekAndPoke/slumber-data)[ Packagist](https://packagist.org/packages/peekandpoke/slumber-data)[ RSS](/packages/peekandpoke-slumber-data/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (6)Used By (0)

[![Code Coverage](https://camo.githubusercontent.com/68227dfdd44cd7ca6715ecc5450ce9a7d2ee835bb60aedaff57e7ef5420cc10c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f736c756d6265722d646174612f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/slumber-data/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9dbcf324d7db1f1398b6a1dbf4d8b2f8969c4be18feb2d65363f10e40d4ee12e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f736c756d6265722d646174612f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/slumber-data/?branch=master)[![Build Status](https://camo.githubusercontent.com/6d4fa76d5a222ed042086b03a3f33b4600636b0117b82e94bbd3985d9eb576fa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f736c756d6265722d646174612f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/slumber-data/build-status/master)

Slumber-Data
============

[](#slumber-data)

Slumber-data is a Object-Document-Maooer (ODM) built on top of [Slumber](https://github.com/PeekAndPoke/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
-----------

[](#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
---------------

[](#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
-------------

[](#core-concepts)

### Entity pooling

[](#entity-pooling)

### RepositoryRegistry

[](#repositoryregistry)

### Storage Drivers

[](#storage-drivers)

Index builder
-------------

[](#index-builder)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

5

Last Release

2992d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82d9145b8f142b52aa21e66cddb1e493e4f6dbcd0629f6a65204260e890dca5c?d=identicon)[PeekAndPoke](/maintainers/PeekAndPoke)

---

Top Contributors

[![PeekAndPoke](https://avatars.githubusercontent.com/u/753129?v=4)](https://github.com/PeekAndPoke "PeekAndPoke (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/peekandpoke-slumber-data/health.svg)

```
[![Health](https://phpackages.com/badges/peekandpoke-slumber-data/health.svg)](https://phpackages.com/packages/peekandpoke-slumber-data)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M402](/packages/robmorgan-phinx)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M340](/packages/drupal-core-recommended)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
