Simple PHP PDO data mapper
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Mikron.php
MikronTest.php
README.md
composer.json
composer.lock
phpunit.xml.dist

README.md

Mikron

Build Status

Simple PHP PDO data mapper

Maps database rows to simple PHP object and nothing more.

Usage

Load database values to Order object. All public members of the class must be the same as field names in database. Entity is identified by field "id"

Simple model class:

    class Entity
    {
        /** @field */
        public $id;

        /** @field */
        public $name;

        /** Not a field */
        public $anything;
    }

Maps database values to Entity class

    $mikron = new Mikron(new Pdo(...));
    $entity = $mikron->load('entity', 1);
    print $entity->id;
    print $entity->name;

    $entity->name = 'New Name';
    $mikron->store($entity); //updates entity name in DB

Custom entity names and table names

Define custom function to map entities to table names and vice versa. By default entity name is same as table name.

    $this->mikron->setNameResolver(function($type, $name) { return ucfirst($name); });