Download the PHP package diecoding/yii2-aws-s3 without Composer
On this page you can find all versions of the php package diecoding/yii2-aws-s3. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-aws-s3
Yii2 AWS S3
Amazon S3 or Amazon Simple Storage Service component for Yii2.
Yii2 AWS S3 uses SemVer.
Table of Contents
- Yii2 AWS S3
- Table of Contents
- Instalation
- Dependencies
- Configuration
- Usage
- Basic Usage
- Advanced Usage
- Custom Commands
- Using Traits
- Model Trait
- Using Trait Methods
- Overriding Trait Methods
- getS3Component
- attributePaths
- getPresignedUrlDuration
- isSuccessResponseStatus
Instalation
Package is available on Packagist, you can install it using Composer.
or add to the require section of your composer.json
file.
Dependencies
- PHP 7.4+
- yiisoft/yii2
- aws/aws-sdk-php
Configuration
- Add the component to
config/main.php
Usage
Basic Usage
Advanced Usage
Custom Commands
Commands have two types: plain commands that's handled by the PlainCommandHandler
and commands with their own handlers.
The plain commands wrap the native AWS S3 commands.
The plain commands must implement the PlainCommand
interface and the rest must implement the Command
interface.
If the command doesn't implement the PlainCommand
interface, it must have its own handler.
Every handler must extend the Handler
class or implement the Handler
interface.
Handlers gets the S3Client
instance into its constructor.
The implementation of the HasBucket
and HasAcl
interfaces allows the command builder to set the values
of bucket and acl by default.
To make the plain commands asynchronously, you have to implement the Asynchronous
interface.
Also, you can use the Async
trait to implement this interface.
Consider the following command:
The handler for this command looks like this:
And usage this command:
Custom plain command looks like this:
Any command can extend the ExecutableCommand
class or implement the Executable
interface that will
allow to execute this command immediately: $command->withSomething('some value')->execute();
.
Using Traits
Model Trait
Attach the Trait to the Model/ActiveRecord
with some media attribute that will be saved in S3:
Override the attributePaths()
method to change the base path where the files will be saved on AWS S3.
- You can map a different path to each file attribute of your
Model/ActiveRecord
.
Using Trait Methods
Overriding Trait Methods
getS3Component
The S3MediaTrait depends on this component to be configured. The default configuration is to use this component on index 's3'
, but you may use another value. For this cases, override the getS3Component()
method:
attributePaths
The main method to override is attributePaths()
, which defines a path in S3 for each attribute of yout model. Allowing you to save each attribute in a different S3 folder.
Here an example:
getPresignedUrlDuration
The default pressigned URL duration is set to "+5 Minutes", override this method and use your own expiration.
The value should be a valid PHP datetime operation. Read PHP documentation for details
isSuccessResponseStatus
The isSuccessResponseStatus()
method validate the AWS response for status codes is 2**. If needed, you can override this validation:
Read more docs: https://sugengsulistiyawan.my.id/docs/opensource/yii2/aws-s3/