2023-09-12
This commit is contained in:
9
app/common/Define/Money/Provider.php
Normal file
9
app/common/Define/Money/Provider.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define\Money;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
interface Provider
|
||||
{
|
||||
public function get(string $money_symbol, DateTimeInterface $dateTime): float;
|
||||
}
|
@ -17,7 +17,10 @@ abstract class Model implements Define\Model
|
||||
|
||||
protected function runFactory(string $property): mixed
|
||||
{
|
||||
return $this->factories[$property]->run();
|
||||
if (isset($this->factories[$property])) {
|
||||
return $this->factories[$property]->run();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
|
@ -112,14 +112,15 @@ abstract class Repository implements Define\Repository
|
||||
$values []= $data[$column];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($changes) === 0) {
|
||||
return $model;
|
||||
}
|
||||
$columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes));
|
||||
$query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?";
|
||||
$values []= $model->id;
|
||||
$values []= $model->{$this->getKey()};
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->fetchById($model->id);
|
||||
return $this->fetchById($model->{$this->getKey()});
|
||||
}
|
||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||
{
|
||||
|
15
app/common/Implement/Exception/EmptyResponse.php
Normal file
15
app/common/Implement/Exception/EmptyResponse.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Exception;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class EmptyResponse extends Exception
|
||||
{
|
||||
public function __construct(string $uri = "", ?Throwable $previous = null)
|
||||
{
|
||||
$message = "Empty Response from {$uri}";
|
||||
$code = 800;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
@ -5,11 +5,12 @@ use Incoviba\Common\Implement\Repository\Mapper;
|
||||
|
||||
class Boolean extends Mapper
|
||||
{
|
||||
public function __construct(string $column, ?string $property = null)
|
||||
public function __construct(string $column, ?string $property = null, bool $default = false)
|
||||
{
|
||||
$this->setFunction(function($data) use ($column) {
|
||||
return $data[$column] !== 0;
|
||||
});
|
||||
$this->setDefault($default);
|
||||
if ($property !== null) {
|
||||
$this->setProperty($property);
|
||||
}
|
||||
|
Reference in New Issue
Block a user