5 Commits
4.2 ... 4.5

Author SHA1 Message Date
User
8fc94aaeb8 20250224#1 2025-02-24 19:45:12 +03:00
User
aba089db5e 20250218#1 2025-02-18 02:39:16 +03:00
User
43e529dcad 20250128#2 2025-01-28 14:21:33 +03:00
User
5bef4f577e 20250128#1 2025-01-28 13:23:44 +03:00
User
b53c3f9815 20250127#1 2025-01-27 03:09:37 +03:00
4 changed files with 32 additions and 20 deletions

View File

@@ -9,5 +9,5 @@ composer create-project rmphp/skeleton project-name
``` ```
```bash ```bash
composer create-project rmphp/skeleton:"^4.2" project-name composer create-project rmphp/skeleton:"^4.5" project-name
``` ```

View File

@@ -2,26 +2,40 @@
namespace Base\Application; namespace Base\Application;
use Exception;
use ReflectionClass; use ReflectionClass;
use Rmphp\Storage\Component\AbstractDataObject;
abstract class AbstractDTO extends AbstractDataObject {
/**
* @param array|object ...$data
* @return static
* @throws Exception
*/
public static function fromData(array|object ...$data) : static {
$array = array_map(function($item) {
return (is_object($item)) ? get_object_vars($item) : $item;
}, $data);
return self::fromArray(array_merge(...$array));
}
/**
* @param object $data
* @return static
* @throws Exception
*/
public static function fromObject(object $data) : static {
return self::fromArray(get_object_vars($data));
}
abstract class AbstractDTO {
/** /**
* @param array $data * @param array $data
* @return static * @return static
* @throws Exception
*/ */
static function fromArray(array $data) : static { public static function fromArray(array $data) : static {
$class = new ReflectionClass(static::class); return self::fillObject(new ReflectionClass(static::class), new static(), $data);
$self = new static();
foreach ($class->getProperties() as $property) {
$propertyNameSnakeCase = strtolower(preg_replace("'([A-Z])'", "_$1", $property->getName()));
// data[propertyName] ?? data[property_name] ?? null
$value = $data[$property->getName()] ?? $data[$propertyNameSnakeCase] ?? null;
// если есть внутренний метод (приоритетная обработка)
if($class->hasMethod('set'.ucfirst($property->getName()))) $self->{'set'.ucfirst($property->getName())}($value);
// прямое присовение по умолчанию
elseif(isset($value)) $self->{$property->getName()} = $value;
}
return $self;
} }
} }

View File

@@ -1,12 +1,10 @@
<?php <?php
use Rmphp\Cache\Cache;
use Rmphp\Cache\CacheInterface;
use Rmphp\Storage\Mysql\MysqlStorage; use Rmphp\Storage\Mysql\MysqlStorage;
use Rmphp\Storage\Mysql\MysqlStorageInterface; use Rmphp\Storage\Mysql\MysqlStorageInterface;
return [ return [
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)), MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
CacheInterface::class => DI\create(Cache::class)->constructor("../var/cache"), 'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'), 'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
]; ];

View File

@@ -15,9 +15,9 @@
"rmphp/content": "^3.1", "rmphp/content": "^3.1",
"rmphp/kernel": "^5.0", "rmphp/kernel": "^5.0",
"rmphp/router": "^1.2", "rmphp/router": "^1.2",
"rmphp/session": "^1.0", "rmphp/session": "^1.1",
"rmphp/redis": "^1.0", "rmphp/redis": "^1.0",
"rmphp/storage": "^4.0", "rmphp/storage": "^6.0",
"symfony/dotenv": "^6.2" "symfony/dotenv": "^6.2"
}, },
"autoload": { "autoload": {