dev-master
9999999-devMigrations between object versions, configurable via annotations.
MIT
The Requires
- php >=5.3.2
- clue/graph dev-master
- doctrine/annotations *
by Nerijus Arlauskas
by Darius KriÅ”tapaviÄius
Wallogit.com
2017 © Pedro PelĆ”ez
Migrations between object versions, configurable via annotations.
Build Status: , (*1)
Migrate objects to different versions based on version annotations., (*2)
For example, let's say we have two class versions, the second one modifies public field name from "slug" to "id":, (*3)
class V1
{
public $slug;
}
class V2
{
public $id;
}
We can then decorate these classes with version annotations, and create migration method to the new version:, (*4)
use Evispa\ObjectMigration\Annotations as Api;
/**
* @Api\Version("object.v1")
*/
class V1
{
public $slug;
}
/**
* @Api\Version("object.v2")
*/
class V2
{
public $id;
/**
* @Api\Migration(from="V1")
*/
public static function fromV1(V1 $other, $options) {
$obj = new self();
$obj->id = $other->slug;
return $obj;
}
}
Use VersionConverter tool to check object version or migrate object to another available version:, (*5)
use Doctrine\Common\Annotations\AnnotationReader; use Evispa\ObjectMigration\VersionReader; use Evispa\ObjectMigration\VersionConverter; $converter = new VersionConverter(new VersionReader(new AnnotationReader()), 'V2'); // create v1 object $v1 = new V1(); $v1->slug = "TEST"; // migrate to another version $v2 = $converter->migrateFrom($v1); $this->assertTrue($v2 instanceof V2); // true $this->assertEquals("TEST", $v2->id); // true
This library will use: * doctrine/annotations for annotation parsing * clue/graph for version migrations search, (*6)
This library can be easily installed via composer, (*7)
composer require evispa/object-migration
or just add it to your composer.json file directly., (*8)
Migrations between object versions, configurable via annotations.
MIT