2017 © Pedro Peláez
 

library pop-data

Pop Data Component for Pop PHP Framework

image

popphp/pop-data

Pop Data Component for Pop PHP Framework

  • Thursday, March 2, 2017
  • by nicksagona
  • Repository
  • 1 Watchers
  • 4 Stars
  • 640 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

pop-data

END OF LIFE

The pop-data component v2.1.0 is now end-of-life. The CSV sub-component has been forked and pushed into its own repository:, (*1)

  • popphp/pop-csv

Build Status Coverage Status, (*2)

OVERVIEW

pop-data provides a streamlined way to convert common data types. With it, you can easily give it some native PHP data and quickly produce a serialized version of that data in a common data type, such as CSV, JSON, SQL, XML or YAML. Or, conversely, you can give it some serialized data, an it will auto-detect the format and convert it to native PHP data., (*3)

pop-datais a component of the Pop PHP Framework., (*4)

INSTALL

Install pop-data using Composer., (*5)

composer require popphp/pop-data

BASIC USAGE

Serialize Data

$phpData = [
    [
        'first_name' => 'Bob',
        'last_name'  => 'Smith'
    ],
    [
        'first_name' => 'Jane',
        'last_name'  => 'Smith'
    ]
];

$data = new Pop\Data\Data($phpData);

$csvString   = $data->serialize('csv');
$jsonString  = $data->serialize('json');
$sqlString   = $data->serialize('sql');
$xmlString   = $data->serialize('xml');
$yamlString  = $data->serialize('yaml');

The $csvString variable now contains:, (*6)

first_name,last_name
Bob,Smith
Jane,Smith

The $jsonString variable now contains:, (*7)

[
    {
        "first_name": "Bob",
        "last_name": "Smith"
    },
    {
        "first_name": "Jane",
        "last_name": "Smith"
    }
]

The $sqlString variable now contains:, (*8)

INSERT INTO data (first_name, last_name) VALUES
('Bob', 'Smith'),
('Jane', 'Smith');

The $xmlString variable now contains:, (*9)

<?xml version="1.0" encoding="utf-8"?>
<data>
  <row>
    <first_name>Bob</first_name>
    <last_name>Smith</last_name>
  </row>
  <row>
    <first_name>Jane</first_name>
    <last_name>Smith</last_name>
  </row>
</data>

The $yamlString variable now contains:, (*10)

---
- first_name: Bob
  last_name: Smith
- first_name: Jane
  last_name: Smith
...

Unserialize Data

You can either pass the data object a direct string of serialized data or a file containing a string of serialized data. It will detect which one it is and parse it accordingly., (*11)

String
$csv     = new Pop\Data\Data($csvString);
$phpData = $csv->unserialize();
File
$xml     = new Pop\Data\Data('/path/to/file.xml');
$phpData = $xml->unserialize();

Convert Between Data Types

$csv = new Pop\Data\Data($csvString);
$xml = $csv->convert('xml');

Write to File

$phpData = [ ... ];

$data = new Pop\Data\Data($phpData);
$data->serialize('csv');
$data->writeToFile('/path/to/file.csv');

Output to HTTP

$phpData = [ ... ];

$data = new Pop\Data\Data($phpData);
$data->serialize('csv');
$data->outputToHttp();
Force download of file
$phpData = [ ... ];

$data = new Pop\Data\Data($phpData);
$data->serialize('csv');
$data->outputToHttp('my-file.csv', true);

The Versions

02/03 2017

dev-master

9999999-dev http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

02/03 2017

2.1.0p1

2.1.0.0-patch1 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

01/07 2016

2.1.0

2.1.0.0 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

02/06 2016

2.0.0p6

2.0.0.0-patch6 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

24/05 2016

2.0.0p5

2.0.0.0-patch5 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

10/05 2016

2.0.0p4

2.0.0.0-patch4 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

25/04 2016

2.0.0p3

2.0.0.0-patch3 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

19/02 2016

2.0.0p2

2.0.0.0-patch2 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

02/11 2015

2.0.0p1

2.0.0.0-patch1 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert

16/07 2015

2.0.0

2.0.0.0 http://www.popphp.org/

Pop Data Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

  • php >=5.4.0

 

The Development Requires

php pop pop php data conversion data convert