Skip to content

Commit 08beb7d

Browse files
author
Fredrick Peter
committed
Validator Package Included
1 parent 921357e commit 08beb7d

File tree

11 files changed

+73
-23
lines changed

11 files changed

+73
-23
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [Get Class](#get-class)
2020
* [First](#first)
2121
* [Get](#get)
22+
* [Form](#form)
2223
* [Usage](#usage)
2324
* [INPUT HTML STRUCTURE](#input-html-structure)
2425
* [Driver](#driver)
@@ -213,6 +214,17 @@ $upload->first();
213214
$upload->get();
214215
```
215216

217+
### Form
218+
- Return form request data
219+
- This will return `validator package` object [Validator](https://github.com/tamedevelopers/validator)
220+
221+
```
222+
->save(function($response){
223+
224+
$response->form();
225+
});
226+
```
227+
216228
## Usage
217229

218230
### INPUT HTML STRUCTURE

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
],
1717
"require": {
1818
"php": ">=8.0",
19-
"tamedevelopers/support": "^2.0.0"
19+
"tamedevelopers/support": "*",
20+
"tamedevelopers/validator": "*"
2021
},
2122
"suggest": {
2223
"aws/aws-sdk-php": "Required to use Amazon `s3` composer require aws/aws-sdk-php (^3.282.0)."

src/File.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Tamedevelopers\Support\Tame;
1010
use Tamedevelopers\File\ImageCompress;
1111
use Tamedevelopers\File\ImageWatermark;
12+
use Tamedevelopers\Validator\Validator;
1213
use Tamedevelopers\File\ImageAutoresize;
1314
use Tamedevelopers\File\Traits\FileTrait;
1415
use Tamedevelopers\File\Methods\FileMethod;
@@ -18,6 +19,16 @@
1819
use Tamedevelopers\File\Traits\FileValidatorTrait;
1920

2021

22+
/**
23+
* File
24+
*
25+
* @package tamedevelopers\file
26+
* @author Tame Developers <[email protected]>
27+
* @author Fredrick Peterson <[email protected]>
28+
* @copyright 2021-2023 Tame Developers
29+
* @license http://www.opensource.org/licenses/MIT The MIT License
30+
* @link https://github.com/tamedevelopers/file
31+
*/
2132
class File extends FileMethod{
2233

2334
use FilePropertyTrait,
@@ -67,16 +78,17 @@ static public function name($name = null)
6778
*/
6879
public function validate(callable $function = null)
6980
{
81+
$this->proceedToValidate();
82+
7083
if(!$this->success){
71-
$this->proceedToValidate()
72-
->callback($function);
84+
$this->callback($function);
7385
}
7486

7587
return $this;
7688
}
7789

7890
/**
79-
* Begin Upload Validation
91+
* Begin Upload Confirmation
8092
*
8193
* @param callable $function
8294
* @return $this
@@ -396,6 +408,30 @@ public function get()
396408
return self::getUploads($this->uploads);
397409
}
398410

411+
/**
412+
* Return validator form request
413+
*
414+
* @return Tamedevelopers\Validator\Validator
415+
*/
416+
public function form()
417+
{
418+
return (new Validator)
419+
->token(false)
420+
->all();
421+
}
422+
423+
/**
424+
* Echo `json_encode` with response and message
425+
*
426+
* @param int $response
427+
* @param mixed $message
428+
* @return mixed
429+
*/
430+
public function echoJson(int $response = 0, $message = null)
431+
{
432+
return Tame::echoJson($response, $message);
433+
}
434+
399435
/**
400436
* Destructor for Removing Cloud Save Files
401437
* We automatically store a copy of uploaded files to local server

src/Traits/FileTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function setDirectory($path = null)
4949
public function globalConfig($message = [], $config = [], $class = [])
5050
{
5151
// define constant to hold global error handler
52-
if(!defined('TAME_FILE_ERROR')){
52+
if(!defined('')){
5353

5454
// create message
5555
$message = $message + [
@@ -114,7 +114,7 @@ public function globalConfig($message = [], $config = [], $class = [])
114114
'class' => $class,
115115
];
116116

117-
define('TAME_FILE_ERROR', $default);
117+
define('TAME_FILE_CONFIG', $default);
118118
}
119119
}
120120

src/Traits/FileValidatorTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ private function callback(callable $function = null)
218218
*/
219219
private function translation($mode = null)
220220
{
221-
return defined('TAME_FILE_ERROR')
222-
? TAME_FILE_ERROR['message'][$mode] ?? TAME_FILE_ERROR['message']
221+
return defined('TAME_FILE_CONFIG')
222+
? TAME_FILE_CONFIG['message'][$mode] ?? TAME_FILE_CONFIG['message']
223223
: null;
224224
}
225225

@@ -231,7 +231,7 @@ private function translation($mode = null)
231231
private function callConfigIfNotCalled()
232232
{
233233
// define constant to hold global error handler
234-
if(!defined('TAME_FILE_ERROR')){
234+
if(!defined('TAME_FILE_CONFIG')){
235235
$this->globalConfig();
236236

237237
// merge with default data
@@ -241,7 +241,7 @@ private function callConfigIfNotCalled()
241241
$this->config = $this->dataMerge();
242242

243243
// class
244-
$this->class = TAME_FILE_ERROR['class'];
244+
$this->class = TAME_FILE_CONFIG['class'];
245245
}
246246
}
247247

@@ -252,8 +252,8 @@ private function callConfigIfNotCalled()
252252
*/
253253
private function dataMerge()
254254
{
255-
// default data from `TAME_FILE_ERROR`
256-
$config = array_merge($this->config, TAME_FILE_ERROR['config']);
255+
// default data from `TAME_FILE_CONFIG`
256+
$config = array_merge($this->config, TAME_FILE_CONFIG['config']);
257257

258258
// Merge config only when custom setting is not empty
259259
foreach ($this->config as $key => $value) {
File renamed without changes.
File renamed without changes.

test/index1.php renamed to tests/index1.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ class: [
2222
);
2323

2424
// easy as this
25-
// File::name('avatar')->save();
25+
// File::name('banners')->save();
2626

2727

2828
// or helper function
29-
// TameFile('avatar')->save();
29+
// TameFile('banners')->save();
3030

3131

3232
// [optional] closure/callable function,
3333
// When using `save()` and `validate()` method.
34-
$upload = File::name('banners')
34+
$upload = File::name('avatar')
3535
->size('500kb')
3636
->save(function($response){
3737

38+
39+
dd(
40+
$response->form()
41+
);
42+
3843
$response
3944
->watermark('test/watermark.png', 'center')
4045
->resize(690, 540)
@@ -98,17 +103,13 @@ class: [
98103
</div>
99104
</div>
100105

101-
<!--file upload-->
102-
<div class="col-sm-12 mt-3">
103-
<div class="form-group">
104-
<label for="upload2">Banners</label>
105-
<input type="file" class="form-control-file" id="upload2"
106-
name="banners[]" multiple>
107-
</div>
106+
<div>
107+
<label for="html">Age</label>
108+
<input type="text" name="age" value="<?= old('age'); ?>">
108109
</div>
109110

110111
<button type="submit" style="margin-top: 40px;">
111-
Upload File
112+
Submit Data
112113
</button>
113114

114115
</form>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)