Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b23cc04
Add Http client factory
Ndiritu Jun 27, 2021
4c3fa35
Update Graph class to use HttpClientFactory
Ndiritu Jun 28, 2021
0293b63
Remove proxy configuration from Graph, GraphRequest and GraphCollecti…
Ndiritu Jun 28, 2021
7231294
Update copyright statement, class and interface php docs
Ndiritu Jun 29, 2021
b6cdb1a
Remove TODO comments
Ndiritu Jun 29, 2021
3665dd2
Set the httpClient on a Graph client only through the constructor
Ndiritu Jun 29, 2021
8762088
Make HttpClientFactory methods static
Ndiritu Jun 29, 2021
719d50c
Undo Windows-style CRLF newlines added by editor
Ndiritu Jun 29, 2021
4dc0e87
Update editorConfig to use Unix-style line endings (LF)
Ndiritu Jun 29, 2021
b95fc51
Restore GraphTest file to LF line endings
Ndiritu Jun 29, 2021
2f161e0
Improve validation of national cloud urls
Ndiritu Jun 30, 2021
b044859
Fix GraphException toString() to use child exception class names if n…
Ndiritu Jun 30, 2021
bca9780
Add reference to Guzzle client configuration documentation
Ndiritu Jun 30, 2021
acd2855
Set default apiVersion and nationalCloud on Graph client if empty str…
Ndiritu Jun 30, 2021
17bb389
Allow non-national cloud but valid hosts to be set as base URL of Gra…
Ndiritu Jun 30, 2021
f11850d
Improve base url and national cloud host validation
Ndiritu Jul 1, 2021
20186f0
Change ClientInitialisationException to GraphClientException
Ndiritu Jul 1, 2021
607d4e8
Renamed Graph to BaseClient
Ndiritu Jul 5, 2021
13112b4
Refactor GraphRequest and GraphCollectionRequest constructors
Ndiritu Jul 7, 2021
bdd2ed5
Make base graph client abstract
Ndiritu Jul 7, 2021
efb8bc8
Fix initialisation of default graph request headers
Ndiritu Jul 7, 2021
bed36da
Update PSR-7 request object when headers or body is updated
Ndiritu Jul 7, 2021
35ce3ff
Support PSR-18 and HttPlug async clients
Ndiritu Jul 8, 2021
8a92a86
GraphCollectionRequest updates
Ndiritu Jul 8, 2021
8583d17
Initialise http request object using init method in constructor
Ndiritu Jul 8, 2021
f1bb80f
Make national cloud host check case-insensitive
Ndiritu Jul 8, 2021
bfb37ca
Fix method access modifiers in AbstractGraphClient
Ndiritu Jul 12, 2021
7606355
Merge pull request #4 from microsoftgraph/philip/feat/graph-request-c…
Ndiritu Aug 18, 2021
018c427
Resolve merge conflicts
Ndiritu Aug 18, 2021
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
54 changes: 27 additions & 27 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# top-most EditorConfig file
root = true

# All PHP files MUST use the Unix LF (linefeed) line ending.
# Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.
# All PHP files MUST end with a single blank line.
# There MUST NOT be trailing whitespace at the end of non-blank lines.
[*]
charset = utf-8
end_of_line = crlf
insert_final_newline = true
trim_trailing_whitespace = true

# PHP-Files, Composer.json, MD-Files
[{*.php,composer.json,*.md}]
indent_style = space
indent_size = 4

# HTML-Files LESS-Files SASS-Files CSS-Files JS-Files JSON-Files
[{*.html,*.less,*.sass,*.css,*.js,*.json}]
indent_style = tab
indent_size = 4

# Gitlab-CI, Travis-CI
[*.yml]
indent_style = space
indent_size = 2
# top-most EditorConfig file
root = true
# All PHP files MUST use the Unix LF (linefeed) line ending.
# Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.
# All PHP files MUST end with a single blank line.
# There MUST NOT be trailing whitespace at the end of non-blank lines.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# PHP-Files, Composer.json, MD-Files
[{*.php,composer.json,*.md}]
indent_style = space
indent_size = 4
# HTML-Files LESS-Files SASS-Files CSS-Files JS-Files JSON-Files
[{*.html,*.less,*.sass,*.css,*.js,*.json}]
indent_style = tab
indent_size = 4
# Gitlab-CI, Travis-CI
[*.yml]
indent_style = space
indent_size = 2
74 changes: 38 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
{
"name": "microsoft/microsoft-graph-core",
"type": "library",
"description": "The Microsoft Graph SDK for PHP",
"homepage": "https://developer.microsoft.com/en-us/graph",
"license": "MIT",
"authors": [
{
"name": "Microsoft Graph Client Tooling",
"email": "graphtooling@service.microsoft.com",
"role": "Developer"
}
],
"require": {
"php": "^8.0 || ^7.3",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"mikey179/vfsstream": "^1.2",
"vimeo/psalm": "^4.8",
"microsoft/microsoft-graph": "^1.34"
},
"autoload": {
"psr-4": {
"Microsoft\\Graph\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Microsoft\\Graph\\Test\\": "tests/Functional/",
"Microsoft\\Graph\\Http\\Test\\": "tests/Http/"
}
}
}
{
"name": "microsoft/microsoft-graph-core",
"type": "library",
"description": "The Microsoft Graph SDK for PHP",
"homepage": "https://developer.microsoft.com/en-us/graph",
"license": "MIT",
"authors": [
{
"name": "Microsoft Graph Client Tooling",
"email": "graphtooling@service.microsoft.com",
"role": "Developer"
}
],
"require": {
"php": "^8.0 || ^7.3",
"guzzlehttp/guzzle": "^7.0",
"php-http/httplug": "^2.2.0",
"php-http/guzzle7-adapter": "^1.0.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"mikey179/vfsstream": "^1.2",
"vimeo/psalm": "^4.8",
"microsoft/microsoft-graph": "^1.34"
},
"autoload": {
"psr-4": {
"Microsoft\\Graph\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Microsoft\\Graph\\Test\\": "tests/Functional/",
"Microsoft\\Graph\\Http\\Test\\": "tests/Http/"
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ public function value()
{
return $this->_value;
}
}
}
63 changes: 63 additions & 0 deletions src/Core/NationalCloud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*/

namespace Microsoft\Graph\Core;

use Microsoft\Graph\Http\GraphRequestUtil;

/**
* Class NationalCloud
*
* Defines Graph hosts for the various national clouds
*
* @package Microsoft\Graph\Core
* @copyright 2021 Microsoft Corporation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://developer.microsoft.com/graph
*/
final class NationalCloud
{
const GLOBAL = "https://graph.microsoft.com";
const US_GOV = "https://graph.microsoft.us";
const US_DOD = "https://dod-graph.microsoft.us";
const GERMANY = "https://graph.microsoft.de";
const CHINA = "https://microsoftgraph.chinacloudapi.cn";

/**
* Unique hostnames from constant values [graph.microsoft.com, graph.microsoft.us, ...]
*
* @var array
*/
private static $hosts = [];

/**
* Checks if url contains a valid National Cloud host
*
* @param string $url
* @return bool
*/
public static function isValidNationalCloudHost(string $url): bool {
self::initHosts();
$validUrlParts = GraphRequestUtil::isValidBaseUrl($url);
return $validUrlParts && array_key_exists($validUrlParts["host"], self::$hosts);
}

/**
* Extracts hostnames from constant values to an array with unique keys for optimal lookup
*/
private static function initHosts(): void {
if (!self::$hosts) {
$reflectedClass = new \ReflectionClass(__CLASS__);
$constants = $reflectedClass->getConstants();
foreach ($constants as $constName => $url) {
// Create associative array for O(1) key lookup
$hostname = parse_url($url)["host"];
self::$hosts[$hostname] = true;
}
}
}
}
21 changes: 21 additions & 0 deletions src/Exception/GraphClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*/

namespace Microsoft\Graph\Exception;

/**
* Class ClientInitialisationException
*
* @package Microsoft\Graph\Exception
* @copyright 2021 Microsoft Corporation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://developer.microsoft.com/graph
*/
class GraphClientException extends GraphException
{

}
12 changes: 6 additions & 6 deletions src/Exception/GraphException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*
*
* Exceptions File
* PHP version 7
*
Expand Down Expand Up @@ -46,6 +46,6 @@ public function __construct($message, $code = 0, $previous = null)
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
return get_called_class() . ": [{$this->code}]: {$this->message}\n";
}
}
}
Loading