Fix the error with S3Client being null

This commit is contained in:
Phan An 2018-08-29 17:18:42 +07:00
parent 9222af21e8
commit 8638c229a8
2 changed files with 8 additions and 2 deletions

View file

@ -11,7 +11,13 @@ class ObjectStorageServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(S3ClientInterface::class, static function (): AwsClientInterface {
$this->app->bind(S3ClientInterface::class, static function (): ?AwsClientInterface {
// If these two values are not configured in .env, AWS will attempt initializing
// the client with null values and throw an error.
if (!config('aws.credentials.key') || !config('aws.credentials.secret')) {
return null;
}
return AWS::createClient('s3');
});
}

View file

@ -11,7 +11,7 @@ class S3Service implements ObjectStorageInterface
private $s3Client;
private $cache;
public function __construct(S3ClientInterface $s3Client, Cache $cache)
public function __construct(?S3ClientInterface $s3Client, Cache $cache)
{
$this->s3Client = $s3Client;
$this->cache = $cache;