Skip to content

Commit a87e67b

Browse files
tfbritosrtab
authored andcommitted
Fixed function
1 parent 217237d commit a87e67b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/Fields/FileField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function validate($value)
5757

5858
public function toNative($value)
5959
{
60-
if (is_null($value)) {
60+
if ($this->isEmpty($value)) {
6161
return $value;
6262
}
6363
return (object) $value;

src/Validators/FileTypeValidator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public function __construct(array $valid_filetypes, $message = null)
2424

2525
public function __invoke($value)
2626
{
27-
if (isset($value->size) &&
28-
$value->size > 0 && !is_null($this->valid_filetypes) && !in_array($value->type, $this->valid_filetypes)) {
27+
if ($value->size > 0 && !is_null($this->valid_filetypes) && !in_array($value->type, $this->valid_filetypes)) {
2928
$message = msg($this->message, array(
3029
"valid_types" => implode(", ", $this->valid_filetypes),
3130
"type" => $value->type

tests/unit/Fields/FileFieldTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public function testToNativeInvalidValue()
9494
$this->assertNull($result);
9595
}
9696

97+
public function testToNativeEmptyString()
98+
{
99+
$result = $this->field->toNative('');
100+
$this->assertEquals('', $result);
101+
}
102+
97103
/**
98104
* @expectedException PHPForm\Exceptions\ValidationError
99105
*/

0 commit comments

Comments
 (0)