ldc-com-app-bo/app/Lib/Inputs/Definition/InputInterface.php
2025-05-20 11:45:42 +02:00

98 lines
2.7 KiB
PHP

<?php
namespace App\Lib\Inputs\Definition;
use App\Enums\Formularies\InputTypeEnum;
use App\Models\Formulary;
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.
*/
public static function from(InputData $data, bool $required = true);
/**
* Parse DB line to Object
*
* ! Need to validate inputType
*
* @param string $title The line placeholder.
* @param string $formSlug The Form slug for this data.
* @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.
*/
public static function make(string $title, string $formSlug, $data, bool $required = true);
// * --- 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;
/**
* Get the matching formulary for this object
*
* @return \App\Models\Formulary|null
*/
public function getFormulary(): ?Formulary;
/**
* Get this input has a matching Formulary ?
*
* @return boolean
*/
public function hasFormulary(): bool;
/**
* 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.
* @return string|array<integer,string>
* @throws \Illuminate\Validation\ValidationException If the data is invalid.
*/
public static function validateData($data, bool $required);
}