带有 Lumen 的 AWS 开发工具包
AWS SDK with Lumen
我正在尝试使用 lumen 安装 AWS Laravel SDK。
我可以安装它:
{
"require": {
"aws/aws-sdk-php-laravel": "~3.0"
}
}
但是,文档说:
Find the providers key in your config/app.php and register the AWS Service Provider.
'providers' => array(
// ...
Aws\Laravel\AwsServiceProvider::class,
)
Find the aliases key in your config/app.php and add the AWS facade alias.
'aliases' => array(
// ...
'AWS' => Aws\Laravel\AwsFacade::class,
)
东西在Lumen,没有config/app。php
我该怎么做???
您可以复制默认的 Lumen 配置文件以覆盖它们。
Configuration Files
You may use full "Laravel style" configuration files if you wish. The
default files are stored in the vendor/laravel/lumen-framework/config
directory. Lumen will use your copy of the configuration file if you
copy and paste one of the files into a config directory within your
project root.
Using full configuration files will give you more control over some
aspects of Lumen's configuration, such as configuring multiple storage
"disks" or read / write database connections.
参考:http://lumen.laravel.com/docs/installation#configuration-files
在bootstrap/app.php中添加以下内容:
提供商:
$app->register(Aws\Laravel\AwsServiceProvider::class);
外观
class_alias('Aws\Laravel\AwsFacade','AWS');
- 请注意,您必须取消注释 $app->withFacades();为了工作的门面。
起初我也有点困惑所以我最后做了什么。
- 使用 Composer 安装 AWS Laravel SDK (https://github.com/aws/aws-sdk-php-laravel)。
- 更新 app.php 以包含
$app->register(Aws\Laravel\AwsServiceProvider::class);
- 将我的 AWS credential/region 值添加到我的 .env 文件
在我的一个助手类中创建一个方法,定义如下:
public static function getS3Instance() {
return new \Aws\S3\S3Client([
'version' => 'latest',
'region' => env('AWS_REGION'),
'credentials' => [
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET')
]
]);
}
在一个模型中,我只需调用 Util::getS3Instance() 并且 boom 我拥有开始使用 S3 所需的一切。此函数可以很容易地适应 return 库中包含的任何 AWS 客户端的实例。
这一切都发生在 Lumen 5.6 项目中,但我认为相同的方法也适用于旧版本的 Lumen。希望对您有所帮助!
我正在尝试使用 lumen 安装 AWS Laravel SDK。 我可以安装它:
{
"require": {
"aws/aws-sdk-php-laravel": "~3.0"
}
}
但是,文档说:
Find the providers key in your config/app.php and register the AWS Service Provider.
'providers' => array(
// ...
Aws\Laravel\AwsServiceProvider::class,
)
Find the aliases key in your config/app.php and add the AWS facade alias.
'aliases' => array(
// ...
'AWS' => Aws\Laravel\AwsFacade::class,
)
东西在Lumen,没有config/app。php
我该怎么做???
您可以复制默认的 Lumen 配置文件以覆盖它们。
Configuration Files
You may use full "Laravel style" configuration files if you wish. The default files are stored in the vendor/laravel/lumen-framework/config directory. Lumen will use your copy of the configuration file if you copy and paste one of the files into a config directory within your project root.
Using full configuration files will give you more control over some aspects of Lumen's configuration, such as configuring multiple storage "disks" or read / write database connections.
参考:http://lumen.laravel.com/docs/installation#configuration-files
在bootstrap/app.php中添加以下内容:
提供商:
$app->register(Aws\Laravel\AwsServiceProvider::class);
外观
class_alias('Aws\Laravel\AwsFacade','AWS');
- 请注意,您必须取消注释 $app->withFacades();为了工作的门面。
起初我也有点困惑所以我最后做了什么。
- 使用 Composer 安装 AWS Laravel SDK (https://github.com/aws/aws-sdk-php-laravel)。
- 更新 app.php 以包含
$app->register(Aws\Laravel\AwsServiceProvider::class);
- 将我的 AWS credential/region 值添加到我的 .env 文件
在我的一个助手类中创建一个方法,定义如下:
public static function getS3Instance() { return new \Aws\S3\S3Client([ 'version' => 'latest', 'region' => env('AWS_REGION'), 'credentials' => [ 'key' => env('AWS_KEY'), 'secret' => env('AWS_SECRET') ] ]); }
在一个模型中,我只需调用 Util::getS3Instance() 并且 boom 我拥有开始使用 S3 所需的一切。此函数可以很容易地适应 return 库中包含的任何 AWS 客户端的实例。
这一切都发生在 Lumen 5.6 项目中,但我认为相同的方法也适用于旧版本的 Lumen。希望对您有所帮助!