Simple Data Mapper library aiming reach any source

0.2.1 2015-07-03 18:20 UTC


Drakojn is a library suite thought to be simple and effective for web development. This suite has small libraries to be connected on your current or future project easily.


Io is a small tool aimed to abstract persistency simple way. The idea is keep your model/data classes as is, and provide a simple way to connect them either a relational (or not) database, text files, web protocols and services and so on


Imagine you have the following class:

namespace Dummy\Data;

class User
    protected $id;
    protected $alias;
    protected $name;
    protected $email;

    /* all setters and getters here */

And you have a table like this on your rdbms:

Table user
|id_user (PK)|login        |name         |email       |password   |
|1           |duodraco     |Anderson...  |o@duodr...  |*****      |
|2           |alganet      |Alexandre..  |alexandre...|*****      |
|3           |hagiro       |Augusto...   |augusto.h...|*****      |

You just have to setup a Drakojn\Io\Mapper\Map object this way:

$map = new Drakojn\Io\Mapper\Map(
    'Dummy\\Data\\User', //local class
    'user', // remote entity, the table
    'id', //local attribute used to identify this object through remote part
        'id' => 'id_user',
        'alias' => 'login',
        'name' => 'name',
        'email' => 'email'
    ] //map between local class and remote presistency part

Set up the communication driver:

$driver = new Drakojn\Io\Driver\Pdo(
  new \PDO('mysql:host=localhost;dbname=dummy','your-user','your-password')

Create the mapper:

$userMapper = new Drakojn\Io\Mapper($driver, $map);

And start to play:

$allUsers = $userMapper->find();// gets all "records"
$myself = $userMapper->findByIdentifier(1);
$gaigalas = $userMapper->find(['login'=>'alganet']);
$someoneIDontLike = $userMapper->find(['name'=>'something bad']);
$klaus = new User;
$klaus->setName('Klaus Silveira');

Now imagine that you cannot use a RDBMS and the only way to persist is the filesystem. No Problem. You can use another Driver:

$fileDriver = new Drakojn\Io\Driver\File('/path/to/store/your/objects/');
$userMapper = new Drakojn\Io\Mapper($fileDriver, $map);

Or if you want a json based file:

$descriptor = new Drakojn\Io\Driver\Descriptor\Json;
$fileDriver = new Drakojn\Io\Driver\File('/path/to/store/your/objects/', $descriptor);
// or even a php serialized file:
$fileDriver->setDescriptor(new Drakojn\Io\Driver\Descriptor\Php);

And develop as you were working with RDBMS. You (or Drakojn Developer) (or YOU as Drakojn Developer) could do an exchange strategy between many sources.


  • IMAP Driver
  • Specialized Pdo Drivers
  • Nosql DB Driver
  • RESTful Driver


  • 0.2.1 - fixes for update and select - breaks when looking for remote keys instead local ones
  • 0.2.0 - Changed family structure for Pdo driver
  • 0.1.0 - Moved File to a Stream family, among new GS driver, added descriptors for stream formatting
  • 0.0.3 - Added build files for Ant and Phing - QA
  • 0.0.2 - Added FileDriver
  • 0.0.1 - First Release with basic mapping through Pdo


This is a early in-development library and it could have a lot of problems. There are some already mapped on github project page issues - if you find something wrong please create an issue there.

Even better: help this project coding or documenting. The developer and opensource community will be really thankful.