1Exporter
2========
3
4[![Build Status](https://secure.travis-ci.org/sebastianbergmann/exporter.png?branch=master)](https://travis-ci.org/sebastianbergmann/exporter)
5
6This component provides the functionality to export PHP variables for visualization.
7
8## Usage
9
10Exporting:
11
12```php
13<?php
14use SebastianBergmann\Exporter\Exporter;
15
16$exporter = new Exporter;
17
18/*
19Exception Object &0000000078de0f0d000000002003a261 (
20    'message' => ''
21    'string' => ''
22    'code' => 0
23    'file' => '/home/sebastianbergmann/test.php'
24    'line' => 34
25    'trace' => Array &0 ()
26    'previous' => null
27)
28*/
29
30print $exporter->export(new Exception);
31```
32
33## Data Types
34
35Exporting simple types:
36
37```php
38<?php
39use SebastianBergmann\Exporter\Exporter;
40
41$exporter = new Exporter;
42
43// 46
44print $exporter->export(46);
45
46// 4.0
47print $exporter->export(4.0);
48
49// 'hello, world!'
50print $exporter->export('hello, world!');
51
52// false
53print $exporter->export(false);
54
55// NAN
56print $exporter->export(acos(8));
57
58// -INF
59print $exporter->export(log(0));
60
61// null
62print $exporter->export(null);
63
64// resource(13) of type (stream)
65print $exporter->export(fopen('php://stderr', 'w'));
66
67// Binary String: 0x000102030405
68print $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
69```
70
71Exporting complex types:
72
73```php
74<?php
75use SebastianBergmann\Exporter\Exporter;
76
77$exporter = new Exporter;
78
79/*
80Array &0 (
81    0 => Array &1 (
82        0 => 1
83        1 => 2
84        2 => 3
85    )
86    1 => Array &2 (
87        0 => ''
88        1 => 0
89        2 => false
90    )
91)
92*/
93
94print $exporter->export(array(array(1,2,3), array("",0,FALSE)));
95
96/*
97Array &0 (
98    'self' => Array &1 (
99        'self' => Array &1
100    )
101)
102*/
103
104$array = array();
105$array['self'] = &$array;
106print $exporter->export($array);
107
108/*
109stdClass Object &0000000003a66dcc0000000025e723e2 (
110    'self' => stdClass Object &0000000003a66dcc0000000025e723e2
111)
112*/
113
114$obj = new stdClass();
115$obj->self = $obj;
116print $exporter->export($obj);
117```
118
119Compact exports:
120
121```php
122<?php
123use SebastianBergmann\Exporter\Exporter;
124
125$exporter = new Exporter;
126
127// Array ()
128print $exporter->shortenedExport(array());
129
130// Array (...)
131print $exporter->shortenedExport(array(1,2,3,4,5));
132
133// stdClass Object ()
134print $exporter->shortenedExport(new stdClass);
135
136// Exception Object (...)
137print $exporter->shortenedExport(new Exception);
138
139// this\nis\na\nsuper\nlong\nstring\nt...\nspace
140print $exporter->shortenedExport(
141<<<LONG_STRING
142this
143is
144a
145super
146long
147string
148that
149wraps
150a
151lot
152and
153eats
154up
155a
156lot
157of
158space
159LONG_STRING
160);
161```
162
163## Installation
164
165You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
166
167    composer require sebastian/exporter
168
169If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
170
171    composer require --dev sebastian/exporter
172
173