首页 > 解决方案 > Guzzle:魔术请求方法需要一个 URI 和可选的选项数组

问题描述

我正在使用https://github.com/golincode/sharepoint-oauth-app-client它已过时并使用 Guzzle 版本 5。我的 Symfony 应用程序使用 Guzzle 6。我正在尝试更新过时的代码以使用 Guzzle 6 但是我遇到以下错误:

Magic request methods require a URI and optional options array

控制器中的代码。

$settings = [
            'site' => [
                'resource'  => '00000000-0000-ffff-0000-000000000000/example.sharepoint.com@09g7c3b0-f0d4-416d-39a7-09671ab91f64',
                'client_id' => '52848cad-bc13-4d69-a371-30deff17bb4d/example.com@09g7c3b0-f0d4-416d-39a7-09671ab91f64',
                'secret'    => 'YzcZQ7N4lTeK5COin/nmNRG5kkL35gAW1scrum5mXVgE=',
            ]
        ];
        // create a SharePoint Site instance
        $site = SPSite::create('https://example.sharepoint.com/sites/mySite/', $settings);

SPSite.php 创建函数

public static function create($url, array $settings = [])
{
    // ensure we have a trailing slash
    if (is_string($url)) {
        $url = sprintf('%s/', rtrim($url, '/'));
    }

    $settings = array_replace_recursive($settings, [
        'site' => [], // SharePoint Site configuration
        'http' => [   // Guzzle HTTP Client configuration
            'base_url' => $url,
        ],
    ]);

    $http = new Client($settings['http']);

    return new static($http, $settings['site']);
}

Client.php 调用函数

public function __call($method, $args)
{
    if (count($args) < 1) {
        throw new \InvalidArgumentException('Magic request methods require a URI and optional options array');
    }

    $uri = $args[0];
    $opts = isset($args[1]) ? $args[1] : [];

    return substr($method, -5) === 'Async'
        ? $this->requestAsync(substr($method, 0, -5), $uri, $opts)
        : $this->request($method, $uri, $opts);
}

我不知道版本 5 和 6 之间发生了什么变化,这使得该代码不再工作。有人有线索吗?

标签: phpsymfonysharepointguzzle

解决方案


推荐阅读