Skip to content

happyclicker/laravel-formatter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Formatter Bundle

This is a fork from https://github.com/nmfmcosta/laravel-formatter which is a fork from https://github.com/soapbox/laravel-formatter updated to work on Laravel 10.

All credit goes to the original authors.

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

Goals

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.

Installation

Through command line:

composer require happyclicker/laravel-formatter

Through composer.json:

{
  "require": {
    "happyclicker/laravel-formatter": "1.x"
  }
}

Parsers

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

  • Array
  • CSV
  • JSON
  • XML
  • YAML

Formats

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

  • Array
  • CSV
  • JSON
  • XML
  • YAML

General Usage

Including The Formatter

use LB\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());

About

A Formatter Class for Laravel 8, 9 and 10 based on SoapBox/laravel-formatter

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%