Skip to content

Commit b0ee4e5

Browse files
committed
clean up
1 parent 2b76f0c commit b0ee4e5

File tree

3 files changed

+61
-23
lines changed

3 files changed

+61
-23
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ Upload files to AWS S3 Directly from Browser
77

88
## Installation
99

10-
You can install the package via composer:
10+
- 1 Install the package via composer:
1111

1212
```bash
1313
composer require hassan/laravel-s3-browser-based-uploads
1414
```
1515

16+
- 2 Publish the config file of the package.
17+
18+
```bash
19+
php artisan vendor:publish --provider="Hassan\S3BrowserBasedUploads\ServiceProvider" --tag=config
20+
```
21+
- 3 add your AWS settings
22+
23+
```bash
24+
AWS_ACCESS_KEY_ID=
25+
AWS_SECRET_ACCESS_KEY=
26+
AWS_DEFAULT_REGION=
27+
AWS_BUCKET=
28+
```
29+
1630
## Usage
1731

1832
``` php

src/S3BrowserBasedUploadsManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ public function __construct(
1919
parent::__construct($client, $bucket, $formInputs, $options, $expiration);
2020
}
2121

22+
/**
23+
* @return string
24+
*/
2225
public function getEndpointUrl() : string
2326
{
2427
return $this->getFormAttributes()['action'];
2528
}
2629

30+
/**
31+
* @return array
32+
*/
2733
public function getFields() : array
2834
{
2935
return $this->getFormInputs();

src/ServiceProvider.php

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,68 @@ public function boot()
1919
}
2020
}
2121

22+
/**
23+
* Register the application services.
24+
*/
25+
public function register()
26+
{
27+
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 's3-browser-based-uploads');
28+
29+
$this->app->bind(S3BrowserBasedUploadsManager::class, function () {
30+
$adapter = $this->getS3Adapter();
31+
32+
return new S3BrowserBasedUploadsManager(
33+
$adapter->getClient(),
34+
$adapter->getBucket(),
35+
$this->getInputs(),
36+
$this->getConditions(),
37+
$this->getExpirationTime()
38+
);
39+
});
40+
41+
$this->app->alias(S3BrowserBasedUploadsManager::class, 's3-browser-based-uploads');
42+
}
43+
44+
45+
/**
46+
* @return AwsS3Adapter
47+
*/
2248
protected function getS3Adapter() : AwsS3Adapter
2349
{
2450
return $this->app['filesystem']->disk($this->getConfig('disk'))->getAdapter();
2551
}
2652

53+
/**
54+
* returns inputs from config file
55+
*/
2756
protected function getInputs() : array
2857
{
2958
return $this->getConfig('inputs', []);
3059
}
3160

61+
/**
62+
* returns conditions from config file
63+
*/
3264
protected function getConditions() : array
3365
{
3466
return $this->getConfig('conditions', []);
3567
}
3668

69+
/**
70+
* returns expiration time from config file
71+
*/
3772
protected function getExpirationTime() : string
3873
{
3974
return $this->getConfig('expiration_time', '+5 minutes');
4075
}
4176

42-
public function getConfig(string $key, $default = null)
43-
{
44-
return config('s3-browser-based-uploads.providers.default.' . $key, $default);
45-
}
46-
4777
/**
48-
* Register the application services.
78+
* @param string $key
79+
* @param null $default
80+
* @return mixed
4981
*/
50-
public function register()
82+
protected function getConfig(string $key, $default = null)
5183
{
52-
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 's3-browser-based-uploads');
53-
54-
$this->app->bind(S3BrowserBasedUploadsManager::class, function () {
55-
$adapter = $this->getS3Adapter();
56-
57-
return new S3BrowserBasedUploadsManager(
58-
$adapter->getClient(),
59-
$adapter->getBucket(),
60-
$this->getInputs(),
61-
$this->getConditions(),
62-
$this->getExpirationTime()
63-
);
64-
});
65-
66-
$this->app->alias(S3BrowserBasedUploadsManager::class, 's3-browser-based-uploads');
84+
return config('s3-browser-based-uploads.providers.default.' . $key, $default);
6785
}
6886
}

0 commit comments

Comments
 (0)