gefar / laravel-formatter by Gefar
forked from DanielFurmanov/laravel-formatter

A formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others.
Package Data
Maintainer Username: Gefar
Maintainer Contact: (Farges Thomas)
Package Create Date: 2017-01-02
Package Last Update: 2019-12-17
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2020-06-29 03:01:46
Package Statistics
Total Downloads: 48
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 1
Total Watchers: 0
Total Forks: 0
Total Open Issues: 0


This fork was made to support encoding and '@attributes' in xml, so that nodes (xml tags) could support attributes. Any credits should go to the original author of this bundle. Use at your own risk!

Formatter Bundle

Build Status

A formatter package that will help you to easily convert between various formats such as XML, JSON, CSV, etc...


The goals of this library are to allow the transfomation of data formats from one type to another. See Parsers and Formats to see supported input / output formats.


Through command line:

composer require daniel-furmanov/laravel-formatter

Through composer.json:

  "require": {
	"daniel-furmanov/laravel-formatter": "dev-master",


All of the following are supported formats that the formatter can read from.

  • Array
  • CSV
  • JSON
  • XML
  • YAML


All of the following are formats that are supported for output.

  • Array
  • CSV
  • JSON
  • XML
  • YAML

General Usage

Including The Formatter

use DanielFurmanov\Formatter\Formatter;

Supported Types

Formatter::JSON; //json
Formatter::CSV;  //csv
Formatter::XML;  //xml
Formatter::ARR;  //array
Formatter::YAML; //yaml

Making Your First Formatter(s)

$formatter = Formatter::make($jsonString, Formatter::JSON);
$formatter = Formatter::make($yamlString, Formatter::YAML);
$formatter = Formatter::make($array, Formatter::ARR);

Outputting From Your Formatter

$csv   = $formatter->toCsv();
$json  = $formatter->toJson();
$xml   = $formatter->toXml();
$array = $formatter->toArray();
$yaml  = $formatter->toYaml();

Deprecated Functionality

The following have been deprecated from the library, however you can easily continue using them in your application

Serialized Array

$serialized = serialize($formatter->toArray());

PHP Export

$export = var_export($formatter->toArray());