Skip to content

Commit 17d99fc

Browse files
committed
IHF: Moved get_dump to Format section.
1 parent 864c9b3 commit 17d99fc

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
lines changed

README.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ Provides Laravel-specific and pure PHP helper functions.
4343
- [db_mysql_now](#db_mysql_now)
4444
- [db_mysql_variable](#db_mysql_variable)
4545
46-
- [Dump](#dump)
47-
- [get_dump](#get_dump)
48-
4946
- [Email](#email)
5047
- [is_email](#is_email)
5148
- [to_rfc2822_email](#to_rfc2822_email)
5249
- [to_swiftmailer_emails](#to_swiftmailer_emails)
5350
5451
- [Format](#format)
52+
- [get_dump](#get_dump)
5553
- [format_bytes](#format_bytes)
5654
5755
- [Json](#json)
@@ -131,31 +129,6 @@ $hostname = db_mysql_variable('hostname');
131129
// localhost
132130
```
133131

134-
## Dump
135-
136-
#### `get_dump()`
137-
138-
Returns nicely formatted string representation of the variable, using [Symfony VarDumper Component](http://symfony.com/doc/current/components/var_dumper/introduction.html) with all of it's benefits:
139-
140-
```php
141-
$array = [
142-
'a simple string' => 'in an array of 5 elements',
143-
'a float' => 1.0,
144-
'an integer' => 1,
145-
'a boolean' => true,
146-
'an empty array' => [],
147-
];
148-
$dump = get_dump($array);
149-
150-
// array:5 [
151-
// "a simple string" => "in an array of 5 elements"
152-
// "a float" => 1.0
153-
// "an integer" => 1
154-
// "a boolean" => true
155-
// "an empty array" => []
156-
// ]
157-
```
158-
159132
## Email
160133

161134
#### `is_email()`
@@ -212,6 +185,29 @@ $address = to_swiftmailer_emails(['address' => 'john.doe@example.com', 'name' =>
212185

213186
## Format
214187

188+
#### `get_dump()`
189+
190+
Returns nicely formatted string representation of the variable, using [Symfony VarDumper Component](http://symfony.com/doc/current/components/var_dumper/introduction.html) with all of it's benefits:
191+
192+
```php
193+
$array = [
194+
'a simple string' => 'in an array of 5 elements',
195+
'a float' => 1.0,
196+
'an integer' => 1,
197+
'a boolean' => true,
198+
'an empty array' => [],
199+
];
200+
$dump = get_dump($array);
201+
202+
// array:5 [
203+
// "a simple string" => "in an array of 5 elements"
204+
// "a float" => 1.0
205+
// "an integer" => 1
206+
// "a boolean" => true
207+
// "an empty array" => []
208+
// ]
209+
```
210+
215211
#### `format_bytes()`
216212
217213
Formats bytes into kilobytes, megabytes, gigabytes or terabytes, with specified precision:

src/dump.php

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

src/format.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
<?php
22

3+
use Symfony\Component\VarDumper\Cloner\VarCloner;
4+
use Symfony\Component\VarDumper\Dumper\CliDumper;
5+
6+
if (!function_exists('get_dump')) {
7+
function get_dump($var)
8+
{
9+
$cloner = new VarCloner();
10+
$cloner->setMaxItems(-1);
11+
$cloner->setMaxString(-1);
12+
13+
$cloned = $cloner->cloneVar($var);
14+
$cloned = $cloned->withMaxDepth(50);
15+
$cloned = $cloned->withMaxItemsPerDepth(-1);
16+
$cloned = $cloned->withRefHandles(true);
17+
18+
$dumper = new CliDumper();
19+
$dumper->setIndentPad(' ');
20+
$output = fopen('php://memory', 'r+b');
21+
$dumper->dump($cloned, $output);
22+
23+
return stream_get_contents($output, -1, 0);
24+
}
25+
}
26+
327
if (!function_exists('format_bytes')) {
428
function format_bytes($bytes, $precision = 2)
529
{

0 commit comments

Comments
 (0)