You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-28Lines changed: 51 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,20 +17,6 @@ Simple conversion of an array to a pretty view.
17
17
</p>
18
18
19
19
20
-
## Content
21
-
22
-
*[Installation](#installation)
23
-
*[Introduction](#introduction)
24
-
*[Using](#using)
25
-
*[Saving numeric keys without alignment](#saving-numeric-keys-without-alignment)
26
-
*[Saving string keys without alignment](#saving-string-keys-without-alignment)
27
-
*[Saving numeric keys with alignment](#saving-numeric-keys-with-alignment)
28
-
*[Saving string keys with alignment](#saving-string-keys-with-alignment)
29
-
*[Change key case](#change-key-case)
30
-
*[Storing file](#storing-file)
31
-
*[Copyright and License](#copyright-and-license)
32
-
33
-
34
20
## Installation
35
21
36
22
To get the latest version of `Pretty Array` package, simply require the project using [Composer](https://getcomposer.org):
@@ -44,19 +30,19 @@ Instead, you may of course manually update your `require-dev` block and run `com
44
30
```json
45
31
{
46
32
"require-dev": {
47
-
"andrey-helldar/pretty-array": "^2.0"
33
+
"andrey-helldar/pretty-array": "^2.2"
48
34
}
49
35
}
50
36
```
51
37
52
-
53
38
## Introduction
54
39
55
40
> Q: Why did you create this package when there is a cooler [symfony/var-exporter](https://github.com/symfony/var-exporter)?
56
41
57
42
The big minus of package [symfony/var-exporter](https://github.com/symfony/var-exporter) is that it works differently with numeric keys.
58
43
59
44
For example, we have an array:
45
+
60
46
```php
61
47
$array = [
62
48
100 => 'foo',
@@ -69,6 +55,7 @@ $array = [
69
55
```
70
56
71
57
When exporting through it, the file will contain the following content:
58
+
72
59
```php
73
60
$array = [
74
61
100 => 'foo',
@@ -82,13 +69,16 @@ $array = [
82
69
83
70
> Q: Why do you think this is bad?
84
71
85
-
This package has a framework-independent base. However, it was originally developed as an assistant for package [lang-translations](https://github.com/andrey-helldar/lang-translations).
72
+
This package has a framework-independent base. However, it was originally developed as an assistant for
This package allows you to publish language translations for the Laravel framework.
88
76
89
-
A feature of the framework is that IDEs that help with development do not know how to read the numeric keys of arrays of translation files, so it was necessary to translate them into a text equivalent.
77
+
A feature of the framework is that IDEs that help with development do not know how to read the numeric keys of arrays of translation files, so it was necessary to translate them
78
+
into a text equivalent.
90
79
91
80
This behavior includes [errors.php](https://github.com/andrey-helldar/lang-translations/blob/master/src/lang/en/errors.php) file:
81
+
92
82
```php
93
83
<?php
94
84
@@ -114,7 +104,9 @@ return [
114
104
// ...
115
105
```
116
106
117
-
The peculiarity of the package is that it takes the values of the source file and combines it with what is already in the application. Thus, the output is a file with numeric keys that IDE helpers cannot read:
107
+
The peculiarity of the package is that it takes the values of the source file and combines it with what is already in the application. Thus, the output is a file with numeric keys
108
+
that IDE helpers cannot read:
109
+
118
110
```php
119
111
<?php
120
112
@@ -140,10 +132,10 @@ return [
140
132
// ...
141
133
```
142
134
143
-
144
135
## Using
145
136
146
137
Source array for all examples:
138
+
147
139
```php
148
140
$array = array (
149
141
'foo' => 1,
@@ -175,6 +167,7 @@ return $service->raw($array);
175
167
```
176
168
177
169
Result:
170
+
178
171
```text
179
172
[
180
173
'foo' => 1,
@@ -195,7 +188,6 @@ Result:
195
188
]
196
189
```
197
190
198
-
199
191
### Saving string keys without alignment
200
192
201
193
```php
@@ -208,6 +200,7 @@ return $service->raw($array);
208
200
```
209
201
210
202
Result:
203
+
211
204
```text
212
205
[
213
206
'foo' => 1,
@@ -228,7 +221,6 @@ Result:
228
221
]
229
222
```
230
223
231
-
232
224
### Saving numeric keys with alignment
233
225
234
226
```php
@@ -241,6 +233,7 @@ return $service->raw($array);
241
233
```
242
234
243
235
Result:
236
+
244
237
```text
245
238
[
246
239
'foo' => 1,
@@ -261,7 +254,6 @@ Result:
261
254
]
262
255
```
263
256
264
-
265
257
### Saving string keys with alignment
266
258
267
259
```php
@@ -275,6 +267,7 @@ return $service->raw($array);
275
267
```
276
268
277
269
Result:
270
+
278
271
```text
279
272
[
280
273
'foo' => 1,
@@ -295,6 +288,38 @@ Result:
295
288
]
296
289
```
297
290
291
+
### Saving simple array
292
+
293
+
```php
294
+
use Helldar\PrettyArray\Services\Formatter;
295
+
296
+
$service = Formatter::make();
297
+
$service->setSimple();
298
+
299
+
return $service->raw($array);
300
+
```
301
+
302
+
Result:
303
+
304
+
```text
305
+
[
306
+
1,
307
+
2,
308
+
3,
309
+
'qaz',
310
+
[
311
+
'qwe',
312
+
'rty',
313
+
'zxc',
314
+
],
315
+
[
316
+
'qwe',
317
+
'rty',
318
+
'zxc',
319
+
],
320
+
'iop',
321
+
]
322
+
```
298
323
299
324
### Change key case
300
325
@@ -309,6 +334,7 @@ return $service->raw($array);
309
334
```
310
335
311
336
Result:
337
+
312
338
```text
313
339
[
314
340
'Foo' => 1,
@@ -341,6 +367,7 @@ The following options are available:
341
367
342
368
343
369
### Storing file
370
+
344
371
```php
345
372
use Helldar\PrettyArray\Services\File;
346
373
use Helldar\PrettyArray\Services\Formatter;
@@ -354,6 +381,7 @@ File::make($formatted)
354
381
```
355
382
356
383
Result in stored file `foo.php`:
384
+
357
385
```php
358
386
<?php
359
387
@@ -375,8 +403,3 @@ return [
375
403
2 => 'iop',
376
404
];
377
405
```
378
-
379
-
380
-
## Copyright and License
381
-
382
-
`Pretty Array` was written by Andrey Helldar, and is released under the MIT License. See the [LICENSE](LICENSE) file for details.
0 commit comments