-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
namespace Packaged\Form\DataHandlers; | ||
|
||
use Packaged\Glimpse\Tags\Form\Input; | ||
use Packaged\Ui\Html\HtmlElement; | ||
|
||
class FileDataHandler extends AbstractDataHandler | ||
{ | ||
public function getFileName() | ||
{ | ||
return $this->_value['name'] ?? null; | ||
} | ||
|
||
public function getFileType() | ||
{ | ||
return $this->_value['type'] ?? null; | ||
} | ||
|
||
public function getFileSize() | ||
{ | ||
return $this->_value['size'] ?? null; | ||
} | ||
|
||
/** | ||
* @link https://www.php.net/manual/en/features.file-upload.errors.php | ||
*/ | ||
public function getErrorCode() | ||
{ | ||
return $this->_value['error'] ?? null; | ||
} | ||
|
||
public function getFileLocation() | ||
{ | ||
return $this->_value['tmp_name'] ?? null; | ||
} | ||
|
||
public function hasUpload() | ||
{ | ||
return isset($this->_value['tmp_name']) && !empty($this->_value['tmp_name']); | ||
} | ||
|
||
protected function _createBaseElement(): HtmlElement | ||
{ | ||
return Input::create()->setType(Input::TYPE_FILE); | ||
} | ||
|
||
protected function _generateInput(): HtmlElement | ||
{ | ||
$ele = $this->_createBaseElement(); | ||
$ele->addAttributes( | ||
[ | ||
'name' => $this->getName(), | ||
'id' => $this->getId(), | ||
'placeholder' => $this->getPlaceholder(), | ||
] | ||
); | ||
return $ele; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters