icyboy / lumen-aws-sdk
一个简单的Lumen 5服务提供者,用于包含PHP的AWS SDK。
1.0.2
2016-11-01 07:55 UTC
Requires
- php: >=5.5.9
- aws/aws-sdk-php: ~3.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: ~4.0|~5.0
This package is not auto-updated.
Last update: 2024-09-23 13:31:44 UTC
README
这是一个简单的Lumen服务提供者,可以轻松地将官方的AWS SDK for PHP包含到您的Lumen应用程序中。
此README是为服务提供者的1.x版本,该版本与AWS SDK for PHP的版本3和Lumen 5.X一起使用。
安装
可以通过在项目的composer.json
中要求icyboy/lumen-aws-sdk
包,通过Composer安装AWS服务提供者。
{ "require": { "icyboy/lumen-aws-sdk": "^1.0" } }
然后运行composer update
php composer.phar update
要使用AWS服务提供者,您必须在启动Lumen应用程序时注册提供者。
在bootstarp/app.php
中找到providers
键并注册AWS服务提供者。
$app->register(Icyboy\LumenAws\AwsServiceProvider::class); class_alias('Icyboy\LumenAws\AwsFacade', 'Aws');
配置
默认情况下,该包使用以下环境变量来自动配置插件而无需修改
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION (default = us-east-1)
要自定义配置文件,请使用Artisan发布包配置。
php artisan vendor:publish
在生成的config/aws.php
配置文件中更新您的设置。
return [ 'credentials' => [ 'key' => 'YOUR_AWS_ACCESS_KEY_ID', 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', ], 'region' => 'us-west-2', 'version' => 'latest', // You can override settings for specific services 'Ses' => [ 'region' => 'us-east-1', ], // if you use fake s3, you must used endpoint 'endpoint' => "http://xxxx", ];
用法
$s3 = App::make('aws')->createClient('s3'); $s3->putObject(array( 'Bucket' => 'YOUR_BUCKET', 'Key' => 'YOUR_OBJECT_KEY', 'SourceFile' => '/the/path/to/the/file/you/are/uploading.ext', ));
如果AWS外观在应用程序配置的aliases
部分中注册,您还可以使用以下技术。
$s3 = Aws::createClient('s3'); $s3->putObject(array( 'Bucket' => 'YOUR_BUCKET', 'Key' => 'YOUR_OBJECT_KEY', 'SourceFile' => '/the/path/to/the/file/you/are/uploading.ext', ));