-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependencies to old Xml generator
- Loading branch information
Showing
22 changed files
with
119 additions
and
282 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
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
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
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 |
---|---|---|
|
@@ -8,11 +8,60 @@ | |
|
||
namespace Ibexa\Rest\Output\Generator\InMemory\Xml; | ||
|
||
use Ibexa\Rest\Output\Generator\Data\ArrayList; | ||
use Ibexa\Rest\Output\Generator\Json\FieldTypeHashGenerator as JsonFieldTypeHashGenerator; | ||
use Ibexa\Rest\Output\Generator\Json\JsonObject; | ||
|
||
final class FieldTypeHashGenerator extends JsonFieldTypeHashGenerator | ||
{ | ||
protected function generateValue($parent, $value): mixed | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} elseif (is_bool($value)) { | ||
return $value ? 'true' : 'false'; | ||
} elseif (is_float($value)) { | ||
return sprintf('%F', $value); | ||
} elseif (is_array($value)) { | ||
return $this->generateArrayValue($parent, $value); | ||
} else { | ||
return $value; | ||
} | ||
} | ||
|
||
/** | ||
* Generates an array value from $value. | ||
* | ||
* @param array $value | ||
* @param string|null $key | ||
*/ | ||
protected function generateArrayValue($parent, $value) | ||
Check failure on line 38 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php GitHub Actions / Unit & integration tests (8.3)
Check failure on line 38 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php GitHub Actions / Unit & integration tests (8.3)
|
||
{ | ||
if ($this->isNumericArray($value)) { | ||
return $this->generateListArray($parent, $value); | ||
} else { | ||
return $this->generateHashArray($parent, $value); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a JSON array from the given $hashArray with $parent. | ||
* | ||
* @param \Ibexa\Rest\Output\Generator\Json\ArrayObject|\Ibexa\Rest\Output\Generator\Json\JsonObject $parent | ||
* @param array $listArray | ||
* | ||
* @return \Ibexa\Rest\Output\Generator\Json\ArrayObject | ||
*/ | ||
protected function generateListArray($parent, array $listArray) | ||
Check failure on line 55 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php GitHub Actions / Unit & integration tests (8.3)
|
||
{ | ||
$arrayList = new ArrayList('value', $parent); | ||
foreach ($listArray as $listItem) { | ||
$arrayList->append($this->generateValue($parent, $listItem)); | ||
} | ||
|
||
return $arrayList; | ||
Check failure on line 62 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php GitHub Actions / Unit & integration tests (8.3)
|
||
} | ||
|
||
/** | ||
* Generates a JSON object from the given $hashArray with $parent. | ||
* | ||
|
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
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.