Skip to content

Commit

Permalink
Add ArrayHelper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Jun 12, 2024
1 parent 52118f5 commit d2c29f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"require": {
"php": "^8.3",
"ext-simplexml": "*",
"behat/behat": "^3.14",
"phpunit/phpunit": "^10.1|^11.0.1",
"symfony/css-selector": "^6.2|^7.1",
Expand Down
33 changes: 33 additions & 0 deletions src/Helpers/ArrayHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Helpers;

use SimpleXMLElement;

class ArrayHelper
{
public static function jsonToArray(string $json): array
{
return json_decode($json, true);
}

public static function arrayToJson(array $table): string
{
return json_encode($table);
}

public static function xmlToArray(string $xml): array
{
return json_decode(json_encode(simplexml_load_string($xml)), true);
}

public static function arrayToXml(array $table): string
{
$xml = new SimpleXMLElement("<root/>");
array_walk_recursive($table, [$xml, "addChild"]);

return $xml->asXML();
}
}

0 comments on commit d2c29f6

Please sign in to comment.