From a5fc14fe0a6811c0368e90a43c747f26f4804895 Mon Sep 17 00:00:00 2001 From: Alexandre Batistella Bellas Date: Tue, 19 Dec 2023 19:40:48 -0300 Subject: [PATCH] feat: implementar base entity --- php/composer.json | 5 +++- php/src/Entities/@shared/BaseEntity.php | 33 +++++++++++++++++++++++++ php/src/Helpers/functions.php | 15 +++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 php/src/Helpers/functions.php diff --git a/php/composer.json b/php/composer.json index 7127c35..9c3b405 100644 --- a/php/composer.json +++ b/php/composer.json @@ -7,7 +7,10 @@ "psr-4": { "AleBatistella\\BlingErpApi\\": "src/", "AleBatistella\\BlingErpApi\\Entities\\Shared": "src/entities/@shared" - } + }, + "files": [ + "src/Helpers/functions.php" + ] }, "authors": [ { diff --git a/php/src/Entities/@shared/BaseEntity.php b/php/src/Entities/@shared/BaseEntity.php index 69ed1c5..46fdc28 100644 --- a/php/src/Entities/@shared/BaseEntity.php +++ b/php/src/Entities/@shared/BaseEntity.php @@ -2,6 +2,39 @@ namespace AleBatistella\BlingErpApi\Entities\Shared; +use AleBatistella\BlingErpApi\Repositories\IBlingRepository; + +/** + * Entidade base para o projeto. + */ abstract class BaseEntity { + /** + * Constrói o objeto. + * + * @param IBlingRepository $repository Repositório para conexão com o Bling. + */ + public function __construct(private IBlingRepository $repository) + { + } + + /** + * Prepara um parâmetro de data para chamada do repositório. + * + * @param \DateTimeInterface|string|null $param Parâmetro do tipo `string`, `\DateTimeInterface` ou `null` + * + * @return string|null + */ + protected function prepareStringOrDateParam(\DateTimeInterface|string|null $param): string|null + { + if (is_null($param)) { + return null; + } + + if (gettype($param) === 'string') { + return $param; + } + + return convertDateToString($param); + } } diff --git a/php/src/Helpers/functions.php b/php/src/Helpers/functions.php new file mode 100644 index 0000000..ee582e9 --- /dev/null +++ b/php/src/Helpers/functions.php @@ -0,0 +1,15 @@ +format('Y-m-d'); + } +}