3 Commits
10.1 ... 11.0.1

Author SHA1 Message Date
User
35026bb223 20250530#1 2025-05-30 11:26:18 +03:00
User
e2727c34e8 20250510#1 2025-05-10 14:20:24 +03:00
User
e16700fe8d 20250509#1 2025-05-09 23:00:16 +03:00
6 changed files with 18 additions and 20 deletions

View File

@@ -10,12 +10,12 @@ Stable version
composer require rmphp/storage composer require rmphp/storage
``` ```
```bash ```bash
composer require rmphp/storage:"^10.0" composer require rmphp/storage:"^11.0"
``` ```
Dev version contains the latest changes Dev version contains the latest changes
```bash ```bash
composer require rmphp/storage:"10.x-dev" composer require rmphp/storage:"11.x-dev"
``` ```

View File

@@ -25,7 +25,7 @@ abstract class AbstractMysqlRepository extends AbstractRepository implements Mys
/** @inheritDoc */ /** @inheritDoc */
public function createFromResult(string $class, bool|MysqlResultData $result, callable $function = null): mixed { public function createFromResult(string $class, ?MysqlResultData $result, callable $function = null): mixed {
if($result instanceof MysqlResultData) { if($result instanceof MysqlResultData) {
$val = (isset($function)) ? $function($result->fetchOne()) : $result->fetchOne(); $val = (isset($function)) ? $function($result->fetchOne()) : $result->fetchOne();
$out = $this->createFromData($class, $val); $out = $this->createFromData($class, $val);
@@ -35,7 +35,7 @@ abstract class AbstractMysqlRepository extends AbstractRepository implements Mys
/** @inheritDoc */ /** @inheritDoc */
public function createListFromResult(string $class, bool|MysqlResultData $result, callable $function = null): array { public function createListFromResult(string $class, ?MysqlResultData $result, callable $function = null): array {
if($result instanceof MysqlResultData) { if($result instanceof MysqlResultData) {
foreach($result->fetch() as $resultValue) { foreach($result->fetch() as $resultValue) {
$val = (isset($function)) ? $function($resultValue) : $resultValue; $val = (isset($function)) ? $function($resultValue) : $resultValue;

View File

@@ -59,7 +59,7 @@ abstract class AbstractDataObject {
// Если тип свойства класс (valueObject) // Если тип свойства класс (valueObject)
elseif($property->hasType() && class_exists($property->getType()->getName())) { elseif($property->hasType() && class_exists($property->getType()->getName())) {
// значение объект // значение объект
if(is_object($value[$property->getName()])){ if(isset($value[$property->getName()]) && is_object($value[$property->getName()])){
$object->{$property->getName()} = $value[$property->getName()]; $object->{$property->getName()} = $value[$property->getName()];
$case[$property->getName()] = 'VO: Object'; $case[$property->getName()] = 'VO: Object';
} }

View File

@@ -16,21 +16,19 @@ interface MysqlRepositoryInterface extends RepositoryInterface {
/** /**
* @param string $class * @param string $class
* @param bool|MysqlResultData $result * @param MysqlResultData|null $result
* @param callable|null $function * @param callable|null $function
* @return mixed * @return mixed
* @throws RepositoryException
*/ */
public function createFromResult(string $class, bool|MysqlResultData $result, callable $function = null): mixed; public function createFromResult(string $class, ?MysqlResultData $result, callable $function = null): mixed;
/** /**
* @param string $class * @param string $class
* @param bool|MysqlResultData $result * @param MysqlResultData|null $result
* @param callable|null $function * @param callable|null $function
* @return array * @return array
* @throws RepositoryException
*/ */
public function createListFromResult(string $class, bool|MysqlResultData $result, callable $function = null): array; public function createListFromResult(string $class, ?MysqlResultData $result, callable $function = null): array;
/** /**
* @param int $id * @param int $id

View File

@@ -115,7 +115,7 @@ class MysqlStorage implements MysqlStorageInterface {
/** @inheritDoc */ /** @inheritDoc */
public function find(string $sql, int $ln=0, int $numPage=1, int $count=0): bool|MysqlResultData { public function find(string $sql, int $ln=0, int $numPage=1, int $count=0): ?MysqlResultData {
if ($ln > 1) { if ($ln > 1) {
$cnts = (!empty($count)) ? $count : $this->query($sql)->num_rows; $cnts = (!empty($count)) ? $count : $this->query($sql)->num_rows;
@@ -128,7 +128,7 @@ class MysqlStorage implements MysqlStorageInterface {
} }
$result = $this->query($sql.$limit); $result = $this->query($sql.$limit);
if (!$result || $result->num_rows == 0) return false; if (!$result || $result->num_rows == 0) return null;
$data = new MysqlResultData($result); $data = new MysqlResultData($result);
$data->count = $cnts ?? 0; $data->count = $cnts ?? 0;
@@ -137,17 +137,17 @@ class MysqlStorage implements MysqlStorageInterface {
} }
/** @inheritDoc */ /** @inheritDoc */
public function findOne(string $sql) : bool|MysqlResultData { public function findOne(string $sql) : ?MysqlResultData {
$result = $this->query($sql." limit 0, 1"); $result = $this->query($sql." limit 0, 1");
if (!$result || $result->num_rows == 0) return false; if (!$result || $result->num_rows == 0) return null;
return new MysqlResultData($result); return new MysqlResultData($result);
} }
/** @inheritDoc */ /** @inheritDoc */
public function findById(string $table, mixed $id, string $name = 'id') : bool|array { public function findById(string $table, mixed $id, string $name = 'id') : ?array {
$id = (is_numeric($id)) ? (int) $id : $this->escapeStr($id); $id = (is_numeric($id)) ? (int) $id : $this->escapeStr($id);
$result = $this->query("select * from ".$this->escapeStr($table)." where `$name`='$id' limit 0, 1"); $result = $this->query("select * from ".$this->escapeStr($table)." where `$name`='$id' limit 0, 1");
if (!$result || $result->num_rows == 0) return false; if (!$result || $result->num_rows == 0) return null;
$data = new MysqlResultData($result); $data = new MysqlResultData($result);
return $data->fetchOne(); return $data->fetchOne();
} }

View File

@@ -82,13 +82,13 @@ interface MysqlStorageInterface {
* @param int $count * @param int $count
* @return bool|MysqlResultData * @return bool|MysqlResultData
*/ */
public function find(string $sql, int $ln = 0, int $numPage = 1, int $count=0) : bool|MysqlResultData; public function find(string $sql, int $ln = 0, int $numPage = 1, int $count=0) : ?MysqlResultData;
/** /**
* @param string $sql * @param string $sql
* @return bool|array * @return bool|array
*/ */
public function findOne(string $sql) : bool|MysqlResultData; public function findOne(string $sql) : ?MysqlResultData;
/** /**
* @param string $table * @param string $table
@@ -96,7 +96,7 @@ interface MysqlStorageInterface {
* @param string $name * @param string $name
* @return bool|array * @return bool|array
*/ */
public function findById(string $table, mixed $id, string $name = 'id') : bool|array; public function findById(string $table, mixed $id, string $name = 'id') : ?array;
/** /**
* Метод экранирования данных с учетом текущего подключения в т.ч для LIKE * Метод экранирования данных с учетом текущего подключения в т.ч для LIKE