core/data-transformer

There is no license information available for the latest version (dev-master) of this package.

Transform Data to Db from DB

dev-master 2014-05-23 06:43 UTC

This package is auto-updated.

Last update: 2024-11-27 03:17:53 UTC


README

Usage

<?php

require_once __DIR__ ."/vendor/autoload.php";

$transformer = new \CNM\Transformer\Transformer();

$metadata = array(
    'table' => 'tests',
    'fields' => array(
        'id' => array(
            'type' => 'integer',
            'default' => 0
        ),
        'name' => array(
            'type' => 'string',
            'default' => ''
        ),
        'options' => array(
            'type' => 'json',
            'default' => array()
        )
    )
);


$adapter =  new \CNM\Metadata\Adapter\ArrayAdapter($metadata);

$data = array(
    'name' => 'Test Data Transformer',
    'options' => array(
        'opt1' => true,
        'opt2' => false
    )
);

$encodedData = $transformer->encode($data, $adapter);

logic for inserting data to db

Get data from database

$decodeData = $transformer->decode($data, $adapter);

and usage data