Skip to content
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"require": {
"php": "^8.0 || ^7.3",
"guzzlehttp/guzzle": "^7.0",
"php-http/httplug": "^2.2.0",
"php-http/guzzle7-adapter": "^1.0.0",
"guzzlehttp/psr7": "^2.0",
"php-http/httplug": "^2.2",
"php-http/guzzle7-adapter": "^1.0",
"ext-json": "*"
},
"require-dev": {
Expand Down
77 changes: 0 additions & 77 deletions src/Core/ExceptionWrapper.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Core/GraphConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
final class GraphConstants
{
// These can be overwritten in setters in the Graph object
const API_VERSION = "v1.0";
const REST_ENDPOINT = "https://graph.microsoft.com/";

// Define HTTP request constants
Expand Down
12 changes: 7 additions & 5 deletions src/Core/NationalCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Microsoft\Graph\Core;

use Microsoft\Graph\Http\GraphRequestUtil;

/**
* Class NationalCloud
*
Expand Down Expand Up @@ -40,10 +38,14 @@ final class NationalCloud
* @param string $url
* @return bool
*/
public static function isValidNationalCloudHost(string $url): bool {
public static function containsNationalCloudHost(string $url): bool {
self::initHosts();
$validUrlParts = GraphRequestUtil::isValidBaseUrl($url);
return $validUrlParts && array_key_exists($validUrlParts["host"], self::$hosts);
$validUrlParts = parse_url($url);
return $validUrlParts
&& array_key_exists("scheme", $validUrlParts)
&& $validUrlParts["scheme"] == "https"
&& array_key_exists("host", $validUrlParts)
&& array_key_exists($validUrlParts["host"], self::$hosts);
}

/**
Expand Down
52 changes: 21 additions & 31 deletions src/Http/BaseClient.php → src/Http/AbstractGraphClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license https://opensource.org/licenses/MIT MIT License
* @link https://developer.microsoft.com/graph
*/
class BaseClient
abstract class AbstractGraphClient
{
/**
* The access_token provided after authenticating
Expand All @@ -32,14 +32,6 @@ class BaseClient
*/
private $accessToken;

/**
* The api version to use ("v1.0", "beta")
* Default is "v1.0"
*
* @var string
*/
private $apiVersion = GraphConstants::API_VERSION;

/**
* Host to use as the base URL and for authentication
* @var string
Expand All @@ -58,16 +50,13 @@ class BaseClient
*
* Creates a Graph client object used to make requests to the Graph API
*
* @param string|null $apiVersion if null|"" defaults to "v1.0"
* @param string|null $nationalCloud if null defaults to "https://graph.microsoft.com"
* @param HttpClientInterface|null $httpClient if null creates default Guzzle client
* @throws GraphClientException
*/
public function __construct(?string $apiVersion = GraphConstants::API_VERSION,
?string $nationalCloud = NationalCloud::GLOBAL,
protected function __construct(?string $nationalCloud = NationalCloud::GLOBAL,
?HttpClientInterface $httpClient = null)
{
$this->apiVersion = ($apiVersion) ?: GraphConstants::API_VERSION;
$this->nationalCloud = ($nationalCloud) ?: NationalCloud::GLOBAL;
$this->httpClient = ($httpClient) ?: HttpClientFactory::nationalCloud($nationalCloud)::createAdapter();
}
Expand All @@ -81,7 +70,7 @@ public function __construct(?string $apiVersion = GraphConstants::API_VERSION,
*
* @return $this object
*/
public function setAccessToken(string $accessToken): self
protected function setAccessToken(string $accessToken): self
{
$this->accessToken = $accessToken;
return $this;
Expand All @@ -94,13 +83,6 @@ public function getAccessToken(): string {
return $this->accessToken;
}

/**
* @return string
*/
public function getApiVersion(): string {
return $this->apiVersion;
}

/**
* @return string
*/
Expand All @@ -127,15 +109,12 @@ public function getHttpClient(): HttpClientInterface
* make queries against Graph
* @throws GraphException
*/
public function createRequest(string $requestType, string $endpoint): GraphRequest
protected function createRequest(string $requestType, string $endpoint): GraphRequest
{
return new GraphRequest(
$requestType,
$endpoint,
$this->accessToken,
$this->nationalCloud,
$this->apiVersion,
$this->httpClient
$this
);
}

Expand All @@ -150,15 +129,26 @@ public function createRequest(string $requestType, string $endpoint): GraphReque
* used to make queries against Graph
* @throws GraphException
*/
public function createCollectionRequest(string $requestType, string $endpoint): GraphRequest
protected function createCollectionRequest(string $requestType, string $endpoint): GraphRequest
{
return new GraphCollectionRequest(
$requestType,
$endpoint,
$this->accessToken,
$this->nationalCloud,
$this->apiVersion,
$this->httpClient
$this
);
}

/**
* Return SDK version used in the service library client.
*
* @return string
*/
public abstract function getSdkVersion(): string;

/**
* Returns API version used in the service library
*
* @return string
*/
public abstract function getApiVersion(): string;
}
Loading