Skip to content

Commit

Permalink
Work on feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasKenneth committed Mar 14, 2022
1 parent 72f43f4 commit 34bc842
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added default implementations for table and JSON output in CLI commons (Shell) #1326

### Changed
- Add missing method getBinaryContent to the ParseNode interface(PHP).
- Split the Parsable interface into AdditionalData interface and Parsable interface(PHP) #1324.
- Shell commands will now default to writing indented JSON. This option can be disabled through the CLI option `--json-no-indent` (Shell) #1326
- Update System.CommandLine version (Shell) #1338
Expand Down
6 changes: 6 additions & 0 deletions abstractions/php/src/Serialization/ParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;

interface ParseNode {
/**
Expand Down Expand Up @@ -98,6 +99,11 @@ public function getEnumValue(string $targetEnum): ?Enum;
*/
public function getByteValue(): ?Byte;

/**
* Get a Stream from node.
* @return StreamInterface|null
*/
public function getBinaryContent(): ?StreamInterface;
/**
* Gets the callback called before the node is deserialized.
* @return callable the callback called before the node is deserialized.
Expand Down
17 changes: 12 additions & 5 deletions serialization/php/json/src/JsonParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,26 @@ private function assignFieldValues($result): void {
if (is_a($result, Parsable::class)){
$fieldDeserializers = $result->getFieldDeserializers();
}

$isAdditionalDataHolder = false;
$additionalData = [];
if (is_a($result, AdditionalDataHolder::class)) {
$isAdditionalDataHolder = true;
$additionalData = $result->getAdditionalData();
}
foreach ($this->jsonNode as $key => $value){
$deserializer = $fieldDeserializers[$key] ?? null;

if ($deserializer !== null){
$deserializer($result, new JsonParseNode($value));
} else if (is_a($result, AdditionalDataHolder::class)) {
$data = $result->getAdditionalData();
} else {
$key = (string)$key;
$data[$key] = $value;
$result->setAdditionalData($data);
$additionalData[$key] = $value;
}
}

if ( $isAdditionalDataHolder ) {
$result->setAdditionalData($additionalData);
}
}

/**
Expand Down

0 comments on commit 34bc842

Please sign in to comment.