Skip to content

Commit

Permalink
Merge pull request #8 from microsoft/dev
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
SilasKenneth authored May 8, 2024
2 parents 1f7d608 + 45ee120 commit 2896ec2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,9 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
composer.lock
coverage/
vendor/
.DS_Store
*/**/.DS_Store
.idea/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Kiota URI Form Encoded Serialization Library for PHP

[![Build and Test](https://github.com/microsoft/kiota-serialization-form-php/actions/workflows/build-and_test.yml/badge.svg?branch=main)](https://github.com/microsoft/kiota-serialization-form-php/actions/workflows/build-and_test.yml)
[![Build and Test](https://github.com/microsoft/kiota-serialization-form-php/actions/workflows/pr-validation.yml/badge.svg?branch=main)](https://github.com/microsoft/kiota-serialization-form-php/actions/workflows/pr-validation.yml)
[![Latest Stable Version](http://poser.pugx.org/microsoft/kiota-serialization-form/v)](https://packagist.org/packages/microsoft/kiota-serialization-form)
[![Total Downloads](http://poser.pugx.org/microsoft/kiota-serialization-form/downloads)](https://packagist.org/packages/microsoft/kiota-serialization-form)
[![PHP Version Require](http://poser.pugx.org/microsoft/kiota-serialization-form/require/php)](https://packagist.org/packages/microsoft/kiota-serialization-form)

The Form Serialization Library for PHP is the PHP `application/x-www-form-urlencoded` serialization library implementation.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"require": {
"microsoft/kiota-abstractions": "^1.1.0",
"microsoft/kiota-abstractions": "^1.3.1",
"guzzlehttp/psr7": "^1.6 || ^2",
"php": "^7.4 || ^8",
"ext-json": "*"
Expand Down
4 changes: 3 additions & 1 deletion src/FormParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Microsoft\Kiota\Abstractions\Serialization\AdditionalDataHolder;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Serialization\ParseNode;
use Microsoft\Kiota\Abstractions\Serialization\ParseNodeFromStringTrait;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
use RuntimeException;

class FormParseNode implements ParseNode
{
use ParseNodeFromStringTrait;

/** @var callable(Parsable): void|null $onBeforeAssignFieldValues */
private $onBeforeAssignFieldValues = null;
Expand Down Expand Up @@ -228,7 +230,7 @@ public function getDateTimeValue(): ?DateTime
*/
public function getDateIntervalValue(): ?DateInterval
{
return ($this->node !== null) ? new DateInterval(strval($this->node)) : null;
return ($this->node !== null) ? $this->parseDateIntervalFromString(strval($this->node)) : null;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/FormSerializationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Microsoft\Kiota\Abstractions\Enum;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Serialization\SerializationWriter;
use Microsoft\Kiota\Abstractions\Serialization\SerializationWriterToStringTrait;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
Expand All @@ -18,6 +19,7 @@

class FormSerializationWriter implements SerializationWriter
{
use SerializationWriterToStringTrait;
/** @var callable|null */
private $onAfterObjectSerialization = null;
/** @var callable|null */
Expand Down Expand Up @@ -63,12 +65,12 @@ private function writePropertyValue(?string $key, $value): void {
*/
public function writeStringValue(?string $key, ?string $value): void
{
$propertyValue = $value !== null ? urlencode(addcslashes($value, "\\\r\n\"\t")) : '';
if ($value !== null) {
if (!empty($key)) {
$this->writePropertyName($key);
}
$this->writePropertyValue($key, $propertyValue);
$urlEncodedString = urlencode($this->getStringValueAsEscapedString($value));
$this->writePropertyValue($key, $urlEncodedString);
}
}

Expand Down Expand Up @@ -121,7 +123,7 @@ public function writeDateTimeValue(?string $key, ?DateTime $value): void
if (!empty($key)) {
$this->writePropertyName($key);
}
$this->writePropertyValue($key, "{$value->format(DateTimeInterface::RFC3339)}");
$this->writePropertyValue($key, $this->getDateTimeValueAsString($value));
}
}

Expand Down Expand Up @@ -275,8 +277,7 @@ public function writeDateIntervalValue(?string $key, ?DateInterval $value): void
if (!empty($key)) {
$this->writePropertyName($key);
}
$res = "P{$value->y}Y{$value->y}M{$value->d}DT{$value->h}H{$value->i}M{$value->s}S";
$this->writePropertyValue($key, $res);
$this->writePropertyValue($key, $this->getDateIntervalValueAsString($value));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/FormSerializationWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function testWriteDateIntervalValue(): void
$this->serializationWriter->writeAnyValue('timeTaken', $interval);

$content = $this->serializationWriter->getSerializedContent();
$this->assertEquals('timeTaken=P0Y0M300DT0H0M100S', $content->getContents());
$this->assertEquals('timeTaken=P300DT100S', $content->getContents());
}

public function testWriteBinaryContentValue(): void
Expand Down

0 comments on commit 2896ec2

Please sign in to comment.