feature/cierres (#25)
Varios cambios Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #25
This commit is contained in:
18
app/common/Ideal/LoggerEnabled.php
Normal file
18
app/common/Ideal/LoggerEnabled.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class LoggerEnabled implements LoggerAwareInterface
|
||||
{
|
||||
public LoggerInterface $logger;
|
||||
public function setLogger(LoggerInterface $logger): void
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function getLogger(): LoggerInterface
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
}
|
@ -24,6 +24,11 @@ abstract class Repository implements Define\Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConnection(): Define\Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
public function load(array $data_row): Define\Model
|
||||
{
|
||||
$model = $this->create($data_row);
|
||||
@ -189,7 +194,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$this->connection->execute($query, $values);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $this->fetchById($this->getIndex($model));
|
||||
}
|
||||
@ -205,10 +210,10 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new EmptyResult($query);
|
||||
throw new EmptyResult($query, null, $data);
|
||||
}
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $this->load($result);
|
||||
}
|
||||
@ -224,7 +229,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return array_map([$this, 'load'], $results);
|
||||
}
|
||||
@ -240,7 +245,7 @@ abstract class Repository implements Define\Repository
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
throw new EmptyResult($query, $exception, $data);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
56
app/common/Ideal/Service/API.php
Normal file
56
app/common/Ideal/Service/API.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
|
||||
abstract class API extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $order
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getAll(null|string|array $order = null): array;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Read
|
||||
*/
|
||||
abstract public function get(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Create
|
||||
*/
|
||||
abstract public function add(array $data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
abstract public function edit(Define\Model $model, array $new_data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Delete
|
||||
*/
|
||||
abstract public function delete(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return Define\Model
|
||||
*/
|
||||
abstract protected function process(Define\Model $model): Define\Model;
|
||||
}
|
10
app/common/Ideal/Service/Repository.php
Normal file
10
app/common/Ideal/Service/Repository.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Service;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
abstract class Repository extends Ideal\Service
|
||||
{
|
||||
abstract public function getRepository(): Define\Repository;
|
||||
}
|
Reference in New Issue
Block a user