简体   繁体   English

传递给Aws \ AwsClient :: getCommand()的参数2必须是类型数组,字符串给定

[英]Argument 2 passed to Aws\AwsClient::getCommand() must be of the type array, string given

I followed installation from this page . 我从这个页面跟着安装。

Which is version 3 of the SDK. 这是SDK的第3版。 Basic usage here . 这里的基本用法。

<?php
require 'vendor/autoload.php';

use Aws\CloudFront\CloudFrontClient;
$cdn = new CloudFrontClient(
['version' => 'latest',
 'region'  => 'us-east-1']
);

// Create a new invalidation.
$response = $cdn->create_invalidation('EPYAAAAAAPAA', 'aws-clear-cache' . time(), "/*");

According to this article . 根据这篇文章

Catchable fatal error: Argument 2 passed to Aws\\AwsClient::getCommand() must be of the type array, string given, called in /Users/jason/www/aws/vendor/aws/aws-sdk-php/src/AwsClient.php on line 167 and defined in /Users/jason/www/aws/vendor/aws/aws-sdk-php/src/AwsClient.php on line 211 可捕获的致命错误:传递给Aws \\ AwsClient :: getCommand()的参数2必须是类型数组,给定的字符串,在/ Users / jason / www / aws / vendor / aws / aws-sdk-php / src / AwsClient中调用第167行的.php,第211行的/Users/jason/www/aws/vendor/aws/aws-sdk-php/src/AwsClient.php中的定义

UPDATED & WORKING SOLUTION HERE: 此处更新和工作解决方案:

$config = array(
                'region' => 'us-east-1',
                'version' => '2015-07-27',
                'credentials' => array(
                    'key'    => env('AMAZON_KEY_CLOUDFRONT'),  
                    'secret' => env('AMAZON_SECRET_CLOUDFRONT') 
                )
            );

        $cdn = new CloudFrontClient($config);

        $cache =    array('DistributionId' => env('CLOUDFRONT'),
                    'InvalidationBatch' => array(
                        'CallerReference' => 'none',
                        'Paths' => array(
                            'Quantity' => 1,
                            'Items' => array( 'test' => '/*')
                            )
                        )

            );

        // Create a new invalidation.
        $response = $cdn->createInvalidation($cache);
        var_dump($response);

I took a look at what was going on here and apparently you're using an invalid method signature. 我看了一下这里发生了什么,显然你正在使用无效的方法签名。

First of all, the AWS PHP SDK uses something called "service description models" to get an API interface for the version you specified. 首先,AWS PHP SDK使用称为“服务描述模型”的东西来获取您指定版本的API接口。 In this case that means they are using some meta-programming techniques to provide an interface to what looks like normal PHP function calls, but the functions are not hard-coded in the SDK. 在这种情况下,这意味着他们使用一些元编程技术来提供看起来像普通PHP函数调用的接口,但这些函数在SDK中没有硬编码。 They don't really exist in the sense we generally think of, at least not as regular PHP functions. 它们并不存在于我们通常认为的意义上,至少不像普通的PHP函数那样存在。 Some PHP magic is going on underneath. 一些PHP魔法正在下面发生。

When you call $cdn->create_invalidation() it runs on the Aws\\CloudFront\\CloudFrontClient instance which inherits from Aws\\AwsClient . 当你调用$cdn->create_invalidation()它会在继承自Aws\\AwsClient Aws\\CloudFront\\CloudFrontClient实例上Aws\\AwsClient Neither of those classes (nor any of their ancestors) actually have a ::create_invalidation() method implementation. 这些类(也没有任何祖先)实际上都没有::create_invalidation()方法实现。 But AwsClient does implement the PHP magic method ::__call() . 但是AwsClient确实实现了PHP魔术方法::__call() You can see the PHP docs for the full info on this magic method, but basically when you call any method that doesn't exist on an object, if its class implements ::__call() , then ::__call() will be invoked instead. 您可以在PHP文档中查看有关此魔术方法的完整信息,但基本上当您调用对象上不存在的任何方法时,如果其类实现::__call() ,则将::__call()代替。

So now we're inside of ::__call() (you can see the code here ) and this method ends up calling ::getCommand() . 所以现在我们在::__call() (你可以看到这里的代码),这个方法最终调用::getCommand() Inside of ::getCommand() you can see that the method signature requires an array to be passed in (the first argument, $name , is the only other method parameter and it's going to have the value "create_invalidation" because of the way ::__call() was implemented above). ::getCommand()内部,您可以看到方法签名需要传入一个数组(第一个参数$name ,是唯一的其他方法参数,并且由于以下方式,它将具有值"create_invalidation" ::__call()已在上面实现)。 So that's where the the first problem crops up: you need to pass in an array, not individual strings or timestamps or anything else. 这就是第一个问题出现的地方:你需要传入一个数组,而不是单个字符串或时间戳或其他任何东西。

But there's one other thing; 但还有另外一件事; the actual method you want to call is not called create_invalidation , but createInvalidation . 要调用的实际方法不是create_invalidation ,而是createInvalidation There are full API docs for the SDK here - just make sure you pick the right version. 有完整的API文档的SDK 这里 -只要确保你选择正确的版本。 For the version I'm looking at, you can find the API docs and method signature for creating invalidations here . 对于我正在查看的版本,您可以在此处找到用于创建失效的API文档和方法签名。

You can find lots of information about the AWS PHP SDK including links to a User Guide, API Docs, and more, in the project's GitHub readme . 您可以在项目的GitHub自述文件中找到有关AWS PHP SDK的大量信息,包括指向用户指南,API文档等的链接。 Good luck and happy coding :) 祝你好运,快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数 1 通过,必须是数组类型,给定字符串 - Argument 1 passed, must be of the type array, string given 传递给 pluginSplit() 的参数 1 必须是字符串类型,给定数组 - Argument 1 passed to pluginSplit() must be of the type string, array given 传递给 GuzzleHttp\\Client::request() 的参数 3 必须是数组类型,给定字符串 - Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given 类型错误:传递给 Illuminate\\Database\\Grammar::parameterize() 的参数 1 必须是数组类型,给出的字符串 - Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given array_map-“传递的参数必须是数组类型,给定字符串”错误 - array_map - “Argument passed must be of the type array, string given” error 传递给Symfony \\ Component \\ HttpFoundation \\ Cookie :: __ construct()的参数2必须为字符串类型或null,给定数组 - Argument 2 passed to Symfony\Component\HttpFoundation\Cookie::__construct() must be of the type string or null, array given 传递给Illuminate \\ Database \\ Grammar :: parameterize()的参数1必须是类型数组,字符串给定 - Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given 传递给 Illuminate\\Database\\Query\\Builder::update() 的参数 1 必须是数组类型,给定的字符串,调用 - Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in 传递给 yii\db\conditions\HashConditionBuilder::build() 的参数 2 必须是数组类型,字符串在 Yii2 中给出 - Argument 2 passed to yii\db\conditions\HashConditionBuilder::build() must be of the type array, string given in Yii2 如何解决:传递给 Illuminate\Database\Grammar::parameterize() 的参数 1 必须是数组类型,给定的字符串 - How to solve: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM