CallRecords
1 year ago
Core
6 months ago
Exception
5 years ago
ExternalConnectors
1 year ago
Http
6 months ago
Model
5 months ago
TermStore
1 year ago
Graph.php
1 year ago
Graph.php
185 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright (c) Microsoft Corporation. All Rights Reserved. |
| 4 | * Licensed under the MIT License. See License in the project root |
| 5 | * for license information. |
| 6 | * |
| 7 | * Graph File |
| 8 | * PHP version 7 |
| 9 | * |
| 10 | * @category Library |
| 11 | * @package Microsoft.Graph |
| 12 | * @copyright 2016 Microsoft Corporation |
| 13 | * @license https://opensource.org/licenses/MIT MIT License |
| 14 | * @version GIT: 0.1.0 |
| 15 | * @link https://graph.microsoft.io/ |
| 16 | */ |
| 17 | |
| 18 | namespace Microsoft\Graph; |
| 19 | |
| 20 | use Microsoft\Graph\Core\GraphConstants; |
| 21 | use Microsoft\Graph\Http\GraphCollectionRequest; |
| 22 | use Microsoft\Graph\Http\GraphRequest; |
| 23 | |
| 24 | /** |
| 25 | * Class Graph |
| 26 | * |
| 27 | * @category Library |
| 28 | * @package Microsoft.Graph |
| 29 | * @license https://opensource.org/licenses/MIT MIT License |
| 30 | * @link https://graph.microsoft.io/ |
| 31 | */ |
| 32 | class Graph |
| 33 | { |
| 34 | /** |
| 35 | * The access_token provided after authenticating |
| 36 | * with Microsoft Graph (required) |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | private $_accessToken; |
| 41 | /** |
| 42 | * The api version to use ("v1.0", "beta") |
| 43 | * Default is "v1.0" |
| 44 | * |
| 45 | * @var string |
| 46 | */ |
| 47 | private $_apiVersion; |
| 48 | /** |
| 49 | * The base url to call |
| 50 | * Default is "https://graph.microsoft.com" |
| 51 | * |
| 52 | * @var string |
| 53 | */ |
| 54 | private $_baseUrl; |
| 55 | /** |
| 56 | * The port to use for proxy requests |
| 57 | * Null disables port forwarding |
| 58 | * |
| 59 | * @var string |
| 60 | */ |
| 61 | private $_proxyPort; |
| 62 | |
| 63 | /** |
| 64 | * Whether SSL verification should be used for proxy requests |
| 65 | * |
| 66 | * @var bool |
| 67 | */ |
| 68 | private $_proxyVerifySSL; |
| 69 | |
| 70 | /** |
| 71 | * Creates a new Graph object, which is used to call the Graph API |
| 72 | */ |
| 73 | public function __construct() |
| 74 | { |
| 75 | $this->_apiVersion = GraphConstants::API_VERSION; |
| 76 | $this->_baseUrl = GraphConstants::REST_ENDPOINT; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Sets the Base URL to call (defaults to https://graph.microsoft.com) |
| 81 | * |
| 82 | * @param string $baseUrl The URL to call |
| 83 | * |
| 84 | * @return Graph object |
| 85 | */ |
| 86 | public function setBaseUrl($baseUrl) |
| 87 | { |
| 88 | $this->_baseUrl = $baseUrl; |
| 89 | return $this; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Sets the API version to use, e.g. "beta" (defaults to v1.0) |
| 94 | * |
| 95 | * @param string $apiVersion The API version to use |
| 96 | * |
| 97 | * @return Graph object |
| 98 | */ |
| 99 | public function setApiVersion($apiVersion) |
| 100 | { |
| 101 | $this->_apiVersion = $apiVersion; |
| 102 | return $this; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the access token. A valid access token is required |
| 107 | * to run queries against Graph |
| 108 | * |
| 109 | * @param string $accessToken The user's access token, retrieved from |
| 110 | * MS auth |
| 111 | * |
| 112 | * @return Graph object |
| 113 | */ |
| 114 | public function setAccessToken($accessToken) |
| 115 | { |
| 116 | $this->_accessToken = $accessToken; |
| 117 | return $this; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Sets the proxy port. This allows you |
| 122 | * to use tools such as Fiddler to view |
| 123 | * requests and responses made with Guzzle |
| 124 | * |
| 125 | * @param string port The port number to use |
| 126 | * @param bool $verifySSL Whether SSL verification should be enabled |
| 127 | * |
| 128 | * @return Graph object |
| 129 | */ |
| 130 | public function setProxyPort($port, $verifySSL = false) |
| 131 | { |
| 132 | $this->_proxyPort = $port; |
| 133 | $this->_proxyVerifySSL = $verifySSL; |
| 134 | |
| 135 | return $this; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Creates a new request object with the given Graph information |
| 140 | * |
| 141 | * @param string $requestType The HTTP method to use, e.g. "GET" or "POST" |
| 142 | * @param string $endpoint The Graph endpoint to call |
| 143 | * |
| 144 | * @return GraphRequest The request object, which can be used to |
| 145 | * make queries against Graph |
| 146 | * @throws Exception\GraphException |
| 147 | */ |
| 148 | public function createRequest($requestType, $endpoint) |
| 149 | { |
| 150 | return new GraphRequest( |
| 151 | $requestType, |
| 152 | $endpoint, |
| 153 | $this->_accessToken, |
| 154 | $this->_baseUrl, |
| 155 | $this->_apiVersion, |
| 156 | $this->_proxyPort, |
| 157 | $this->_proxyVerifySSL |
| 158 | ); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Creates a new collection request object with the given |
| 163 | * Graph information |
| 164 | * |
| 165 | * @param string $requestType The HTTP method to use, e.g. "GET" or "POST" |
| 166 | * @param string $endpoint The Graph endpoint to call |
| 167 | * |
| 168 | * @return GraphCollectionRequest The request object, which can be |
| 169 | * used to make queries against Graph |
| 170 | * @throws Exception\GraphException |
| 171 | */ |
| 172 | public function createCollectionRequest($requestType, $endpoint) |
| 173 | { |
| 174 | return new GraphCollectionRequest( |
| 175 | $requestType, |
| 176 | $endpoint, |
| 177 | $this->_accessToken, |
| 178 | $this->_baseUrl, |
| 179 | $this->_apiVersion, |
| 180 | $this->_proxyPort, |
| 181 | $this->_proxyVerifySSL |
| 182 | ); |
| 183 | } |
| 184 | } |
| 185 |