microsoft/microsoft-graph-core 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

microsoft/microsoft-graph-core

Composer 安装命令:

composer require microsoft/microsoft-graph-core

包简介

The Microsoft Graph Core SDK for PHP

README 文档

README

Latest Stable Version Coverage

Install the Core Library

To install the microsoft-graph-core library with Composer, either run composer require microsoft/microsoft-graph-core, or edit your composer.json file:

{
    "require": {
        // x-release-please-start-version
        "microsoft/microsoft-graph-core": "^3.0.0"
        // x-release-please-end
    }
}

Get started with Microsoft Graph

1. Register your application

Register your application to use the Microsoft Graph API by following the steps at Register an application with the Microsoft Identity platform.

2. Authenticate with the Microsoft Graph service

The Microsoft Graph Core SDK for PHP does not include any default authentication implementations. The thephpleague/oauth2-client library will handle the OAuth2 flow for you and provide a usable token for querying the Graph.

To authenticate as an application, please see this guide to configure the right permissions.

You can use the Guzzle HTTP client, which comes preinstalled with this library, to get an access token like this:

$tokenRequestContext = new ClientCredentialContext(
    'tenantId',
    'clientId',
    'clientSecret'
);
// requests using https://graph.microsoft.com/.default scopes by default
$tokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext);
$token = $tokenProvider->getAuthorizationTokenAsync(GraphConstants::REST_ENDPOINT)->wait();

3. Create a Guzzle HTTP client object

You can create a Guzzle HTTP client object pre-configured for use with the Graph API using our GraphClientFactory. The GraphClientFactory sets some Guzzle config defaults such as connection and request timeouts, and the base_uri to your preferred National Cloud endpoint.

In the near future, the GraphClientFactory will provide some default middleware to use with the Graph API such as retry handlers.

use Microsoft\Graph\Core\GraphClientFactory;

$guzzleConfig = [
    // your preferred guzzle config
];

$httpClient = GraphClientFactory::createWithConfig($guzzleConfig);

4. Call Microsoft Graph using the v1.0 endpoint

The following is an example that shows how to call Microsoft Graph.

use Microsoft\Graph\Core\GraphClientFactory;

class UsageExample
{
    public function run()
    {
        $accessToken = 'xxx';

        $config = [
            'headers' => [
                'Authorization' => $accessToken
            ]
        ];

        $httpClient = GraphClientFactory::createWithConfig($config);
        $response = $httpClient->get("/v1.0/me");
        $currentUser = json_decode($response->getBody());

        echo "Hello, I am {$currentUser['givenName']}";
    }
}

We provide Microsoft Graph models for easy serialization and deserialization.

If you would like to leverage the models we provide, please take a look at the Microsoft Graph PHP SDK and for beta models - the Microsoft Graph Beta PHP SDK.

Documentation and resources

Develop

Run Tests

Run

vendor/bin/phpunit

from the base directory.

Debug tests on Windows

This SDK has an XDebug run configuration that attaches the debugger to VS Code so that you can debug tests.

  1. Install the PHP Debug extension into Visual Studio Code.
  2. From the root of this repo, using PowerShell, run php .\tests\GetPhpInfo.php | clip from the repo root. This will copy PHP configuration information into the clipboard which we will use in the next step.
  3. Paste your clipboard into the XDebug Installation Wizard and select Analyse my phpinfo() output.
  4. Follow the generated instructions for installing XDebug. Note that the /ext directory is located in your PHP directory.
  5. Add the following info to your php.ini file:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

Now you can hit a Visual Studio Code breakpoint in a test. Try this:

  1. Add a breakpoint to testCreateWithConfigCreatesClient in .\tests\Http\GraphClientFactoryTest.php.
  2. Run the Listen for XDebug configuration in VS Code.
  3. Run .\vendor\bin\phpunit --filter testCreateWithConfigCreatesClient from the PowerShell terminal to run the test and hit the breakpoint.

Issues

View or log issues on the Issues tab in the repo.

Contribute

Please read our Contributing guidelines carefully for advice on how to contribute to this repo.

Copyright and license

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

microsoft/microsoft-graph-core 适用场景与选型建议

microsoft/microsoft-graph-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.65M 次下载、GitHub Stars 达 15, 最近一次更新时间为 2021 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 microsoft/microsoft-graph-core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 microsoft/microsoft-graph-core 我们能提供哪些服务?
定制开发 / 二次开发

基于 microsoft/microsoft-graph-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.65M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 17
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 13
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-20