Giter Club home page Giter Club logo

php-transformer's Introduction

ATTENTION: This repository is archived and therefore readonly.

PHP Transformer

Build Status GitHub license GitHub issues

This package allows you to transform data from from a api to a format that you need.

Install

$ composer install flaver/php-transformer 

Then add the composer autoload file to your application. And you are good to go

Usage

<?php

include 'vendor/autoload.php';

$data = new MyApiService()->getData();

$transfomer = \PHPTransformer\Factory::create();
$orders = $transfomer->getArrayFromValue($data['orders']);

Mappings

Important When you are transforming to a object your given value is found in the value property of the object. This does not count for array's, there are the keys mapped as property names.

string => int, float, array, boolean, object, date
int => string, float, array, boolean, object
float => string, int, array, boolean, object
array => string, int, float, object
boolean => string, int, float, array, object
json => string, array, object

Function

<?php
$transformer = \PHPTransformer\Factory::create();

// Output: ['Lorem', 'Ipsum']
$transformer->getArrayFromValue("Lorem Ipsum");

// Output: stdClass: { test => "test" }
$transformer->getObjectFromValue('{"test": test}');

// Output: 1.0
$transformer->getFloatFromValue(1);

// Output: 1
$transformer->getIntFromValue("1");

// Output: "1 asd 2"
$transformer->getStringFromValue([1, 'asd', 2]);

// Output: true
$transformer->getBooleanFromValue('true');

// Output: DateTime object
$transformer->getDateTimeFromValue('now');

php-transformer's People

Contributors

flaver12 avatar scuben avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.