PHPackages                             matryoshka-model/matryoshka - 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. matryoshka-model/matryoshka

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

matryoshka-model/matryoshka
===========================

A lightweight framework that provides a standard and easy way to implement a model service layer

v0.8.1(10y ago)52.0k3[8 issues](https://github.com/matryoshka-model/matryoshka/issues)7BSD-2-ClausePHPPHP &gt;=5.5

Since Aug 28Pushed 9y agoCompare

[ Source](https://github.com/matryoshka-model/matryoshka)[ Packagist](https://packagist.org/packages/matryoshka-model/matryoshka)[ Docs](https://github.com/matryoshka-model/matryoshka)[ RSS](/packages/matryoshka-model-matryoshka/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (21)Used By (7)

[![](./docs/assets/images/matryoshka_logo_hi_res_512.png)](./docs/assets/images/matryoshka_logo_hi_res_512.png)

Matryoshka ---------- [![Latest Stable Version](https://camo.githubusercontent.com/c8d8b1ea228dae503aecb1d8f37bbe33e3647a90ce434faec917c8899249efea/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617472796f73686b612d6d6f64656c2f6d617472796f73686b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matryoshka-model/matryoshka) [![Build Status](https://camo.githubusercontent.com/038adf9c184dd34599b737dabb2ac115cbf80d628ebcd376ee7453e22a72e6c2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d617472796f73686b612d6d6f64656c2f6d617472796f73686b612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/matryoshka-model/matryoshka) [![Coveralls branch](https://camo.githubusercontent.com/eb2fb77e1b8dd9e4faefc10123f10928cec612c2949ffed26dd51e8b61b57ed2/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6d617472796f73686b612d6d6f64656c2f6d617472796f73686b612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/matryoshka-model/matryoshka?branch=master) [![Total Downloads](https://camo.githubusercontent.com/ea674b3b32d05f37e78bbee458729fef51d891316eec10d06f8ac250d92fbc27/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617472796f73686b612d6d6f64656c2f6d617472796f73686b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matryoshka-model/matryoshka) [![Matryoshka Model's Slack](https://camo.githubusercontent.com/7b173ae656e6f68002d07e15d05a8323c38983856f38238b76f6baf1821d8b54/687474703a2f2f6d617472796f73686b612d736c61636b696e2e6865726f6b756170702e636f6d2f62616467652e7376673f7374796c653d666c61742d737175617265)](http://matryoshka-slackin.herokuapp.com)

> Matryoshka is not an ORM.

Matryoshka is a micro framework (&lt; 1000 SLOC) that helps you to build your model [service layer](http://martinfowler.com/eaaCatalog/serviceLayer.html) in a structured way without the need of using the complex ORM systems, avoiding overheads. Matryoshka does not provide a persistence layer implementation itself and does not require adapters: you have the full control over the persistence layer by implementing [criterias](http://en.wikipedia.org/wiki/Criteria_Pattern). Its layered design aims to provide a strong seperation between the persistence and the rest of your application, whether the datagateway you need to use (i.e. Zend\\Db, MongoCollection, a REST client or anything else). In order to simplify your job with common persistence systems, a set of [wrappers](http://en.wikipedia.org/wiki/Wrapper_library) are already provided as separated repositories. They are just a set of ready-to-use classes. Matryoshka uses a few of [Zend Framework 2](http://framework.zend.com/) components but does not require you to use Zend Framework: you are free to use Matryoshka with any framework. Last but not least, the Matryoshka design allows you to use just single components or all of them in cooperations. Anyway you can decide how to design your own application model: only you know what your application needs.

[Read more about Matryoshka components](docs/Overview.md)

#### Wrappers:

[](#wrappers)

- [rest-wrapper](https://github.com/matryoshka-model/rest-wrapper)
- [mongo-wrapper](https://github.com/matryoshka-model/mongo-wrapper)

#### Integration modules:

[](#integration-modules)

- [zf2-matryoshka-module](https://github.com/matryoshka-model/zf2-matryoshka-module)
- [zf-apigility-matryoshka](https://github.com/matryoshka-model/zf-apigility-matryoshka)

#### Others:

[](#others)

Other addons, plugins, and modules made with Matryoshka.

- [mongo-transactional](https://github.com/matryoshka-model/mongo-transactional)

#### Community

[](#community)

For questions and support please visit the [slack channel](http://matryoshka.slack.com) (get an invite [here](http://matryoshka-slackin.herokuapp.com)).

Theory of operation
-------------------

[](#theory-of-operation)

Matryoshka doesn't provide a persistence layer implementation itself, but it can work with any third party implementation that acts as datagateway. Regardless of the datagateway you choose, Matryoshka provides to clients (i.e. your controller) the same set of handful API. To accomplish this goal Matryoshka uses criteria interfaces that developer have to implement.

Think a criteria as a small piece of code that tell to the datagateway how to perform an operation on your dataset: for example filter some rows. So, each criteria represent a simple task: different kind of criteria interfaces are defined for write, read and delete operations. Also, in concrete criteria classes, the developer can add methods to augment the "query interface" with domain specific logic.

A concrete criteria class acts both as a criterion defining a query interface and also as [mediator](http://en.wikipedia.org/wiki/Mediator_pattern) between model layer and datagateway. Only criteria classes performs operations against the datagateway interface, instead Matryoshka's components do not.

So Matryoska is unawareness about the datagateway interface, that makes it working with any kind of third-party datagateway implementation.

Matryoshka dolls (layers):

- **ModelManager**A dedicated service locator for your model service classes (i.e., model)
- **Model**An end user service that manages a collection of related data by using criterias (similar to a table gateway or a document collection)
- **Criteria**An "user query interface" from an API point of view, also acting as mediator between model and datagateway

Finally, in the empty space of the innermost doll you can put:

- **Datagateway**Any kind of datagateway, like `Zend\Db\TableGateway` or `\MongoCollection` or a REST client

Basic usage example:

```
//Assiming MyModel an instance of a Matryoshka Model class registered in Matryoshka model manager
$myModel = $modelManager->get('MyModel');

//Assuming MyCriteria a class extending ReadableCriteriaInterface
$criteria = new MyCriteria();
$criteria->setMyCustomFilter('foo');

//Execute a query
$resultSet = $myModel->find($criteria);
```

Installation
------------

[](#installation)

Install it using [composer](http://getcomposer.org).

Add the following to your `composer.json` file:

```
"require": {
    "matryoshka-model/matryoshka": "~0.8.0"
}

```

Requirements
------------

[](#requirements)

- PHP &gt;= 5.5

Configuration
-------------

[](#configuration)

[Read about Matryoshka configuration here](docs/Configuration.md)

---

[![Analytics](https://camo.githubusercontent.com/b937d8ae077f1ece14dce453fcdf08c2731f91ae2121d2b4c5b876a5b6f8ed91/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d34393635373137362d322f6d617472796f73686b613f666c6174)](https://github.com/igrigorik/ga-beacon)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.2% 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 ~38 days

Recently: every ~104 days

Total

17

Last Release

3665d ago

PHP version history (2 changes)v0.0.1PHP &gt;=5.4.0

v0.7.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/504f6b7857bcaa1337d91366a2768d65dcfcdf12ca9281422f7b4d9404aba4ac?d=identicon)[fntlnz](/maintainers/fntlnz)

![](https://avatars.githubusercontent.com/u/120051?v=4)[Leo Di Donato](/maintainers/leodido)[@leodido](https://github.com/leodido)

![](https://www.gravatar.com/avatar/376c46dedf9febc5ed5f99f8aed6269b93e2e7ea09b71e2d8f26faf078fd10ad?d=identicon)[leogr](/maintainers/leogr)

![](https://avatars.githubusercontent.com/u/3627018?v=4)[visa4](/maintainers/visa4)[@visa4](https://github.com/visa4)

---

Top Contributors

[![leogr](https://avatars.githubusercontent.com/u/3390997?v=4)](https://github.com/leogr "leogr (201 commits)")[![leodido](https://avatars.githubusercontent.com/u/120051?v=4)](https://github.com/leodido "leodido (86 commits)")[![visa4](https://avatars.githubusercontent.com/u/3627018?v=4)](https://github.com/visa4 "visa4 (25 commits)")[![fntlnz](https://avatars.githubusercontent.com/u/3083633?v=4)](https://github.com/fntlnz "fntlnz (21 commits)")[![theboolean](https://avatars.githubusercontent.com/u/1123102?v=4)](https://github.com/theboolean "theboolean (1 commits)")

---

Tags

databasemodeldbmvccriteriaback-endmatryoshkamodel-service

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matryoshka-model-matryoshka/health.svg)

```
[![Health](https://phpackages.com/badges/matryoshka-model-matryoshka/health.svg)](https://phpackages.com/packages/matryoshka-model-matryoshka)
```

###  Alternatives

[symlex/doctrine-active-record

Object-oriented CRUD for Doctrine DBAL

308.7k2](/packages/symlex-doctrine-active-record)[lastzero/doctrine-active-record

Object-oriented CRUD for Doctrine DBAL

306.0k](/packages/lastzero-doctrine-active-record)

PHPackages © 2026

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