2023-08-28 19:08:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Lib\Inputs\Definition;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Formularies\InputTypeEnum;
|
2023-08-31 12:48:31 +02:00
|
|
|
use App\Models\Formulary;
|
2023-08-28 19:08:23 +02:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
use Illuminate\Contracts\Support\Jsonable;
|
|
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package App\Lib\Inputs
|
|
|
|
|
*/
|
|
|
|
|
interface InputInterface extends Jsonable, Arrayable, \JsonSerializable
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Lib\Inputs\Definition\InputData $data
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(InputData $data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse DB line to Object
|
|
|
|
|
*
|
|
|
|
|
* ! Need to validate inputType
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Lib\Inputs\Definition\InputData $data
|
|
|
|
|
* @param boolean $required
|
|
|
|
|
* @return static
|
|
|
|
|
* @throws \RuntimeException If the input type is not recognized, or data is invalid.
|
|
|
|
|
*/
|
2025-05-20 16:20:23 +02:00
|
|
|
public static function from(InputData $data, bool $required = true): static;
|
2023-08-28 19:08:23 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse DB line to Object
|
|
|
|
|
*
|
|
|
|
|
* ! Need to validate inputType
|
|
|
|
|
*
|
|
|
|
|
* @param string $title The line placeholder.
|
2023-08-31 12:48:31 +02:00
|
|
|
* @param string $formSlug The Form slug for this data.
|
2023-08-28 19:08:23 +02:00
|
|
|
* @param string|array $data The line with data.
|
|
|
|
|
* @param boolean $required The line is required.
|
|
|
|
|
* @return static
|
|
|
|
|
* @throws \RuntimeException If the input type is not recognized, or data is invalid.
|
|
|
|
|
*/
|
2025-05-20 16:20:23 +02:00
|
|
|
public static function make(string $title, string $formSlug, $data, bool $required = true): static;
|
2023-08-28 19:08:23 +02:00
|
|
|
|
|
|
|
|
// * --- CHILDS Should implement ---
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this input required ?
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function isRequired(): bool;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the matching enum for this object
|
|
|
|
|
*
|
|
|
|
|
* @return \App\Enums\Formularies\InputTypeEnum
|
|
|
|
|
*/
|
|
|
|
|
public static function getType(): InputTypeEnum;
|
|
|
|
|
|
2023-08-31 12:48:31 +02:00
|
|
|
/**
|
|
|
|
|
* Get the matching formulary for this object
|
|
|
|
|
*
|
2025-05-20 10:16:12 +02:00
|
|
|
* @return \App\Models\Formulary|null
|
2023-08-31 12:48:31 +02:00
|
|
|
*/
|
|
|
|
|
public function getFormulary(): ?Formulary;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get this input has a matching Formulary ?
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function hasFormulary(): bool;
|
|
|
|
|
|
2023-08-28 19:08:23 +02:00
|
|
|
/**
|
|
|
|
|
* Get the validator this input
|
|
|
|
|
*
|
|
|
|
|
* @param string|array $data The line with data.
|
|
|
|
|
* @param boolean $required The line is required.
|
|
|
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
|
|
|
*/
|
|
|
|
|
public static function getValidator($data, bool $required): Validator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validate data using getValidator instance
|
|
|
|
|
*
|
|
|
|
|
* @param string|array $data The line with data.
|
|
|
|
|
* @param boolean $required The line is required.
|
2025-05-20 16:20:23 +02:00
|
|
|
* @return void
|
2023-08-28 19:08:23 +02:00
|
|
|
* @throws \Illuminate\Validation\ValidationException If the data is invalid.
|
|
|
|
|
*/
|
2025-05-20 16:20:23 +02:00
|
|
|
public static function validateData($data, bool $required): void;
|
2023-08-28 19:08:23 +02:00
|
|
|
}
|