Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
07a994df83 | |||
e09ea26a3c | |||
ebfd42a88e | |||
054e6a7cdc |
@@ -16,11 +16,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.4",
|
"php": "^8.4",
|
||||||
"ext-mbstring": "*"
|
"ext-mbstring": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": ">=11.5.6"
|
"phpunit/phpunit": "^12.0.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
532
composer.lock
generated
532
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -211,6 +211,15 @@ final class ClassMapper
|
|||||||
// -- тип свойства
|
// -- тип свойства
|
||||||
$propertyType = $property->getType();
|
$propertyType = $property->getType();
|
||||||
|
|
||||||
|
// - если значение является типом bool
|
||||||
|
if ($propertyType->getName() === 'bool') {
|
||||||
|
// -- присваиваю дату
|
||||||
|
self::SetParameterToClass($classReflector, $key, $classObj, $value == "1");
|
||||||
|
|
||||||
|
// -- следующий элемент
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// - если значение является классом
|
// - если значение является классом
|
||||||
if (!$propertyType->isBuiltin() && is_array($value)) {
|
if (!$propertyType->isBuiltin() && is_array($value)) {
|
||||||
// -- присваиваю объект
|
// -- присваиваю объект
|
||||||
@@ -300,7 +309,7 @@ final class ClassMapper
|
|||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
// Если значение null
|
// Если значение null
|
||||||
if ($value == null || $value == "null")
|
if (!is_bool($value) && ($value == null || $value == "null"))
|
||||||
// - то присваиваю значение по умолчанию
|
// - то присваиваю значение по умолчанию
|
||||||
$value = self::GetDefaults($property->getType()->getName());
|
$value = self::GetDefaults($property->getType()->getName());
|
||||||
|
|
||||||
@@ -314,18 +323,18 @@ final class ClassMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получает значение по умолчанию для разных типов данных.
|
* Возвращает значение по умолчанию для типа $typeName.
|
||||||
*
|
*
|
||||||
* @param string $typeName Имя типа данных.
|
* @param string $typeName Тип
|
||||||
*
|
*
|
||||||
* @return mixed|null Результат.
|
* @return mixed Значение по умолчанию
|
||||||
*/
|
*/
|
||||||
public static function GetDefaults (string $typeName): mixed
|
public static function GetDefaults (string $typeName): mixed
|
||||||
{
|
{
|
||||||
return match ($typeName) {
|
return match (strtolower($typeName)) {
|
||||||
'int' => 0,
|
'int', 'integer' => 0,
|
||||||
'float' => 0.0,
|
'float', 'double' => 0.0,
|
||||||
'bool' => false,
|
'bool', 'boolean' => false,
|
||||||
'string' => '',
|
'string' => '',
|
||||||
'array' => [],
|
'array' => [],
|
||||||
'object' => new stdClass(),
|
'object' => new stdClass(),
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
namespace goodboyalex\php_components_pack\tests\classes;
|
namespace goodboyalex\php_components_pack\tests\classes;
|
||||||
|
|
||||||
use goodboyalex\php_components_pack\classes\ClassMapper;
|
use goodboyalex\php_components_pack\classes\ClassMapper;
|
||||||
|
use goodboyalex\php_components_pack\tests\data\A;
|
||||||
|
use goodboyalex\php_components_pack\tests\data\B;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ClassMapperTest extends TestCase
|
class ClassMapperTest extends TestCase
|
||||||
@@ -11,12 +13,10 @@ class ClassMapperTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->PrepareForTest();
|
$this->PrepareForTest();
|
||||||
|
|
||||||
$a = new \goodboyalex\php_components_pack\tests\data\A();
|
$a = new A('a', 2, true);
|
||||||
$a->a = 'a';
|
|
||||||
$a->b = 2;
|
|
||||||
$a->c = true;
|
|
||||||
|
|
||||||
$b = new B();
|
$b = new B();
|
||||||
|
|
||||||
ClassMapper::MapClass($a, $b);
|
ClassMapper::MapClass($a, $b);
|
||||||
|
|
||||||
$this->assertEquals('a', $b->a);
|
$this->assertEquals('a', $b->a);
|
||||||
|
@@ -1,10 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace goodboyalex\php_components_pack\tests\classes;
|
namespace goodboyalex\php_components_pack\tests\data;
|
||||||
|
|
||||||
class B
|
class B
|
||||||
{
|
{
|
||||||
public string $a;
|
public string $a;
|
||||||
public int $b;
|
public int $b;
|
||||||
public string $d;
|
public string $d;
|
||||||
|
|
||||||
|
public function __construct (string $a = "", int $b = 0, string $d = "")
|
||||||
|
{
|
||||||
|
$this->a = $a;
|
||||||
|
$this->b = $b;
|
||||||
|
$this->d = $d;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user