9 Commits
4.2 ... 4.7

Author SHA1 Message Date
User
fee7f1466c 20250303#1 2025-03-03 00:41:34 +03:00
User
a05a8c8dd1 20250302#1 2025-03-02 23:46:57 +03:00
User
133371a908 20250228#2 2025-02-28 13:39:44 +03:00
User
49ae47e43e 20250228#1 2025-02-28 13:11:14 +03:00
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
11 changed files with 167 additions and 23 deletions

View File

@@ -11,6 +11,7 @@
# PROD / DEV
APP_MODE=DEV
APP_NODES_FILE=application/config/app.php
CLI_NODES_FILE=application/config/app-cli.php
APP_COMPONENTS_FILE=application/config/components.php
CONTAINER_INI=application/config/container.php
CONTAINER_CACHE=var/cache/container

View File

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

View File

@@ -2,26 +2,40 @@
namespace Base\Application;
use Exception;
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
* @return static
* @throws Exception
*/
static function fromArray(array $data) : static {
$class = new ReflectionClass(static::class);
$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;
public static function fromArray(array $data) : static {
return self::fillObject(new ReflectionClass(static::class), new static(), $data);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Base\Controllers;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\Response\TextResponse;
use Psr\Http\Message\ResponseInterface;
use Rmphp\Kernel\Main;
use Throwable;
abstract class AbstractHandler extends Main {
/**
* @param Throwable $throwable
* @param array $data
* @return void
*/
public function logException(Throwable $throwable, array $data = []) : void {
$this->logger()->warning($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
}
/**
* @param Throwable $throwable
* @param array $data
* @return void
*/
public function logError(Throwable $throwable, array $data = []) : void {
$this->logger()->error($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine(), $data);
}
/**
* @param string $name
* @param string $value
* @return void
*/
public function addHeader(string $name, string $value) : void {
$this->globals()->addHeader($name, $value);
}
/**
* @param $html
* @param int $status
* @param array $headers
* @return ResponseInterface
*/
public function htmlResponse($html, int $status = 200, array $headers = []) : ResponseInterface {
return new HtmlResponse($html, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
}
/**
* @param $text
* @param int $status
* @param array $headers
* @return ResponseInterface
*/
public function textResponse($text, int $status = 200, array $headers = []) : ResponseInterface {
return new TextResponse($text, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
}
/**
* @param array $array
* @param int $status
* @param array $headers
* @return ResponseInterface
*/
public function jsonResponse(array $array, int $status = 200, array $headers = []) : ResponseInterface {
return new JsonResponse($array, $status, array_merge($this->globals()->response()->getHeaders(), $headers), JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}
}

3
application/bin/cli Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/php
<?php
require_once dirname(__FILE__).'/console.php';

3
application/bin/console Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/php
<?php
require_once dirname(__FILE__).'/console.php';

View File

@@ -0,0 +1,13 @@
<?php
use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory;
use Rmphp\Kernel\AppCli;
use Rmphp\Kernel\ResponseEmitter;
require_once dirname(__DIR__,2).'/vendor/autoload.php';
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__,2).'/.env');
$app = new AppCli();
$response = $app->handler(ServerRequestFactory::fromGlobals(), new Response());
(new ResponseEmitter())->emit($response);

View File

@@ -0,0 +1,19 @@
<?php
# Example:
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
# ['key'=>'', 'router'=>'application/config/routes-cli/routes.php'],
# ['key'=>'/', 'router'=>[]],
return [
['key'=>'', 'router'=>[
[
'key'=>'index',
'routes' => [
[
'action' => "App\Infrastructure\Handlers\IndexHandler",
'method' => "index"
]
]
]
]],
];

View File

@@ -1,12 +1,10 @@
<?php
use Rmphp\Cache\Cache;
use Rmphp\Cache\CacheInterface;
use Rmphp\Storage\Mysql\MysqlStorage;
use Rmphp\Storage\Mysql\MysqlStorageInterface;
return [
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'),
];

View File

@@ -12,12 +12,12 @@
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
"ramsey/uuid": "^4.7",
"rmphp/content": "^3.1",
"rmphp/kernel": "^5.0",
"rmphp/router": "^1.2",
"rmphp/session": "^1.0",
"rmphp/content": "^4.0",
"rmphp/kernel": "^6.0",
"rmphp/router": "^2.0",
"rmphp/session": "^1.1",
"rmphp/redis": "^1.0",
"rmphp/storage": "^4.0",
"rmphp/storage": "^6.0",
"symfony/dotenv": "^6.2"
},
"autoload": {

View File

@@ -0,0 +1,22 @@
<?php
/**
* Created by PhpStorm.
* User: Zuev Yuri
* Date: 02.03.2025
* Time: 22:02
*/
namespace App\Infrastructure\Handlers;
use Base\Controllers\AbstractHandler;
use Psr\Http\Message\ResponseInterface;
class IndexHandler extends AbstractHandler {
public function index() : bool|ResponseInterface {
return $this->textResponse((new \DateTime())->format('Y-m-d H:i:s'));
}
}