Skip to content

Commit

Permalink
feat: implementar base entity
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Dec 19, 2023
1 parent ecfa58a commit a5fc14f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 4 additions & 1 deletion php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"psr-4": {
"AleBatistella\\BlingErpApi\\": "src/",
"AleBatistella\\BlingErpApi\\Entities\\Shared": "src/entities/@shared"
}
},
"files": [
"src/Helpers/functions.php"
]
},
"authors": [
{
Expand Down
33 changes: 33 additions & 0 deletions php/src/Entities/@shared/BaseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 15 additions & 0 deletions php/src/Helpers/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

if (!function_exists('convertDateToString')) {
/**
* Converte uma data para o formato YYYY-MM-DD.
*
* @param \DateTimeInterface $date
*
* @return string
*/
function convertDateToString(\DateTimeInterface $date): string
{
return $date->format('Y-m-d');
}
}

0 comments on commit a5fc14f

Please sign in to comment.