定制 sunaoka/laravel-aws-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sunaoka/laravel-aws-sdk-php

最新稳定版本:1.4.1

Composer 安装命令:

composer require sunaoka/laravel-aws-sdk-php

包简介

AWS Service Provider for Laravel

README 文档

README

Latest Stable Version License PHP from Packagist Laravel Test codecov

Installation

composer require sunaoka/laravel-aws-sdk-php

Configurations

php artisan vendor:publish --tag=aws-config

The settings can be found in the generated config/aws.php configuration file.

<?php

return [
    'credentials' => [
        'key'    => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'token'  => env('AWS_SESSION_TOKEN'),
    ],
    'region'      => env('AWS_DEFAULT_REGION'),
    'version'     => env('AWS_API_VERSION', 'latest'),
    'endpoint'    => env('AWS_ENDPOINT'),

    // Override Configuration for specific services
    // 'S3' => [
    //     'use_path_style_endpoint' => false,
    // ],
];

Usage

$s3 = \AWS::createS3();

$result = $s3->getObject([
    'Bucket' => 'Bucket',
    'Key'    => 'Key',
]);

echo $result['Body'];

Testing

You may use the AWS facade's fake method to apply the mock handler.

For more information on mock handlers, please refer to the Developer Guide.

use Aws\Result;
use Aws\MockHandler;
use Aws\CommandInterface;
use Psr\Http\Message\RequestInterface;
use Aws\Exception\AwsException;

$mock = new MockHandler();
$mock->append(new Result(['Body' => 'foo']));
$mock->append(function (CommandInterface $cmd, RequestInterface $req) {
    return new AwsException('Mock exception', $cmd);
});

\AWS::fake($mock);

$s3 = \AWS::createS3();

$result = $s3->getObject([
    'Bucket' => 'Bucket',
    'Key'    => 'Key',
]);

echo $result['Body']; // foo

Mock handlers can also be set for each client.

use Aws\DynamoDB\DynamoDbClient;
use Aws\MockHandler;
use Aws\Result;
use Aws\S3\S3Client;

$mockHandlers = [
    S3Client::class => new MockHandler([
        new Result(['Body' => __METHOD__]),
    ]),
    DynamoDbClient::class => new MockHandler([
        new Result(['TableNames' => ['Table1', 'Table2', 'Table3']]),
    ]),
];

\AWS::fake($mockHandlers);

$s3 = \AWS::createS3();

$result = $s3->getObject([
    'Bucket' => 'Bucket',
    'Key'    => 'Key',
]);

echo $result['Body']; // foo

$dynamoDb = \AWS::createDynamoDb();

$result = $dynamoDb->listTables();

echo $result['TableNames'][0]; // Table1

统计信息

  • 总下载量: 683
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-02-21