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