Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP - Request Adapter #1048

Merged
merged 15 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions abstractions/php/src/RequestAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interface RequestAdapter {
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
* @param RequestInformation $requestInfo the request info to execute.
* @param mixed|null $targetClass the class of the response model to deserialize the response into.
* @param string $targetClass the class of the response model to deserialize the response into.
* @param ResponseHandler|null $responseHandler The response handler to use for the HTTP request instead of the default handler.
* @return Promise with the deserialized response model.
*/
public function sendAsync(RequestInformation $requestInfo, $targetClass = null, ?ResponseHandler $responseHandler = null): Promise;
public function sendAsync(RequestInformation $requestInfo, string $targetClass, ?ResponseHandler $responseHandler = null): Promise;
SilasKenneth marked this conversation as resolved.
Show resolved Hide resolved

/**
* Gets the serialization writer factory currently in use for the HTTP core service.
Expand All @@ -25,12 +25,37 @@ public function getSerializationWriterFactory(): SerializationWriterFactory;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
* @param RequestInformation $requestInfo
* @param mixed $targetClass the request info to execute.
* @param string $targetClass the request info to execute.
* @param ResponseHandler|null $responseHandler
* @return Promise with the deserialized response model collection.
*/
public function sendCollectionAsync(RequestInformation $requestInfo, $targetClass = null, ?ResponseHandler $responseHandler = null): Promise;
public function sendCollectionAsync(RequestInformation $requestInfo, string $targetClass, ?ResponseHandler $responseHandler = null): Promise;

/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
* @param RequestInformation $requestInfo
* @param string $primitiveType e.g. int, bool
* @param ResponseHandler|null $responseHandler
* @return Promise
*/
public function sendPrimitiveAsync(RequestInformation $requestInfo, string $primitiveType, ?ResponseHandler $responseHandler = null): Promise;

/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection.
* @param RequestInformation $requestInfo
* @param string $primitiveType e.g. int, bool
* @param ResponseHandler|null $responseHandler
* @return Promise
*/
public function sendPrimitiveCollectionAsync(RequestInformation $requestInfo, string $primitiveType, ?ResponseHandler $responseHandler = null): Promise;

/**
* Executes the HTTP request specified by the given RequestInformation with no return content.
* @param RequestInformation $requestInfo
* @param ResponseHandler|null $responseHandler
* @return Promise
*/
public function sendNoContentAsync(RequestInformation $requestInfo, ?ResponseHandler $responseHandler = null): Promise;
/**
* Enables the backing store proxies for the SerializationWriters and ParseNodes in use.
* @param BackingStoreFactory $backingStoreFactory The backing store factory to use.
Expand Down
10 changes: 5 additions & 5 deletions abstractions/php/src/RequestInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class RequestInformation {
/** @var string $RAW_URL_KEY */
private static string $RAW_URL_KEY = 'request-raw-url';
public static string $RAW_URL_KEY = 'request-raw-url';
/** @var string $urlTemplate The url template for the current request */
public string $urlTemplate;
/**
Expand All @@ -19,8 +19,8 @@ class RequestInformation {
*/
public array $pathParameters = [];

/** @var string|null $uri */
private ?string $uri;
/** @var string $uri */
private string $uri;
/**
* @var string The HTTP method for the request
*/
Expand All @@ -36,12 +36,12 @@ class RequestInformation {
/** @var string $binaryContentType */
private static string $binaryContentType = 'application/octet-stream';
/** @var string $contentTypeHeader */
private static string $contentTypeHeader = 'Content-Type';
public static string $contentTypeHeader = 'Content-Type';

/** Gets the URI of the request.
* @return string
*/
public function getUri(): ?string {
public function getUri(): string {
if (!empty($this->uri)) {
return $this->uri;
}
Expand Down
22 changes: 15 additions & 7 deletions abstractions/php/src/Serialization/ParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public function getIntegerValue(): int;
*/
public function getFloatValue(): float;

/**
* Gets the Long value of the node.
* @return int the Long value of the node.
*/
public function getLongValue(): int;

/**
* Gets the UUID value of the node.
* @return string the UUID value of the node.
Expand All @@ -55,7 +49,21 @@ public function getUUIDValue(): string;
* Gets the model object value of the node.
* @return object the model object value of the node.
*/
public function getObjectValue(): object;
public function getObjectValue(string $targetClass): object;

/**
* Gets the collection of model object values from the node
* @param string $targetClass
* @return object[]
*/
public function getCollectionOfObjectValues(string $targetClass): array;

/**
* Gets the collection of primitive values from the node
* @param string $primitiveType
* @return array<mixed>
*/
public function getCollectionOfPrimitiveValues(string $primitiveType): array;

/**
* Gets the OffsetDateTime value of the node.
Expand Down
2 changes: 1 addition & 1 deletion abstractions/php/src/Serialization/ParseNodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ParseNodeFactory {
* @param StreamInterface $rawResponse the content type of the {@link StreamInterface}.
* @return ParseNode a {@link ParseNode} that can deserialize the given {@link StreamInterface}.
*/
public function getParseNode(string $contentType, StreamInterface $rawResponse): ParseNode;
public function getRootParseNode(string $contentType, StreamInterface $rawResponse): ParseNode;

/**
* Returns the content type this factory's parse nodes can deserialize.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class ParseNodeFactoryRegistry implements ParseNodeFactory {
* @param StreamInterface $rawResponse
* @return ParseNode
*/
public function getParseNode(string $contentType, StreamInterface $rawResponse): ParseNode {
public function getRootParseNode(string $contentType, StreamInterface $rawResponse): ParseNode {
if (empty(trim($contentType))) {
throw new InvalidArgumentException('$contentType cannot be empty.');
}
if (array_key_exists($contentType, $this->contentTypeAssociatedFactories)) {
return $this->contentTypeAssociatedFactories[$contentType]->getParseNode($contentType, $rawResponse);
return $this->contentTypeAssociatedFactories[$contentType]->getRootParseNode($contentType, $rawResponse);
}
throw new UnexpectedValueException('Content type ' . $contentType . ' does not have a factory to be parsed');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(ParseNodeFactory $concreteParseNodeFactory, ?callabl
* @param StreamInterface $rawResponse
* @return ParseNode
*/
public function getParseNode(string $contentType, StreamInterface $rawResponse): ParseNode {
$node = $this->concreteParseNodeFactory->getParseNode($contentType, $rawResponse);
public function getRootParseNode(string $contentType, StreamInterface $rawResponse): ParseNode {
$node = $this->concreteParseNodeFactory->getRootParseNode($contentType, $rawResponse);
$originalBefore = $node->getOnBeforeAssignFieldValues();
$originalAfter = $node->getOnAfterAssignFieldValues();

Expand Down
8 changes: 8 additions & 0 deletions http/php/guzzle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"name": "microsoft/kiota-http-guzzle",
"description": "Kiota Request Adapter implementation",
"type": "library",
"repositories": [
{
"type": "path",
"url": "../../../abstractions/php",
"only": ["microsoft/kiota-abstractions"]
}
],
"require": {
"php": "^7.4 | ^8.0",
"php-http/guzzle7-adapter": "^1.0",
"php-http/httplug": "^2.2",
"microsoft/kiota-abstractions": "*@dev",
"ext-zlib": "*"
},
"require-dev": {
Expand Down
Loading