2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\API;
|
|
|
|
|
|
|
|
use App\Rules\ImageData;
|
|
|
|
|
|
|
|
abstract class AbstractMediaImageUpdateRequest extends Request
|
|
|
|
{
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
|
|
|
return auth()->user()->is_admin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
2020-09-06 21:20:42 +00:00
|
|
|
$this->getImageFieldName() => ['string', 'required', new ImageData()],
|
2020-04-26 19:09:43 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileContentAsBinaryString(): string
|
|
|
|
{
|
|
|
|
[$_, $data] = explode(',', $this->{$this->getImageFieldName()});
|
|
|
|
|
|
|
|
return base64_decode($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileExtension(): string
|
|
|
|
{
|
|
|
|
[$type, $data] = explode(';', $this->{$this->getImageFieldName()});
|
|
|
|
[$_, $extension] = explode('/', $type);
|
|
|
|
|
|
|
|
return $extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function getImageFieldName(): string;
|
|
|
|
}
|