Skip to content

Commit 4cd8abe

Browse files
author
Fredrick Peter
committed
generate method added
1 parent a878434 commit 4cd8abe

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* [Driver](#driver)
2727
* [Name](#name)
2828
* [BaseDir](#baseDir)
29+
* [Generate](#generate)
2930
* [Folder](#folder)
3031
* [Filter](#filter)
3132
* [Structure](#structure)
@@ -311,6 +312,14 @@ File::name('avatar')
311312
->baseDir('newBaseDirectory');
312313
```
313314

315+
### Generate
316+
- Takes one param `bool`
317+
318+
```
319+
File::name('avatar')
320+
->generate(false);
321+
```
322+
314323
### Folder
315324
- Takes one param `string` as `folder_path` to save file
316325
- Remember the system already have your `baseDirectory`

src/File.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,26 @@ public function baseDir($directory)
210210
return $this;
211211
}
212212

213+
/**
214+
* Allow generation of new name for uploaded files
215+
*
216+
* @param bool $allow
217+
* @return $this
218+
*/
219+
public function generate(?bool $allow = true)
220+
{
221+
$this->config['generate'] = $allow;
222+
223+
return $this;
224+
}
225+
213226
/**
214227
* Change driver type
215228
*
216-
* @param string|null $driver
229+
* @param string $driver
217230
* @return $this
218231
*/
219-
public function driver($driver = null)
232+
public function driver($driver)
220233
{
221234
// trim string
222235
$driver = Str::lower($driver);

src/Traits/FileTrait.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait FileTrait{
2424
public function globalConfig($message = [], $config = [], $class = [])
2525
{
2626
// define constant to hold global error handler
27-
if(!defined('')){
27+
if(!defined('TAME_FILE_CONFIG')){
2828

2929
// create message
3030
$message = $message + [
@@ -97,10 +97,8 @@ public function globalConfig($message = [], $config = [], $class = [])
9797
'class' => $class,
9898
];
9999

100-
if(!defined('TAME_FILE_CONFIG')){
101-
define('TAME_FILE_CONFIG', $default);
102-
}
103-
100+
// define global config
101+
define('TAME_FILE_CONFIG', $default);
104102
}
105103
}
106104

src/Traits/FileValidatorTrait.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ private function proceedToSave()
3636
// file data
3737
$fileItems = $this->fileItemsData();
3838

39+
// change the correct uploaded message
40+
$this->data["message"] = $this->translation('200');
41+
3942
// check if file item is true
4043
// and count is more than 0
4144
if(is_array($fileItems) && count($fileItems) > 0){
@@ -93,7 +96,7 @@ private function proceedToValidate()
9396
}
9497

9598
// begin file validation
96-
else{
99+
else {
97100

98101
$validationAttempt = true;
99102
foreach($this->fileItemsData() as $key => $file){
@@ -188,7 +191,7 @@ private function proceedToValidate()
188191
if($validationAttempt){
189192
$this->data = [
190193
"status" => 200,
191-
"message" => $this->translation('200'),
194+
"message" => "File validated successfully:",
192195
];
193196
$this->success = true;
194197
}
@@ -257,7 +260,7 @@ private function dataMerge()
257260

258261
// Merge config only when custom setting is not empty
259262
foreach ($this->config as $key => $value) {
260-
if (!empty($value)) {
263+
if (!empty($value) || is_bool($value)) {
261264
$config[$key] = $value;
262265
}
263266
}

0 commit comments

Comments
 (0)