58 Commits
1.0 ... 4.8

Author SHA1 Message Date
User
ddb82ee395 20250303#4 2025-03-03 15:25:46 +03:00
User
a095b76e8d 20250303#3 2025-03-03 14:30:02 +03:00
User
70810412f4 20250303#2 2025-03-03 14:25:44 +03:00
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
User
11b1544317 20250113#4 2025-01-13 05:04:47 +03:00
User
9e4ae35455 20250113#3 2025-01-13 04:56:52 +03:00
User
23133c173c 20250113#2 2025-01-13 04:52:35 +03:00
User
bf529d83c8 20250113#1 2025-01-13 04:44:41 +03:00
User
794e82f7ce 20241102#2 2024-11-02 07:39:22 +03:00
User
035f88ea72 20241102#1 2024-11-02 07:31:03 +03:00
User
1b0af12a46 20241004#1 2024-10-04 03:00:11 +03:00
User
99f78f7362 20240814#2 2024-08-14 21:27:27 +03:00
User
72d2445bb2 20240814#1 2024-08-14 21:13:25 +03:00
User
40e771f1f2 20240719#1 2024-07-19 13:38:34 +03:00
User
858dfd17c0 20240708#2 2024-07-08 14:02:22 +03:00
User
c3e7bc6fc7 20240708#1 2024-07-08 13:57:42 +03:00
User
3ebbe07db6 20240508#1 2024-05-08 01:07:24 +03:00
User
e865eca689 20240505#3 2024-05-05 11:27:59 +03:00
User
e83753471c 20240505#2 2024-05-05 11:15:11 +03:00
User
6c571aa358 20240505#1 2024-05-05 11:09:18 +03:00
User
8b92eecba1 20240502#2 2024-05-02 12:01:28 +03:00
User
e03c9bccfc 20240502#1 2024-05-02 11:29:58 +03:00
User
88b597d78d 20240423#6 2024-04-23 05:43:03 +03:00
User
de10cbae31 20240423#5 2024-04-23 05:41:46 +03:00
User
98c2d37870 20240423#4 2024-04-23 05:25:47 +03:00
User
1258828b2d 20240423#3 2024-04-23 05:17:27 +03:00
User
8ef1287567 20240423#2 2024-04-23 05:16:53 +03:00
User
009832a046 20240423#1 2024-04-23 05:15:45 +03:00
User
4ad36c6034 20240413#9 2024-04-13 12:24:53 +03:00
User
8346234859 20240413#8 2024-04-13 12:16:12 +03:00
User
cb5408be4a 20240413#7 2024-04-13 11:33:47 +03:00
User
041ee17263 20240413#6 2024-04-13 04:41:58 +03:00
User
15ec4a46bc 20240413#5 2024-04-13 04:38:40 +03:00
User
da2bab7338 20240413#4 2024-04-13 04:18:46 +03:00
User
5b8ef84efa 20240413#3 2024-04-13 00:50:33 +03:00
User
9abb4d4d6b 20240413#2 2024-04-13 00:39:19 +03:00
User
171def66b8 20240413#1 2024-04-13 00:38:33 +03:00
User
f6b47693a4 20240412#5 2024-04-12 03:32:09 +03:00
User
36861b6967 20240412#4 2024-04-12 03:28:10 +03:00
User
44250475c1 20240412#3 2024-04-12 03:26:36 +03:00
User
a35a50eb53 20240412#2 2024-04-12 03:24:10 +03:00
User
c2d2ad9177 20240412#1 2024-04-12 03:18:04 +03:00
User
035783e264 20231011#1 2023-10-11 00:22:06 +03:00
User
cdf9a13242 20231010#1 2023-10-10 23:13:19 +03:00
User
7df5be904f 20231007#1 2023-10-07 23:11:28 +03:00
User
34de164e72 20230926#2 2023-09-26 21:50:53 +03:00
User
19731cb6fe 20230926#1 2023-09-26 16:50:06 +03:00
User
4c087a156b 20230926#1 2023-09-26 16:49:41 +03:00
User
4ea833db5a 20230818#1 2023-08-18 02:15:16 +03:00
User
19b505a458 20230626#1 2023-06-26 21:11:35 +03:00
62 changed files with 602 additions and 311 deletions

8
.editorconfig Normal file
View 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

View File

@@ -8,24 +8,18 @@
#
# Real environment variables win over .env files.
# App mode (DEV, TEST, PROD)
# PROD / DEV
APP_MODE=DEV
# Including file with array of componens
APP_COMPONENTS_FILE="config/components.php"
# Including file with array of app nodes
APP_NODES_FILE="config/appnodes.php"
# Define app nodes
#APP_NODE1='{"key":"/","action":"App\\Auth\\Controllers\\UserController","method":"index"}'
#APP_NODE2='{"key":"/","router":"config/routes/main/collection.php"}'
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="public/web/404.html"
PAGE501="public/web/501.html"
PAGE404="/templates/error/404.tpl"
PAGE501="/templates/error/501.tpl"
# Users environment
CONTAINER_DIR="config/container"
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}'

View File

@@ -5,15 +5,9 @@
Stable version
```bash
composer create-project rmphp/skeleton
```
```bash
composer create-project rmphp/skeleton:"^1.0"
composer create-project rmphp/skeleton project-name
```
Dev version contains the latest changes
```bash
composer create-project rmphp/skeleton:"1.0.x-dev"
```
composer create-project rmphp/skeleton:"^4.8" project-name
```

View 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);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,149 @@
<?php
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\Kernel\Main;
use Throwable;
abstract class AbstractController 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);
}
/**
* @param string $url
* @param int $status
* @param array $headers
* @return ResponseInterface
*/
public function redirectResponse(string $url, int $status = 302, array $headers = []) : ResponseInterface {
return new RedirectResponse($url, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
}
/**
* @param string $point
* @param string $subtemplate
* @param array $data
* @param int $status
* @param array $headers
* @return 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));
}
/**
* @param string $point
* @param string $string
* @return void
*/
public function templSetValue(string $point, string $string) : void {
$this->template()->setValue($point, $string);
}
/**
* @param string $point
* @param string $string
* @return void
*/
public function templAddValue(string $point, string $string) : void {
$this->template()->addValue($point, $string);
}
/**
* @param string $point
* @param string $subtemplate
* @param array $resource
* @return void
*/
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 $resource
* @return void
*/
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;
}
}

View 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");
}
}

View File

@@ -1,7 +1,7 @@
<?php
namespace App\Common\Controllers;
namespace Base\Controllers;
class NotFoundException extends \Exception {
}
}

View 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;
}
}

View File

@@ -1,43 +1,33 @@
<?php
namespace App\Common\Controllers;
namespace Base\Handlers;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\Response\TextResponse;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Rmphp\Kernel\Main;
use Throwable;
abstract class AbstractController extends Main {
abstract class AbstractHandler extends Main {
/**
* @param string $name
* @return mixed|void
*/
public function containerGet(string $name) {
try {
return $this->container()->get($name);
}
catch (NotFoundExceptionInterface $notFoundException){
$this->syslogger()->error($notFoundException->getMessage());
}
catch (ContainerExceptionInterface $containerException){
$this->syslogger()->error($containerException->getMessage());
}
}
/**
* @param \Throwable $throwable
* @param Throwable $throwable
* @param array $data
* @return void
*/
public function logException(\Throwable $throwable, array $data = []) : 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
@@ -65,7 +55,6 @@ abstract class AbstractController extends Main {
* @return ResponseInterface
*/
public function textResponse($text, int $status = 200, array $headers = []) : ResponseInterface {
$this->container()->set("showDebugLogs", false);
return new TextResponse($text, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
}
@@ -76,19 +65,7 @@ abstract class AbstractController extends Main {
* @return ResponseInterface
*/
public function jsonResponse(array $array, int $status = 200, array $headers = []) : ResponseInterface {
$this->container()->set("showDebugLogs", false);
return new JsonResponse($array, $status, array_merge($this->globals()->response()->getHeaders(), $headers), JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}
/**
* @param string $url
* @param int $status
* @param array $headers
* @return ResponseInterface
*/
public function redirectResponse(string $url, int $status = 302, array $headers = []) : ResponseInterface {
$this->container()->set("showDebugLogs", false);
return new RedirectResponse($url, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
}
}
}

3
application/bin/cli Normal file
View File

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

13
application/bin/cli.php Normal file
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

@@ -11,15 +11,19 @@
"laminas/laminas-diactoros": "^2.5",
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
"symfony/dotenv": "^6.2",
"rmphp/kernel": "^1.0",
"rmphp/router": "^1.0",
"rmphp/content": "^1.0",
"rmphp/storage": "^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": {
@@ -30,6 +34,7 @@
"process-timeout":0
},
"require-dev": {
"symfony/var-dumper": "^5.3",
"rmphp/var-damper": "^1.0"
}
}

19
config/app-cli.php Normal file
View 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"
]
]
]
]],
];

13
config/app.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
/**
* Правила для точек монтирования слоев
*/
# Example:
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
# ['key'=>'/', 'router'=>[]],
return [
['key'=>'/', 'router'=>'config/routes/routes.php'],
];

View File

@@ -1,17 +0,0 @@
<?php
/**
* Правила для точек монтирования модулей
* Каждый массив определяет порядок срабатывания, часть url с которого
*/
# Example:
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
# ['key'=>'/', 'router'=>'config/routes/main/collection.php'],
# ['key'=>'/', 'router'=>'config/routes/main.json']
# ['key'=>'/', 'router'=>'config/routes/main.yaml'],
return [
['key'=>'/', 'router'=>'config/routes/main.yaml'],
];

View File

@@ -4,18 +4,17 @@ return [
/**
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
*/
\Rmphp\Foundation\RouterInterface::class => 'config/factories/routerFactory.php',
\Rmphp\Foundation\RouterInterface::class => 'config/components/routerFactory.php',
/**
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
*/
\Rmphp\Foundation\TemplateInterface::class => 'config/factories/templateFactory.php',
\Rmphp\Foundation\TemplateInterface::class => 'config/components/templateFactory.php',
/**
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
*/
\Psr\Log\LoggerInterface::class => 'config/factories/loggerFactory.php',
\Psr\Log\LoggerInterface::class => 'config/components/loggerFactory.php',
/**
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
*/
\Psr\Container\ContainerInterface::class => 'config/factories/containerFactory.php',
\Psr\Container\ContainerInterface::class => 'config/components/containerFactory.php',
];

View 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();}

View 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'));

View 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
View File

@@ -0,0 +1,5 @@
<?php
return [
"config/container/services.php",
"config/container/settings.php",
];

View File

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

View File

@@ -1,18 +0,0 @@
<?php
use DI\ContainerBuilder;
$containerDir = (getenv("CONTAINER_DIR"))?:"config/container/";
$dependencies = glob(dirname(__DIR__,2)."/".$containerDir."/*.php");
$dependenciesCollection = array_map(function ($dependenciesFile){
return require $dependenciesFile;
}, $dependencies);
try {
$builder = new ContainerBuilder();
$builder->enableCompilation(__DIR__ . '/../../var/cache/container');
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
return $builder->build();
} catch (Exception $e) {echo $e->getMessage();}

View File

@@ -1,2 +0,0 @@
<?php
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__.'/../../var/logs/log'.date('Ymd').'.log'));

View File

@@ -1,2 +0,0 @@
<?php
return (new \Rmphp\Content\Content('public/web/main/sheet.html'))->setSubtemplePath('templates');

View 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: ""

View File

@@ -1,14 +0,0 @@
[
{
"key": "/",
"routes": [
{"action": "App\\Main\\Controllers\\IndexController", "method": "index", "params": ""}
]
},
{
"key": "[any]",
"routes": [
{"action": "App\\Main\\Controllers\\IndexController", "method": "emptyAction", "params": ""}
]
}
]

View File

@@ -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: ""

View File

@@ -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: ""

View File

@@ -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
View 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;
}

View File

@@ -0,0 +1,40 @@
body{
font-family: Arial, sans-serif;
font-size: 15px;
margin: 0;
padding: 0;
background:#d4e5d8;
}
* {
scrollbar-width: thin;
scrollbar-color: #CCC #FFF
}
*::-webkit-scrollbar {
width: 10px;
}
*::-webkit-scrollbar-track {
background: #FFF;
}
*::-webkit-scrollbar-thumb {
background-color: #AAA;
border-radius: 20px;
border: 3px solid #FFF;
}
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;
}

View File

@@ -11,29 +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"))){
$app->syslogger()->dump("request", $request);
$app->syslogger()->dump("response", $response);
$app->syslogger()->dump("globals", [
"ENV"=>$_ENV,
"GET"=>$request->getQueryParams(),
"POST"=>$request->getParsedBody(),
"COOKIE"=>$request->getCookieParams(),
"SESSION"=>$_SESSION ?? [],
"SERVER"=>$request->getServerParams()
]);
$app->syslogger()->dump("kernel", $app);
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
$app->syslogger()->dump("Response", $response);
addShutdownInfo($app->syslogger()->getLogs());
}
}

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404</title>
</head>
<body>
<h1>Error 404</h1>
</body>
</html>

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>500</title>
</head>
<body>
<h1>Error 500</h1>
</body>
</html>

View File

@@ -1,18 +0,0 @@
body{font-family: Arimo, sans-serif; font-size: 15px; margin: 0; padding: 0;}
* {
scrollbar-width: thin;
scrollbar-color: #CCC #FFF
}
*::-webkit-scrollbar {
width: 10px;
}
*::-webkit-scrollbar-track {
background: #FFF;
}
*::-webkit-scrollbar-thumb {
background-color: #AAA;
border-radius: 20px;
border: 3px solid #FFF;
}
h1{padding: 0 30px}

View File

@@ -1,36 +0,0 @@
<?php
namespace App\Common\Controllers;
abstract class AbstractPageController extends AbstractController {
/**
* @param string $point
* @param string $string
*/
public function templateAddValue(string $point, string $string) : void {
$this->template()->addValue($point, $string);
}
/**
* @param string $point
* @param string $subTempl
* @param array $resource
*/
public function templateSetSubtemple(string $point, string $subTempl, array $resource = []) : void {
$this->template()->setSubtemple($point, $subTempl, $resource);
}
/**
* @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->templateSetSubtemple("main", "/main/errpage.tpl", [
"errorText" => "<span style='color:red'>Error: ".$exception->getMessage()." (".$exception->getCode().")"."</span>"
]);
}
}

View File

@@ -1,10 +0,0 @@
<?php
namespace App\Common\Services;
use Rmphp\Kernel\Main;
class AbstractService extends Main {
}

View 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
]);
}
}

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\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'));
}
}

View 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>

View File

@@ -1,25 +0,0 @@
<?php
namespace App\Main\Controllers;
use App\Common\Controllers\AbstractPageController;
use App\Common\Services\ServiceException;
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", "Главная");
$this->template()->setSubtemple("main", "main/index.tpl", [
]);
}
catch(ServiceException $exception){}
return true;
}
}

View File

@@ -5,15 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rmphp - <?=$this->getPoint('title')?></title>
<link href="/web/main/css/style.css?1" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="/assets/css/style.css?1" rel="stylesheet">
</head>
<body>
<?=$this->getPoint('main')?>
<script type="text/javascript" src="/web/main/js/script.js?1"></script>
<script type="text/javascript" src="/assets/js/script.js?1"></script>
<?=$this->getPoint('jsscript')?>
</body>
</html>

38
templates/error/404.tpl Normal file
View File

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<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>
<div class="err-page">
<div class="err-page__header">404</div>
<div class="err-page__text">Page Not Found</div>
</div>
</body>
</html>

38
templates/error/501.tpl Normal file
View File

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<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>
<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
View File

12
templates/inc/header.tpl Normal file
View File

@@ -0,0 +1,12 @@
<header class="header">
<div class="header__logo">
<a class="header__logolink" href="/">&nbsp;</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>

View File

@@ -1,5 +0,0 @@
<article>
<main>
<h1>Hellow</h1>
</main>
</article>