PHPackages                             mixteer/persistor - 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. mixteer/persistor

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

mixteer/persistor
=================

A minimal ORM libray for quick development.

120PHP

Since Apr 28Pushed 11y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Persistor - a minimalistic ORM
==============================

[](#persistor---a-minimalistic-orm)

> This library is not production ready because it is not tested yet. Please don't use it in production but do play with it! It's a proof-of-concept.

Persistor is a minimal ORM that helps with object persistence without getting in your way. The basic idea is for you to be able to override any of it's behavior whenever it doesn't accomplish what you want, at least that's the end goal.

Right now, it's at version 0.1.0 so it's not ready for production but if you find the idea worth it, please, submit a pull requests if you contribute and raise issues if you're trying it.

Install
-------

[](#install)

The library is available on [packagist](https://packagist.org/) and installable via [composer](http://getcomposer.org).

```
{
    "require": {
        "mixteer/persistor": "dev-master"
    }
}
```

Concepts
--------

[](#concepts)

Persistor is built around a few design patterns so that you don't have to write them all every time you need them.

1. *Metadata mapper* - this is a class that maps your objects' properties to the corresponding database table fields. The metadata mapper interface provided by Persistor requires a little bit more but nothing out of the ordinary.
2. *Identity map* - an object that keeps all the objects already loaded from the database for faster future access. This will remain transparent to you so you'll generally won't need to bother. But many times, we want our objects to be rather cache than deleted at the end of the request so as the library matures, the API will be stabilised so you might code against a provided interface.
3. *Unit of work* - an object that coordinates the writing of changes to the database and manages concurrency problems. With persistor, the unit of work is coupled with a dependency manager so you might declare your objects dependencies in order to take care of referential integrity.
4. *Lazy loading* - an object that doesn't contain the all data you need but knows how to get it. The lazy loader used by Persistor is rather simple. You specify how you'd like your object loaded when requested and you get an anonymous function that will execute when the data is requested.

Those are the 4 main design patterns that make Persistor work. Everything was kept simple for the sake of the developer being fully in control.

Usage
-----

[](#usage)

To get started using persistor, you need a metadata mapper class that tells Persistor about your objects. Let's assume you have a `Progeny` class whose objects you'd like to persist.

```
