Giter Site home page Giter Site logo

laravel-formatter's Introduction

Formatter Bundle

Laravel Bundle ported from the FuelPHP Format class, that helps you easily convert between various formats such as XML, JSON, CSV, etc...

Installation

Using artisan to install the bundle

php artisan bundle:install formatter

Or you can clone the bundle straight from github. Run the following command inside your bundles folder:

git clone [email protected]:rodrigore/laravel-formatter.git formatter

Add the Following to your application/bundles.php file:

'formatter' => array('auto' => true) // you can leave out the auto => true

That's it, Formatter should now be installed and ready to go!

Usage

The best way to learn how to use Formatter is to look through the code, where you can familiarize yourself with all of the available methods.

###Calling Formatter

Formatter::make($data_to_convert, 'type of data')->to_the_format_you_want();

Available Formats to Convert From

  • Json
  • Serialized Array
  • XML
  • CSV

Available Formates to Convert To

  • Json
  • Serializaed Array
  • XML
  • CSV
  • PHP Array
  • PHP Export
  • YAML
$json_string = '{"foo":"bar","baz":"qux"}';
print_r(Formatter::make($json_string, 'json')->to_array());

// Returns
Array
(
    [foo] => bar
    [baz] => qux
)

Handling errors from csv

To check if an error was ocurred when you use the method from_csv, you can use the array call errors.

// Post use of Formatter::make($file, 'csv')
if ( ! empty(Formatter::$errors) ) {
    // Show the errors
    print_r(Formatter::$errors);
}

The exception were replaced and added to the array of errors. Also, if the CSV file contains a row with more o less data than the headings this errors are store in this array.

Spanish Folder

The es Folder was added, with the two messages from the exception and the news errors.

ToDo

  • Check if the replaced of Exception to messages are ok.
  • Add more validation to the csv file.
  • Add more error messages to the other methods.

laravel-formatter's People

Contributors

dberry37388 avatar austinw avatar rodrigore avatar

Stargazers

Juan Pablo avatar

Watchers

James Cloos avatar  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.