Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddb82ee395 | ||
|
|
a095b76e8d | ||
|
|
70810412f4 | ||
|
|
fee7f1466c | ||
|
|
a05a8c8dd1 | ||
|
|
133371a908 | ||
|
|
49ae47e43e | ||
|
|
8fc94aaeb8 | ||
|
|
aba089db5e | ||
|
|
43e529dcad | ||
|
|
5bef4f577e | ||
|
|
b53c3f9815 | ||
|
|
11b1544317 | ||
|
|
9e4ae35455 | ||
|
|
23133c173c | ||
|
|
bf529d83c8 | ||
|
|
794e82f7ce | ||
|
|
035f88ea72 | ||
|
|
1b0af12a46 | ||
|
|
99f78f7362 | ||
|
|
72d2445bb2 | ||
|
|
40e771f1f2 | ||
|
|
858dfd17c0 | ||
|
|
c3e7bc6fc7 | ||
|
|
3ebbe07db6 | ||
|
|
e865eca689 | ||
|
|
e83753471c | ||
|
|
6c571aa358 | ||
|
|
8b92eecba1 | ||
|
|
e03c9bccfc | ||
|
|
88b597d78d | ||
|
|
de10cbae31 | ||
|
|
98c2d37870 | ||
|
|
1258828b2d | ||
|
|
8ef1287567 | ||
|
|
009832a046 | ||
|
|
4ad36c6034 | ||
|
|
8346234859 | ||
|
|
cb5408be4a | ||
|
|
041ee17263 | ||
|
|
15ec4a46bc | ||
|
|
da2bab7338 | ||
|
|
5b8ef84efa | ||
|
|
9abb4d4d6b | ||
|
|
171def66b8 | ||
|
|
f6b47693a4 | ||
|
|
36861b6967 | ||
|
|
44250475c1 | ||
|
|
a35a50eb53 | ||
|
|
c2d2ad9177 |
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
15
.env.dist
15
.env.dist
@@ -8,15 +8,18 @@
|
||||
#
|
||||
# Real environment variables win over .env files.
|
||||
|
||||
# PROD / DEV
|
||||
APP_MODE=DEV
|
||||
APP_COMPONENTS_FILE=config/app.php
|
||||
APP_NODES_FILE=config/nodes.php
|
||||
CONTAINER_DIR=config/container
|
||||
APP_NODES_FILE=config/app.php
|
||||
CLI_NODES_FILE=config/app-cli.php
|
||||
APP_COMPONENTS_FILE=config/components.php
|
||||
CONTAINER_INI=config/container.php
|
||||
CONTAINER_CACHE=var/cache/container
|
||||
|
||||
# Default page
|
||||
PAGE404=templates/error/404.tpl
|
||||
PAGE501=templates/error/501.tpl
|
||||
PAGE404="/templates/error/404.tpl"
|
||||
PAGE501="/templates/error/501.tpl"
|
||||
|
||||
# Users environment
|
||||
MYSQL_PARAM='{"host":"host.docker.internal", "user":"***user***", "pass":"***password***","base":"***basename***", "logsEnable":true}'
|
||||
MYSQL_PARAM='{"host":"host.docker.internal", "user":"***user***", "pass":"***password***","base":"***basename***", "logsEnable":true}'
|
||||
REDIS_PARAM='{"host":"127.0.0.1","port":6379,"connectTimeout":2.5,"backoff":{"algorithm":1,"base":500,"cap":750}, "database":0, "defaultExpire":300}'
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
Stable version
|
||||
|
||||
```bash
|
||||
composer create-project rmphp/skeleton
|
||||
composer create-project rmphp/skeleton project-name
|
||||
```
|
||||
|
||||
```bash
|
||||
composer create-project rmphp/skeleton:"^3.0"
|
||||
```
|
||||
composer create-project rmphp/skeleton:"^4.8" project-name
|
||||
```
|
||||
|
||||
41
application/base/Application/AbstractDTO.php
Normal file
41
application/base/Application/AbstractDTO.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromArray(array $data) : static {
|
||||
return self::fillObject(new ReflectionClass(static::class), new static(), $data);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Repository;
|
||||
|
||||
namespace Base\Application;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class RepositoryException extends \Exception {
|
||||
class ApplicationException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
@@ -12,4 +13,4 @@ class RepositoryException extends \Exception {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Common\Services;
|
||||
namespace Base\Application;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class ServiceException extends \Exception {
|
||||
class DTOException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
@@ -13,4 +13,4 @@ class ServiceException extends \Exception {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Controllers;
|
||||
namespace Base\Controllers;
|
||||
|
||||
use Laminas\Diactoros\Response\HtmlResponse;
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Laminas\Diactoros\Response\RedirectResponse;
|
||||
use Laminas\Diactoros\Response\TextResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Rmphp\Foundation\Exceptions\AppException;
|
||||
use Rmphp\Kernel\Main;
|
||||
use Throwable;
|
||||
|
||||
@@ -81,11 +80,24 @@ abstract class AbstractController extends Main {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $point
|
||||
* @param string $subtemplate
|
||||
* @param array $data
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function renderResponse(int $status = 200, array $headers = []) : ResponseInterface {
|
||||
public function renderResponse(string $point, string $subtemplate, array $data = [], int $status = 200, array $headers = []) : ResponseInterface {
|
||||
$this->template()->setSubtemplate($point, $this->getTemplatePath($subtemplate), $data);
|
||||
return new HtmlResponse($this->template()->getResponse(), $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function render(int $status = 200, array $headers = []) : ResponseInterface {
|
||||
return new HtmlResponse($this->template()->getResponse(), $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||
}
|
||||
|
||||
@@ -94,7 +106,7 @@ abstract class AbstractController extends Main {
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function setTemplateValue(string $point, string $string) : void {
|
||||
public function templSetValue(string $point, string $string) : void {
|
||||
$this->template()->setValue($point, $string);
|
||||
}
|
||||
|
||||
@@ -103,41 +115,35 @@ abstract class AbstractController extends Main {
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function addTemplateValue(string $point, string $string) : void {
|
||||
public function templAddValue(string $point, string $string) : void {
|
||||
$this->template()->addValue($point, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $point
|
||||
* @param string $subTempl
|
||||
* @param string $subtemplate
|
||||
* @param array $resource
|
||||
* @return void
|
||||
*/
|
||||
public function setSubtemplate(string $point, string $subTempl, array $resource = []) : void {
|
||||
$this->template()->setSubtemple($point, $subTempl, $resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $point
|
||||
* @param string $subTempl
|
||||
* @param array $resource
|
||||
* @return void
|
||||
*/
|
||||
public function addSubtemplate(string $point, string $subTempl, array $resource = []) : void {
|
||||
$this->template()->addSubtemple($point, $subTempl, $resource);
|
||||
public function templSetSubtemplate(string $point, string $subtemplate, array $resource = []) : void {
|
||||
$this->template()->setSubtemplate($point, $this->getTemplatePath($subtemplate), $resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $point
|
||||
* @param string $subtemplate
|
||||
* @param array $data
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return ResponseInterface
|
||||
* @param array $resource
|
||||
* @return void
|
||||
*/
|
||||
public function render(string $point, string $subtemplate, array $data = [], int $status = 200, array $headers = []) : ResponseInterface {
|
||||
$this->template()->setSubtemple($point, $subtemplate, $data);
|
||||
return new HtmlResponse($this->template()->getResponse(), $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||
public function templAddSubtemplate(string $point, string $subtemplate, array $resource = []) : void {
|
||||
$this->template()->addSubtemplate($point, $this->getTemplatePath($subtemplate), $resource);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplatePath(string $path) : string {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
35
application/base/Controllers/AbstractPageController.php
Normal file
35
application/base/Controllers/AbstractPageController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Controllers;
|
||||
|
||||
use Base\Application\ApplicationException;
|
||||
use Base\Application\DTOException;
|
||||
use Base\Domain\DomainException;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
abstract class AbstractPageController extends AbstractController {
|
||||
|
||||
/**
|
||||
* @param Exception $exception
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function exceptionPage(Exception $exception, array $data = []) : void {
|
||||
$this->logException($exception, $data);
|
||||
$this->syslogger()->warning($exception->getMessage()." on ".$exception->getFile().":".$exception->getLine(), $data);
|
||||
$this->template()->setSubtemplate("main", "/error/errpage.tpl", [
|
||||
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $e
|
||||
* @return string
|
||||
*/
|
||||
public function checkError(Throwable $e) : string {
|
||||
($e instanceof Exception) ? $this->logException($e) : $this->logError($e);
|
||||
if($e instanceof DTOException || $e instanceof DomainException || $e instanceof ApplicationException) return $e->getMessage();
|
||||
return "Ошибка. Дата и время: ".date("d-m-Y H:i:s");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Controllers;
|
||||
namespace Base\Controllers;
|
||||
|
||||
class NotFoundException extends \Exception {
|
||||
|
||||
}
|
||||
}
|
||||
15
application/base/Domain/DomainException.php
Normal file
15
application/base/Domain/DomainException.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Domain;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class DomainException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
public function __construct($message="", $code=0, array $data = [], Throwable $previous=null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
71
application/base/Handlers/AbstractHandler.php
Normal file
71
application/base/Handlers/AbstractHandler.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Handlers;
|
||||
|
||||
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
3
application/bin/cli
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
require_once dirname(__FILE__).'/cli.php';
|
||||
13
application/bin/cli.php
Normal file
13
application/bin/cli.php
Normal 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);
|
||||
@@ -11,17 +11,19 @@
|
||||
"laminas/laminas-diactoros": "^2.5",
|
||||
"monolog/monolog": "^2.3",
|
||||
"php-di/php-di": "^6.3",
|
||||
"symfony/dotenv": "^6.2",
|
||||
"rmphp/kernel": "^3.0",
|
||||
"rmphp/router": "^1.0",
|
||||
"rmphp/content": "^2.0",
|
||||
"rmphp/storage": "^2.0",
|
||||
"rmphp/session": "^1.0",
|
||||
"rmphp/cache-file": "^1.0"
|
||||
"ramsey/uuid": "^4.7",
|
||||
"rmphp/content": "^4.0",
|
||||
"rmphp/kernel": "^6.0",
|
||||
"rmphp/router": "^2.0",
|
||||
"rmphp/session": "^1.1",
|
||||
"rmphp/redis": "^1.0",
|
||||
"rmphp/storage": "^6.0",
|
||||
"symfony/dotenv": "^6.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src"
|
||||
"App\\": "src",
|
||||
"Base\\": "application/base"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
19
config/app-cli.php
Normal file
19
config/app-cli.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
# Example:
|
||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||
# ['key'=>'', 'router'=>'config/routes-cli/routes.php'],
|
||||
# ['key'=>'/', 'router'=>[]],
|
||||
|
||||
return [
|
||||
['key'=>'', 'router'=>[
|
||||
[
|
||||
'key'=>'index',
|
||||
'routes' => [
|
||||
[
|
||||
'action' => "App\Infrastructure\Handlers\IndexHandler",
|
||||
'method' => "index"
|
||||
]
|
||||
]
|
||||
]
|
||||
]],
|
||||
];
|
||||
@@ -1,21 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Правила для точек монтирования слоев
|
||||
*/
|
||||
|
||||
# Example:
|
||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
||||
# ['key'=>'/', 'router'=>[]],
|
||||
|
||||
return [
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\RouterInterface::class => 'config/factories/routerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\TemplateInterface::class => 'config/factories/templateFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Log\LoggerInterface::class => 'config/factories/loggerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Container\ContainerInterface::class => 'config/factories/containerFactory.php',
|
||||
['key'=>'/', 'router'=>'config/routes/routes.php'],
|
||||
];
|
||||
|
||||
20
config/components.php
Normal file
20
config/components.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\RouterInterface::class => 'config/components/routerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||
*/
|
||||
\Rmphp\Foundation\TemplateInterface::class => 'config/components/templateFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Log\LoggerInterface::class => 'config/components/loggerFactory.php',
|
||||
/**
|
||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||
*/
|
||||
\Psr\Container\ContainerInterface::class => 'config/components/containerFactory.php',
|
||||
];
|
||||
19
config/components/containerFactory.php
Normal file
19
config/components/containerFactory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
$containerIni = (getenv("CONTAINER_INI")) ?: "config/container.php";
|
||||
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
||||
|
||||
$dependencies = require dirname(__DIR__,2).'/'.$containerIni;
|
||||
|
||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||
return require dirname(__DIR__,2)."/".$dependenciesFile;
|
||||
}, $dependencies);
|
||||
|
||||
try {
|
||||
$builder = new ContainerBuilder();
|
||||
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,2)."/".$containerCache);
|
||||
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||
return $builder->build();
|
||||
} catch (Exception $e) {echo $e->getMessage();}
|
||||
2
config/components/loggerFactory.php
Normal file
2
config/components/loggerFactory.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 2).'/var/logs/log'.date('Ymd').'.log'));
|
||||
4
config/components/templateFactory.php
Normal file
4
config/components/templateFactory.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return (new \Rmphp\Content\Content('/templates/base.tpl'))->setSubtemplatePath('/templates/')->setSubtemplatePathAlias([
|
||||
"main" => "/src/Infrastructure/subtemplates",
|
||||
]);
|
||||
5
config/container.php
Normal file
5
config/container.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
"config/container/services.php",
|
||||
"config/container/settings.php",
|
||||
];
|
||||
@@ -1,15 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Rmphp\Cache\Cache;
|
||||
use Rmphp\Cache\CacheInterface;
|
||||
use Rmphp\Session\Session;
|
||||
use Rmphp\Session\SessionInterface;
|
||||
use Rmphp\Storage\Mysql\MysqlStorage;
|
||||
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
||||
|
||||
return [
|
||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
||||
SessionInterface::class => DI\create(Session::class)->constructor(),
|
||||
CacheInterface::class => DI\create(Cache::class)->constructor("../var/cache"),
|
||||
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Repository\Mysql\*Repository'),
|
||||
];
|
||||
'App\Domain\Repository\*RepositoryInterface' => DI\autowire('App\Infrastructure\Repository\*Repository'),
|
||||
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||
];
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
$containerDir = (getenv("CONTAINER_DIR"))?:"config/container";
|
||||
$containerCache = (getenv("CONTAINER_CACHE"))?:"var/cache/container";
|
||||
|
||||
$dependencies = glob(dirname(__DIR__,2)."/".$containerDir."/*.php");
|
||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||
return require $dependenciesFile;
|
||||
}, $dependencies);
|
||||
|
||||
try {
|
||||
$builder = new ContainerBuilder();
|
||||
if(getenv("APP_MODE") != "DEV") $builder->enableCompilation(dirname(__DIR__,2)."/".$containerCache);
|
||||
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||
return $builder->build();
|
||||
} catch (Exception $e) {echo $e->getMessage();}
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__.'/../../var/logs/log'.date('Ymd').'.log'));
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
return (new \Rmphp\Content\Content('templates/base.tpl'))->setSubtemplePath('templates');
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Правила для точек монтирования модулей
|
||||
* Каждый массив определяет порядок срабатывания, часть url с которого
|
||||
*/
|
||||
|
||||
# Example:
|
||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
||||
# ['key'=>'/', 'router'=>'config/routes/main.yaml'],
|
||||
|
||||
return [
|
||||
['key'=>'/', 'router'=>'config/routes/main.yaml'],
|
||||
];
|
||||
|
||||
13
config/routes/99-main.yaml
Normal file
13
config/routes/99-main.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
# Index
|
||||
- key: "/"
|
||||
routes:
|
||||
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||
method: "index"
|
||||
params: ""
|
||||
|
||||
# Empty
|
||||
- key: "<@any>"
|
||||
routes:
|
||||
- action: "App\\Infrastructure\\Controllers\\IndexController"
|
||||
method: "emptyAction"
|
||||
params: ""
|
||||
@@ -1,12 +0,0 @@
|
||||
- key: "/"
|
||||
routes:
|
||||
- action: "App\\Main\\Controllers\\IndexController"
|
||||
method: "index"
|
||||
params: ""
|
||||
|
||||
# Empty
|
||||
- key: "[any]"
|
||||
routes:
|
||||
- action: "App\\Main\\Controllers\\IndexController"
|
||||
method: "emptyAction"
|
||||
params: ""
|
||||
@@ -1,13 +0,0 @@
|
||||
# Index
|
||||
- key: "/"
|
||||
routes:
|
||||
- action: "App\\Main\\Controllers\\IndexController"
|
||||
method: "index"
|
||||
params: ""
|
||||
|
||||
# Empty
|
||||
- key: "[any]"
|
||||
routes:
|
||||
- action: "App\\Main\\Controllers\\IndexController"
|
||||
method: "emptyAction"
|
||||
params: ""
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
$routes = glob(__DIR__."/{*.yaml}", GLOB_BRACE);
|
||||
|
||||
$routesCollection = array_map(function ($routesFile){
|
||||
return file_get_contents($routesFile).PHP_EOL;
|
||||
}, $routes);
|
||||
|
||||
return yaml_parse(implode($routesCollection));
|
||||
16
config/routes/routes.php
Normal file
16
config/routes/routes.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
$cashFile = dirname(__DIR__,2).'/var/routes/'.md5(__FILE__);
|
||||
|
||||
if(getenv("APP_MODE") == "PROD" && file_exists($cashFile)){
|
||||
return unserialize(file_get_contents($cashFile));
|
||||
} else {
|
||||
$routesCollection = array_map(function ($routesFile){
|
||||
return file_get_contents($routesFile).PHP_EOL;
|
||||
}, glob(__DIR__."/{*.yaml}", GLOB_BRACE));
|
||||
|
||||
$routes = yaml_parse(implode($routesCollection));
|
||||
if (!is_dir(dirname($cashFile))) mkdir(dirname($cashFile), 0777, true);
|
||||
file_put_contents($cashFile, serialize($routes));
|
||||
return $routes;
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
body{font-family: Arimo, sans-serif; font-size: 15px; margin: 0; padding: 0;}
|
||||
body{
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 15px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background:#d4e5d8;
|
||||
}
|
||||
* {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #CCC #FFF
|
||||
@@ -15,4 +21,20 @@ body{font-family: Arimo, sans-serif; font-size: 15px; margin: 0; padding: 0;}
|
||||
border: 3px solid #FFF;
|
||||
}
|
||||
|
||||
h1{padding: 0 30px}
|
||||
h1{padding: 0 30px}
|
||||
|
||||
.main-block{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 50vh;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
color:#888;
|
||||
}
|
||||
.main-block__header{
|
||||
font-size: 70px;
|
||||
}
|
||||
.main-block__text{
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,19 @@ require_once dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__).'/.env');
|
||||
|
||||
error_reporting(0); ini_set('display_errors','Off');
|
||||
if(getenv("APP_MODE") == 'DEV'){
|
||||
if(getenv("APP_MODE") == 'DEBUG'){
|
||||
error_reporting(E_ALL); ini_set('display_errors','On');
|
||||
} else {
|
||||
error_reporting(0); ini_set('display_errors','Off');
|
||||
}
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals();
|
||||
|
||||
$app = new App();
|
||||
$response = $app->handler($request, (new Response())->withHeader("Content-Type", "text/html; charset=utf-8"));
|
||||
$response = $app->handler($request, new Response());
|
||||
(new ResponseEmitter())->emit($response);
|
||||
|
||||
|
||||
if(getenv("APP_MODE") == 'DEV' && in_array("Dev", $response->getHeader("App-Mode"))){
|
||||
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
|
||||
$app->syslogger()->dump("Response", $response);
|
||||
addShutdownInfo($app->syslogger()->getLogs());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Services;
|
||||
|
||||
use Rmphp\Kernel\Main;
|
||||
|
||||
class AbstractService extends Main {
|
||||
|
||||
|
||||
}
|
||||
0
src/Infrastructure/Components/.gitkeep
Normal file
0
src/Infrastructure/Components/.gitkeep
Normal file
24
src/Infrastructure/Controllers/IndexController.php
Normal file
24
src/Infrastructure/Controllers/IndexController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Infrastructure\Controllers;
|
||||
use Base\Controllers\AbstractPageController;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class IndexController extends AbstractPageController {
|
||||
|
||||
/**
|
||||
* @return bool|ResponseInterface
|
||||
*/
|
||||
public function index() : bool|ResponseInterface {
|
||||
try {
|
||||
//$this->addHeader("App-Mode", "Dev");
|
||||
$this->template()->setValue("title", "Главная");
|
||||
}
|
||||
catch(\Throwable $e){$error = $this->checkError($e);}
|
||||
|
||||
return $this->renderResponse("main", "@main/index.tpl", [
|
||||
"date" => (new \DateTime())->format('Y-m-d H:i:s'),
|
||||
"error" => $error ?? null
|
||||
]);
|
||||
}
|
||||
}
|
||||
22
src/Infrastructure/Handlers/IndexHandler.php
Normal file
22
src/Infrastructure/Handlers/IndexHandler.php
Normal 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\Handlers\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'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
0
src/Infrastructure/Repository/.gitkeep
Normal file
0
src/Infrastructure/Repository/.gitkeep
Normal file
8
src/Infrastructure/subtemplates/index.tpl
Normal file
8
src/Infrastructure/subtemplates/index.tpl
Normal file
@@ -0,0 +1,8 @@
|
||||
<article>
|
||||
<main>
|
||||
<div class="main-block">
|
||||
<div class="main-block__header">Hello</div>
|
||||
<div class="main-block__text">Now is <?= $this->date ?></div>
|
||||
</div>
|
||||
</main>
|
||||
</article>
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Main\Controllers;
|
||||
use App\Common\Controllers\AbstractController;
|
||||
use App\Common\Services\ServiceException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
|
||||
class IndexController extends AbstractController {
|
||||
|
||||
/**
|
||||
* @return bool|ResponseInterface
|
||||
*/
|
||||
public function index() : bool|ResponseInterface {
|
||||
try {
|
||||
$this->addHeader("App-Mode", "Dev");
|
||||
$this->template()->setValue("title", "Главная");
|
||||
$this->template()->setSubtemple("main", "main/index.tpl", [
|
||||
"date" => (new \DateTime())->format('Y-m-d H:i:s')
|
||||
]);
|
||||
return $this->renderResponse();
|
||||
}
|
||||
catch(ServiceException $exception){}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>404</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>404 Page Not Found</title>
|
||||
<style>
|
||||
body{
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 15px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: #c9d1e1;
|
||||
}
|
||||
.err-page{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 50vh;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
color:#888;
|
||||
}
|
||||
.err-page__header{
|
||||
font-size: 70px;
|
||||
}
|
||||
.err-page__text{
|
||||
font-size: 30px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Error 404</h1>
|
||||
<div class="err-page">
|
||||
<div class="err-page__header">404</div>
|
||||
<div class="err-page__text">Page Not Found</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>500</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>501 Not Implemented</title>
|
||||
<style>
|
||||
body{
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 15px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: #e1c9d1;
|
||||
}
|
||||
.err-page{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 50vh;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
color:#888;
|
||||
}
|
||||
.err-page__header{
|
||||
font-size: 70px;
|
||||
}
|
||||
.err-page__text{
|
||||
font-size: 30px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Error 500</h1>
|
||||
<div class="err-page">
|
||||
<div class="err-page__header">501</div>
|
||||
<div class="err-page__text">Not Implemented</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
0
templates/inc/footer.tpl
Normal file
0
templates/inc/footer.tpl
Normal file
12
templates/inc/header.tpl
Normal file
12
templates/inc/header.tpl
Normal file
@@ -0,0 +1,12 @@
|
||||
<header class="header">
|
||||
<div class="header__logo">
|
||||
<a class="header__logolink" href="/"> </a>
|
||||
</div>
|
||||
<div class="header__freearea"></div>
|
||||
<div class="header__user"><?=$this->user->fio ?? "Гость"?></div>
|
||||
<div class="header__out">
|
||||
<a href="/?logout">
|
||||
<i class="header__outicon fa-solid fa-right-from-bracket"></i>
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
@@ -1,5 +0,0 @@
|
||||
<article>
|
||||
<main>
|
||||
<h1>Hello. Now is <?=$this->date?></h1>
|
||||
</main>
|
||||
</article>
|
||||
Reference in New Issue
Block a user