Files
oficial/app/common/Implement/Repository/Factory.php
aldarien 61c813fc08 feature/cierres (#30)
Reservas agregar y aprobar

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #30
2025-09-11 15:16:12 -03:00

38 lines
880 B
PHP

<?php
namespace Incoviba\Common\Implement\Repository;
use Closure;
use Exception;
use Incoviba\Common\Define;
use Incoviba\Common\Implement\Exception\EmptyResult;
class Factory implements Define\Repository\Factory
{
public Closure $callable;
public array $args;
public function setCallable(callable $callable): Define\Repository\Factory
{
$this->callable = $callable(...);
return $this;
}
public function setArgs(array $args): Define\Repository\Factory
{
$this->args = $args;
return $this;
}
/**
* @return mixed
* @throws EmptyResult
*/
public function run(): mixed
{
try {
return call_user_func_array($this->callable, $this->args);
} catch (Exception $exception) {
throw new EmptyResult($exception->getMessage(), $exception);
}
}
}