PHPackages                             manuakasam/sam-versioning - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. manuakasam/sam-versioning

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

manuakasam/sam-versioning
=========================

A Module that eases the implementation of a version control for your entities

5151PHP

Since Nov 10Pushed 12y agoCompare

[ Source](https://github.com/manuakasam/SamVersioning)[ Packagist](https://packagist.org/packages/manuakasam/sam-versioning)[ RSS](/packages/manuakasam-sam-versioning/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

SamVersioning
=============

[](#samversioning)

This Module provides Features to keep versions of your DB-Entries. Using different Terminology, whenever you insert or update a Row from your DB-Tables, a copy of this very Row is saved into a separate Table. That is, if you configure this Module to to so ;)

[![Scrutinizer Quality Score](https://camo.githubusercontent.com/7c91f3aaef26be0a563ad1386bbe2909f72ca25aa6433cd296035b801bf89a15/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616e75616b6173616d2f53616d56657273696f6e696e672f6261646765732f7175616c6974792d73636f72652e706e673f733d31653734623562613330383836343336653763393066613238376561313031363232393161396638)](https://scrutinizer-ci.com/g/manuakasam/SamVersioning/)[![Build Status](https://camo.githubusercontent.com/8911bd3124ac4bec47105c976f5ce61479f9ee878523c71e50047a8b3f1445c9/68747470733a2f2f7472617669732d63692e6f72672f6d616e75616b6173616d2f53616d56657273696f6e696e672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/manuakasam/SamVersioning)[![Coverage Status](https://camo.githubusercontent.com/a4f5bcc81ed72ad41130dfb6a3213827836945e9d090566363ea90dda1e23350/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6d616e75616b6173616d2f53616d56657273696f6e696e672f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/manuakasam/SamVersioning?branch=master)

Modules Workflow
================

[](#modules-workflow)

The Workflow of this Module is very simple. Whenever an Event is triggered that you specify in this Modules config, the Entity will be serialized and copied into a dedicated db-table.

```
Example\Entity\Row1 - saved to DB
  -> serialize Row1
    -> insert to versioning table (ID: 1)
Example\Entity\Row1 - editted by someone
  -> serialize Row1
    -> insert to versioning table (ID: 2 - no update!)

```

Requirements
============

[](#requirements)

This Module is designed to work out of the Box with Doctrine 2 (`DoctrineORMModule`) and Zend Framework 2. While the ultimate goal will be to implement the same Features for `Zend\Db`, too, currently this is not supported.

Installation
============

[](#installation)

The easiest way to install this module is through the use of Composer:

```
composer.phar require manuakasam/sam-versioning dev-master

```

After that you should update your Database, this can either be done via doctrine

```
doctrine orm:validate-schema               // Everything OK? Next:
doctrine orm:schema-tool:update --dump-sql // Only updating what you're expecting? Next:
doctrine orm:schema-tool:update --force    // And we're good to go

```

or by using the `/data/schema.sql`-file.

All that's left is to add this Module to the loaded Modules within your `application.config.php` in the usual way.

```
return array(
    'modules' => array(
        'Application',
        'DoctrineModule',
        'DoctrineORMModule',
        'SamVersioning'         // Load order isn't realy important tho
    ),

```

Configuration
=============

[](#configuration)

The configuration is just as simple as the installation. Copy `/SamVersioning/config/sam-versioning.globa.php.dist`to your `/config/autoload` directory, remove the `.dist` extension and modify it's contents to your needs. The `versionify` array expects you to attack key=&gt;value pairs of ClassName =&gt; EventName. That way SamVersioning will be able to listen to those Events. An example could be:

```
return array(
    'sam_versioning' => array(
        'versionify' => array(
            'My\Namespaced\Service'    => 'eventname.additem.post',
            'My\Namespaced\Service'    => 'eventname.edititem.post',
            'Other\Namespaced\Service' => 'objecteditted',
        )
    )
);

```

Events? What Events?
====================

[](#events-what-events)

In the best scenario you already have your services set up in a way that they provide events that you can easily hook into. Often times however this is not the case, but changing your Services to provide events is nothing more than two lines of code. See the following example:

```
namespace MyNS\Services;
class SomeService {
    public function saveEntity($entity) {
        $this->dbMapper->save($entity);
    }
}

```

Like this, SamVersioning can do nothing to keep track of the Version of `$entity`, so let's modify the code to allow us to keep track of it. Be sure to attach the Entity to your event as parameter with the name `object`

```
namespace MyNS\Services;
class SomeService {
    public function saveEntity($entity) {
        $this->dbMapper->save($entity);

        $eventManager = new EventManager('MyNS\Services\SomeService');
                                                          // notice this array and the object key
        $eventManager->trigger('save-entity.post', $this, array('object' => $entity));
    }
}

```

And that's it, a configuration for this Service to be folllowed would be this:

```
return array(
    'sam_versioning' => array(
        'versionify' => array(
            'MyNS\Services\SomeService' => 'save-entity.post'
        )
    )
);

```

Todo
====

[](#todo)

- Learn how to Unit Test
- Implement Unit Tests
- Provide ViewHelpers to gain easy access to earlier versions
- Provide a RollBack-Feature for earlier versions
- Provide the same features for Zend\\Db, too
- Let me know about your Ideas!

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ed31be404d98dfdab5b15351d3615e2bc4bceda9735fb398435d70e80f3d3b3?d=identicon)[manuakasam](/maintainers/manuakasam)

---

Top Contributors

[![manuakasam](https://avatars.githubusercontent.com/u/1087280?v=4)](https://github.com/manuakasam "manuakasam (32 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (2 commits)")

### Embed Badge

![Health badge](/badges/manuakasam-sam-versioning/health.svg)

```
[![Health](https://phpackages.com/badges/manuakasam-sam-versioning/health.svg)](https://phpackages.com/packages/manuakasam-sam-versioning)
```

###  Alternatives

[bizley/cookiemonster

Yii extension to manage cookie warning.

2020.1k1](/packages/bizley-cookiemonster)[myth/collection

Javascript inspired, supercharged array object for PHP.

165.3k2](/packages/myth-collection)

PHPackages © 2026

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