mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-30 09:54:16 +00:00
new: Add classes required to upload identity document during account registration. #5
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\Modules\Documents\Services\ConvertsBase64ToFile;
|
||||
|
||||
class DocumentObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $document_type;
|
||||
|
||||
/** @var array */
|
||||
private $files;
|
||||
|
||||
/** @var string */
|
||||
private $reference;
|
||||
|
||||
/** @var int */
|
||||
private $status;
|
||||
|
||||
/** @var string|null */
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* DocumentObject constructor.
|
||||
* @param string $document_type
|
||||
* @param array $files
|
||||
* @param string $reference
|
||||
* @param int $status
|
||||
* @param null|string $path
|
||||
*/
|
||||
public function __construct(string $document_type, array $files, string $reference, int $status, ?string $path = '')
|
||||
{
|
||||
$this->document_type = $document_type;
|
||||
$this->files = $files;
|
||||
$this->reference = $reference;
|
||||
$this->status = $status;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDocumentType(): string
|
||||
{
|
||||
return $this->document_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReference(): string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function getFiles(): array
|
||||
{
|
||||
return (new ConvertsBase64ToFile($this->path))->convert($this->files);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\DataTransferObjects;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\ValueObjects\Constants\FileType;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManager;
|
||||
|
||||
class FileObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* FileInfoObject constructor.
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct(string $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Intervention\Image\Image|string
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->getExtension() === 'pdf' ? $this->data : (new imageManager())->make($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName(): string
|
||||
{
|
||||
return (string) Str::uuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return finfo_file(finfo_open(), $this->data, FILEINFO_MIME_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function getExtension(): string
|
||||
{
|
||||
if(array_key_exists($this->getMimeType(), FileType::EXTENSION)){
|
||||
return FileType::EXTENSION[$this->getMimeType()];
|
||||
}
|
||||
|
||||
throw new MalformedRequestException('Failed to save file due to Unknown file extension');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function getDecodedData(): string
|
||||
{
|
||||
return $this->getExtension() === 'pdf' ?
|
||||
base64_decode((explode('base64,', $this->getData()))[1]):
|
||||
$this->getData()->encode('data-url')->encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*/
|
||||
public function setData(string $data): void
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user