Skip to content

Commit 9149adc

Browse files
committed
Merge pull request #13 from SoapBox/2.0
Laravel Formatter 2.0
2 parents 035ebef + cc31318 commit 9149adc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+853
-3996
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
composer.phar
33
composer.lock
44
.DS_Store
5+
notes

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
5+
- 5.5
6+
- 5.6
67

78
before_script:
89
- curl -s http://getcomposer.org/installer | php

composer.json

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
{
22
"name": "soapbox/laravel-formatter",
33
"type": "library",
4-
"description": "A Laravel 4 formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others. ",
5-
"keywords": ["laravel", "formatter", "data","convert","csv", "xml", "yaml"],
4+
"description": "A formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others.",
5+
"keywords": ["laravel", "formatter", "data", "convert", "csv", "xml", "yaml"],
66
"homepage": "http://github.com/SoapBox/laravel-formatter",
77
"license": "MIT",
8-
"version": "1.4",
8+
"version": "2.0",
99
"authors": [
1010
{
1111
"name": "Graham McCarthy",
1212
"email": "graham@soapboxhq.com",
1313
"homepage": "http://grahammccarthy.com"
14+
},
15+
{
16+
"name": "Jaspaul Bola",
17+
"email": "jaspaul.b@gamil.com",
18+
"homepage": "http://jaspaulbola.com"
1419
}
1520
],
1621
"require": {
17-
"php": ">=5.3.0",
18-
"illuminate/support": ">=4.0",
19-
"illuminate/foundation": ">=4.0",
20-
"illuminate/config": ">=4.0",
21-
"illuminate/session": ">=4.0",
22-
"illuminate/filesystem": ">=4.0",
23-
"illuminate/view": ">=4.0"
24-
},
25-
"require-dev": {
26-
"orchestra/testbench": "2.1.*",
27-
"mockery/mockery": "dev-master"
22+
"php": ">=5.4.0",
23+
"league/csv": "~6.0",
24+
"mustangostang/spyc": "0.5.*@dev",
25+
"illuminate/support": ">=4.0"
2826
},
2927
"autoload": {
3028
"psr-0": {
31-
"Spyc": "src/spyc/",
3229
"SoapBox\\Formatter": "src/"
3330
}
3431
},

readme.md

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,96 @@ Formatter Bundle
33

44
[![Build Status](https://travis-ci.org/SoapBox/laravel-formatter.svg?branch=master)](https://travis-ci.org/SoapBox/laravel-formatter)
55

6-
A Laravel 4 Formatter Package based on the work done by @dberry37388 with FuelPHP's Formatter class.
6+
A formatter package that will help you to easily convert between various formats such as XML, JSON, CSV, etc...
77

8-
This package will help you to easily convert between various formats such as XML, JSON, CSV, etc...
8+
# Goals
9+
The goals of this library are to allow the transfomation of data formats from one type to another.
10+
See Parsers and Formats to see supported input / output formats.
911

12+
# Installation
1013

11-
Installation
12-
------------
14+
Through command line:
1315

14-
Begin by installing this package through Composer. Edit your project's `composer.json` file to require `SoapBox/laravel-formatter`.
16+
```bash
17+
composer require soapbox/laravel-formatter
18+
```
19+
20+
Through composer.json:
1521

16-
"require": {
17-
"soapbox/laravel-formatter": "dev-master"
18-
}
22+
```json
23+
{
24+
"require": {
25+
"soapbox/laravel-formatter": "2.x"
26+
}
27+
}
1928

20-
Next, update Composer from the Terminal:
29+
```
2130

22-
composer update
31+
## Parsers
32+
All of the following are supported formats that the formatter can read from.
33+
* Array
34+
* CSV
35+
* JSON
36+
* XML
37+
* YAML
2338

24-
Once this operation completes, the final step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.
39+
## Formats
40+
All of the following are formats that are supported for output.
41+
* Array
42+
* CSV
43+
* JSON
44+
* XML
45+
* YAML
2546

26-
'SoapBox\Formatter\FormatterServiceProvider'
47+
## General Usage
2748

49+
__Including The Formatter__
2850

29-
Usage
30-
-----
31-
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.
51+
```php
52+
use SoapBox\Formatter\Formatter;
53+
```
3254

33-
###Calling Formatter
34-
Formatter::make($data_to_convert, 'type of data')->to_the_format_you_want();
55+
__Supported Types__
3556

36-
### Available Formats to Convert From
37-
- Json
38-
- Serialized Array
39-
- XML
40-
- CSV
57+
```php
58+
Formatter::JSON; //json
59+
Formatter::CSV; //csv
60+
Formatter::XML; //xml
61+
Formatter::ARR; //array
62+
Formatter::YAML; //yaml
63+
```
4164

42-
### Available Formats to Convert To
43-
- Json
44-
- Serializaed Array
45-
- XML
46-
- CSV
47-
- PHP Array
48-
- PHP Export
49-
- YAML
65+
__Making Your First Formatter(s)__
5066

67+
```php
68+
$formatter = Formatter::make($jsonString, Formatter::JSON);
69+
$formatter = Formatter::make($yamlString, Formatter::YAML);
70+
$formatter = Formatter::make($array, Formatter::ARR);
71+
...
5172
```
52-
$json_string = '{"foo":"bar","baz":"qux"}';
53-
$result = Formatter::make($json_string, 'json')->to_array();
54-
55-
if ( empty(Formatter::$errors) ) {
56-
//show the results
57-
print_r($result);
58-
} else {
59-
// Show the errors
60-
print_r(Formatter::$errors);
61-
return;
62-
}
6373

64-
// Returns
65-
Array
66-
(
67-
[foo] => bar
68-
[baz] => qux
69-
)
74+
__Outputting From Your Formatter__
75+
76+
```php
77+
$csv = $formatter->toCsv();
78+
$json = $formatter->toJson();
79+
$xml = $formatter->toXml();
80+
$array = $formatter->toArray();
81+
$yaml = $formatter->toYaml();
82+
```
83+
84+
## Deprecated Functionality
85+
The following have been deprecated from the library, however you can easily continue using them in your application
86+
87+
__Serialized Array__
88+
89+
```php
90+
$serialized = serialize($formatter->toArray());
91+
```
92+
93+
__PHP Export__
94+
95+
```php
96+
$export = var_export($formatter->toArray());
7097
```
7198

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php namespace SoapBox\Formatter;
2+
3+
use Illuminate\Support\Arr;
4+
5+
class ArrayHelpers {
6+
7+
public static function isAssociative($array) {
8+
return array_keys($array) !== range(0, count($array) - 1);
9+
}
10+
11+
public static function dotKeys(array $data) {
12+
return array_keys(Arr::dot($data));
13+
}
14+
15+
public static function dot(array $data) {
16+
return Arr::dot($data);
17+
}
18+
19+
public static function set(array &$data, $key, $value) {
20+
Arr::set($data, $key, $value);
21+
}
22+
23+
}

src/SoapBox/Formatter/Facades/Formatter.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)