-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
3,045 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.PHONY: test static coverage profile-clear | ||
|
||
test: | ||
vendor/bin/phpunit --color | ||
|
||
static: | ||
psalm --show-info=true | ||
|
||
|
||
coverage: | ||
XDEBUG_MODE=coverage vendor/bin/phpunit \ | ||
--coverage-clover $(PHPUNIT_COVERAGE_PATH)/cov.xml \ | ||
--coverage-filter src \ | ||
--coverage-html $(PHPUNIT_COVERAGE_PATH); | ||
hash xdg-open && xdg-open $(PHPUNIT_COVERAGE_PATH)/index.html; | ||
|
||
profile-clear: | ||
rm $(XDEBUG_OUTPUT_DIR)/cachegrind.out.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Flattener | ||
|
||
A lib for (un)flatten php data structure and a small cli for apply this on Json input. | ||
|
||
## Usage | ||
|
||
### Lib | ||
|
||
Basically, `Flattener::flatten(...)` turn this | ||
|
||
```php | ||
<?php | ||
|
||
[ | ||
'hello' => [ | ||
'world' => [ | ||
'!', '?' | ||
], | ||
'people' => [ | ||
1, 2.3 | ||
], | ||
], | ||
'bye' => null | ||
] | ||
``` | ||
|
||
into | ||
|
||
```php | ||
<?php | ||
|
||
[ | ||
'.hello.world[0]' => '!', | ||
'.hello.world[1]' => '?', | ||
'.hello.people[0]' => 1, | ||
'.hello.people[1]' => 2.3, | ||
'.bye' => null, | ||
] | ||
``` | ||
|
||
(And `Flattener::unflatten(...)` will play this backward) | ||
|
||
### CLI | ||
|
||
|
||
Get help | ||
|
||
```shell | ||
bin/json-unflatten --help | ||
``` | ||
|
||
## Dev | ||
|
||
### Coverage | ||
|
||
```shell | ||
make coverage | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
namespace Leneko\Flattener; | ||
|
||
require dirname(__DIR__, 1) . '/vendor/autoload.php'; | ||
|
||
use Silly\Application; | ||
|
||
$app = new Application('Json (un)flatten'); | ||
|
||
$app->command( | ||
'flatten [path]', | ||
function (string $path = 'php://stdin') { | ||
echo JsonFlatten::flatten( | ||
\file_get_contents($path) | ||
); | ||
} | ||
) | ||
->descriptions( | ||
'flatten a json structure', | ||
['path' => 'path to read or STDIN if not set'] | ||
); | ||
|
||
$app->command( | ||
'unflatten [path]', | ||
function (string $path = 'php://stdin') { | ||
echo JsonFlatten::unflatten( | ||
\file_get_contents($path) | ||
); | ||
} | ||
) | ||
->descriptions( | ||
'unflatten a json structure', | ||
['path' => 'path to read or STDIN if not set'] | ||
);; | ||
|
||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.