适用于 Laravel 的 AWS 开发工具包出现 PHP 致命错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21785217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AWS SDK for Laravel giving PHP fatal error
提问by Chris Farrugia
I installed the https://github.com/aws/aws-sdk-php-laravel? SDK and followed the instructions in the readme.md. Everything installed, I put in my key, secret, region, etc. in the /app/config/packages/aws/aws-sdk-php-laravel
.
我安装了https://github.com/aws/aws-sdk-php-laravel?SDK 并按照 readme.md 中的说明进行操作。一切都安装好了,我把我的密钥、秘密、地区等放在/app/config/packages/aws/aws-sdk-php-laravel
.
The Error I'm Getting
我得到的错误
PHP Fatal error: Class 'Aws\Common\Aws' not found in /Volumes/Data/Users/chris/Sites/ln.com/vendor/aws/aws-sdk-php-laravel/src/Aws/Laravel/AwsServiceProvider.php on line 48
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Aws\Common\Aws' not found","file":"\/Volumes\/Data\/Users\/chris\/Sites\/ln.com\/vendor\/aws\/aws-sdk-php-laravel\/src\/Aws\/Laravel\/AwsServiceProvider.php","line":48}}
Line 48 of that file referenced above simply says:
上面引用的那个文件的第 48 行简单地说:
$aws = Aws::factory($config);
I installed per the instructions
我按照说明安装
I put in my providers and aliases in /app/config/app.php with:
我把我的提供者和别名放在 /app/config/app.php 中:
'Aws\Laravel\AwsServiceProvider'
in the providers array.
在提供者数组中。
I put in:
我输入:
'AWS' => 'Aws\Laravel\AwsFacade'
in the aliases section.
在别名部分。
Then, I'm trying to use their same usage example:
然后,我尝试使用他们相同的用法示例:
$s3 = AWS::get('s3');
$s3->putObject(array(
'Bucket' => 'My Bucket',
'Key' => 'My Key',
'SourceFile'=> Config::get('settings.ProcessListings.image_dir') . $listing->mls_listing_id . "/test.txt"
));
What I've Tried
我试过的
My only thoughts here were that in my file that I'm trying to use the SDK in, at the top I have:
我唯一的想法是在我试图在其中使用 SDK 的文件中,在顶部我有:
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
I've added to that:
我补充说:
use Aws\Laravel\AwsFacade;
use Aws\Laravel\AwsServiceProvider;
and combinations of the two but neither work. Any ideas?
和两者的组合,但都不起作用。有任何想法吗?
回答by Antonio Carlos Ribeiro
Your problem is in a class Aws\Common\Aws
from aws/aws-sdk-php
which is not available to composer (the autoloader). Those are steps that usually fix Laravel, when things like this happen and the problem is not on your source code, of course:
你的问题是一类Aws\Common\Aws
由aws/aws-sdk-php
这是不提供给作曲家(磁带自动加载机)。这些是通常修复 Laravel 的步骤,当发生这样的事情并且问题不在你的源代码上时,当然:
cd /your/application/dir
rm bootstrap/compiled.php
rm -rf vendor (or just rename your vendor folder to test)
composer update --no-dev
回答by Rahul Haque
I know I am late but, I've come across this problem recently and I didn't want to remove my compiled packages. In my case, running php artisan config:cache
was throwing that error. So what I did, I found Aws\\Laravel\\AwsServiceProvider
in bootstrap/cache/services.php
and removed them which solved the issue.
我知道我迟到了,但是我最近遇到了这个问题,我不想删除我编译的包。就我而言,跑步php artisan config:cache
会引发该错误。所以,我做什么,我发现Aws\\Laravel\\AwsServiceProvider
在bootstrap/cache/services.php
和删除它们,其解决了问题。