A Formatter Class for Laravel 4 based on FuelPHP's Formatter Class

Overview

Changelog

  • Update support for Laravel 6 & phpunit 8
  • Update composer.json
  • Upgrade to PSR-4
  • add parameter newline, delimiter, enclosure, and escape to export csv
  • When converting a XML to an array, convert @attributes to attribute
  • add parameter encoding and formated to export xml
  • JSON parse fix (Instead of only converting the first level to array, use the associative array parameter with true, so all levels will be decoded to array structure)
  • Add support for laravel 5
  • add package discovery for laravel 5
  • add support delimiter to a csv

Formatter Bundle

Build Status

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 soapbox/laravel-formatter

Through composer.json:

{
  "require": {
    "soapbox/laravel-formatter": "2.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 SoapBox\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());
Comments
  • Error while converting to CSV from JSON

    Error while converting to CSV from JSON

    Invalid argument supplied for foreach()

    1. ErrorException …\vendor\soapbox\laravel-formatter\src\SoapBox\Formatter\Formatter.php415
    2. Illuminate\Exception\Handler handleError …\vendor\soapbox\laravel-formatter\src\SoapBox\Formatter\Formatter.php415
    3. SoapBox\Formatter\Formatter is_assoc …\vendor\soapbox\laravel-formatter\src\SoapBox\Formatter\Formatter.php162

    The JSON seems fine. Could the problem be in that there is an key which value is an object of objects? It works otherwise if I leave that key out.

    UPDATE: The same JSON outputs as XML without errors!

    opened by ux-engineer 8
  • Laravel 5.6 support

    Laravel 5.6 support

    Refuses to install on Laravel 5.6

    Using version ^3.0 for soapbox/laravel-formatter
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for soapbox/laravel-formatter ^3.0 -> satisfiable by soapbox/laravel-formatter[3.0].
        - Conclusion: remove laravel/framework v5.6.16
        - Conclusion: don't install laravel/framework v5.6.16
        - soapbox/laravel-formatter 3.0 requires illuminate/support 5.5.x -> satisfiable by illuminate/support[5.5.x-dev, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40].
        - illuminate/support 5.5.x-dev conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.0 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.16 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.17 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.2 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.28 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.35 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.36 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.37 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.39 conflicts with laravel/framework[v5.6.16].
        - illuminate/support v5.5.40 conflicts with laravel/framework[v5.6.16].
        - don't install illuminate/support v5.5.33|don't install laravel/framework v5.6.16
        - don't install illuminate/support v5.5.34|don't install laravel/framework v5.6.16
        - Installation request for laravel/framework (locked at v5.6.16, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.16].
    
    opened by Ancyker 4
  • XML With Attributes

    XML With Attributes

    Can Output this kind of XML

    <markers> <marker name="Pan Africa Market" address="1521 1st Ave, Seattle, WA" lat="47.608940" lng="-122.340141" type="restaurant" /> <marker name="Buddha Thai &amp; Bar" address="2222 2nd Ave, Seattle, WA" lat="47.613590" lng="-122.344391" type="bar" /> </markers> Source is (Array or Laravel Query).

    opened by megadola 4
  • Update package to support Laravel 6, phpunit 8 and PHP 7.2

    Update package to support Laravel 6, phpunit 8 and PHP 7.2

    If this pull request gets merged it applies the following changes:

    • bumps the illuminate/support package to 6.0
    • bumps the phpunit/phpunit to version ~8.0
    • Laravel 6 requires php to be in version 7.2, so that change also applies
    • Fixes tests to stop using the @expectedException notation as it will be deprecated in Phpunit 9 and refactors to use the $this->expectException(\InvalidArgumentException::class); instead
    • updates the testcase to now include the void return type required by phpunit 8
    opened by vicgonvt 3
  • [Laravel 5.6] Add support for laravel 5.6

    [Laravel 5.6] Add support for laravel 5.6

    Using version ^3.0 for soapbox/laravel-formatter
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for soapbox/laravel-formatter ^3.0 -> satisfiable by soapbox/laravel-formatter[3.0].
        - Conclusion: remove laravel/framework v5.6.3
        - Conclusion: don't install laravel/framework v5.6.3
        - soapbox/laravel-formatter 3.0 requires illuminate/support 5.5.x -> satisfiable by illuminate/support[v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34].
        - don't install illuminate/support v5.5.0|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.16|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.17|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.2|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.28|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.33|don't install laravel/framework v5.6.3
        - don't install illuminate/support v5.5.34|don't install laravel/framework v5.6.3
        - Installation request for laravel/framework (locked at v5.6.3, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.3].
    
    
    opened by SlyDave 3
  • No releases available

    No releases available

    Hello,

    Would you please create a release for your formatter? We have had trouble in the past with using dev-master in our composer file, so it would be great if you could create a release. That way we know we are always including a verison that will work for us.

    opened by maarten00 3
  • xml to array  error

    xml to array error

    use SoapBox\Formatter\Formatter; use SoapBox\Formatter\Parsers\ArrayParser;

    $xml = '<request_id>1234444</request_id><error_no>H000011-0003</error_no><error_type>2</error_type><error_no/><error_msg/><error_msg>auth error!</error_msg>'; $formatter = Formatter::make($xml, Formatter::ARR); $array = $formatter->toArray(); print_r($array); /////////////////////// output: unserialize(): Error at offset 0 of 199 bytes

    opened by W2YN 2
  • How to set CSV title row?

    How to set CSV title row?

    Hi,

    I have timeseries data like:

    [ [ 1417646511,4 ], [ 1417648041,3 ], [ 1417649181,1 ], ...
    

    This exports as CSV without title row – how to add the title row?

    0,1
    1417646511,4
    1417648041,3
    1417649181,1
    
    opened by ux-engineer 2
  • Laravel Formatter 2.0

    Laravel Formatter 2.0

    Updating the formatter library to change the code structure to be more extensible than the previous version. The new version also fixes problems with "formatting" multi-dimensional arrays / nested-objects.

    opened by Jaspaul 1
  • json_encode issue with PHP 5.3

    json_encode issue with PHP 5.3

    When you have a string value such as "12E389532" (a serial number in my case), json_encode tries to encode it as a number (because it sees the "E" in it and thinks it is in scientific notation). Because of the JSON_NUMERIC_CHECK flag that is set in Formatter, it chokes.

    Would recommend removing it for PHP 5.3 or lower, and for PHP 5.4 or higher, perhaps this would be better:

    return $pretty ? static::pretty_json($data) : json_encode($data, JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING);
    
    opened by sburkett 1
  • Fixed line_number variable, Errors method

    Fixed line_number variable, Errors method

    Variable line_number declaration was missing in method _from_csv. Now it gets the key number of $row and add 1 to equal the correct line number. I also created a separate errors() method to get errors from the object, because getting the static variable couldn’t work for me.

    opened by terdelyi 1
  • Fix Laravel version requirements

    Fix Laravel version requirements

    Since Laravel 6 comes with semver, updates shouldn't contain breaking changes for the whole 6.x branch. Requiring illuminate/support ^6.0 should become ^6

    opened by matteoformenti 0
  • Yet, Laravel6.0 not support

    Yet, Laravel6.0 not support

    Laravel6.0 not support

    • soapbox/laravel-formatter 3.1.1 requires illuminate/support ~5.5

    https://packagist.org/packages/soapbox/laravel-formatter

    requires illuminate/support: ~5.5

    opened by daijongkim 1
  • CSV Parser enclosure should be user definable

    CSV Parser enclosure should be user definable

    I am running into an issue where there is a comma within a cell but it is properly enclosed in a quotation marks.

    https://github.com/SoapBox/laravel-formatter/blob/master/src/Parsers/CsvParser.php#L18

    However, due to the setEnclosure being hardcoded to a pipe character, the parsing is breaking and ignoring the enclosure.

    I propose allowing users of this package to simply define the enclosure to be whatever they need.

    opened by AaronHolbrook 0
  • RSS

    RSS

    XML rss feed requires rss tag https://support.google.com/merchants/answer/160589?hl=en

    Is there a way to add it without manipulating the XML post creation?

    opened by verlekar-viraj 0
Releases(3.1.1)
Owner
Soapbox Innovations Inc.
Helping managers and employees have better meetings, one byte at a time.
Soapbox Innovations Inc.
An opinionated blade template formatter for Laravel that respects readability

blade-formatter An opinionated blade template formatter for Laravel that respects readability Online Demo Features Automatically Indents markup inside

Shuhei Hayashibara 277 Dec 26, 2022
Laravel Response Formatter

I created this package to make it easier to format the response from a controller. I have used this package in my projects and I hope you enjoy it!

aris wahyudiyanto 12 Dec 5, 2022
A laravel package to generate class files from stub files.

Laravel Stub Generator A php laravel package to generate useable php files from given stub files . Installation Require the package using composer: co

Touhidur Rahman 31 Dec 29, 2022
Make any class queue aware in a Laravel app

Make any class queue aware This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support us We in

Spatie 8 Jun 17, 2022
27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

zjango 8 Sep 9, 2018
Is an Extension of Laravel View Class which compiles String Template on the fly. It automatically detects changes on your string template and recompiles it if needed.

Laravel-fly-view Is an Extension of Laravel View Class which compiles String Template on the fly. It automatically detects changes on your string temp

John Turingan 16 Jul 17, 2022
Helper class for working with Laravel Mix in WordPress themes and plugins.

Hybrid\Mix Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json

Theme Hybrid 9 Jun 2, 2022
Laravel-model-mapper - Map your model attributes to class properties with ease.

Laravel Model-Property Mapper This package provides functionality to map your model attributes to local class properties with the same names. The pack

Michael Rubel 15 Oct 29, 2022
A simple php class creator for laravel.

Laravel Make Class Features Create a php class from the command for any directory in the root name-space; Store a custom path as an alias and use alia

orpheusohms 6 Nov 10, 2022
Provide all attributes (including irregular patterns) to Laravel Blade class components.

blade-wants-attributes blade-wants-attributes offers you the ability to use Blade/HTML-defined attributes within the constructors of Laravel Blade cla

Stephan Casas 4 Sep 15, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
A quick and incomplete example of how to validate a form using a FormValidator class on the simple-mvc

Simple MVC Description This repository is a simple PHP MVC structure from scratch. It uses some cool vendors/libraries such as Twig and Grumphp. For t

Romain Clair 1 Nov 24, 2021
laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.

laravel-potion Potion is a pure PHP asset manager for Laravel based off of Assetic. Description Laravel 5 comes with a great asset manager called Elix

Matthew R. Miller 61 Mar 1, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
Awes.io // boilerplate based on Vue, Nuxt, TailwindCSS plus Laravel as a backend. 🤟

Platform for Interactive Business Applications 10x faster to create than the traditional way • 3x increase application experiences • 60% decrease in d

Awes.io 753 Dec 30, 2022
PHP package to help the development of Laravel-based Telegram bots

Laravel-telegram-bot Project description goes here. This description is usually two to three lines long. It should give an overview of what the projec

CC - UFFS 6 May 10, 2021
Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

Tina Hammar 7 Nov 23, 2022
MediaDB is a web-based media streaming service written in Laravel and Vue.

MediaDB (API) MediaDB is a web-based media streaming service written in Laravel and Vue. The nginx-vod-module is used for on-the-fly repackaging of MP

François M. 53 Sep 3, 2022
A simple laravel package to handle multiple key based model route binding

Laravel Model UUID A simple package to handle the multiple key/column based route model binding for laravel package Installation Require the package u

null 13 Mar 2, 2022