Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
035783e264 |
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
|
||||||
12
.env.dist
12
.env.dist
@@ -8,15 +8,17 @@
|
|||||||
#
|
#
|
||||||
# Real environment variables win over .env files.
|
# Real environment variables win over .env files.
|
||||||
|
|
||||||
|
# PROD / DEV
|
||||||
APP_MODE=DEV
|
APP_MODE=DEV
|
||||||
APP_COMPONENTS_FILE=config/app.php
|
APP_NODES_FILE=application/config/app.php
|
||||||
APP_NODES_FILE=config/nodes.php
|
APP_COMPONENTS_FILE=application/config/components.php
|
||||||
CONTAINER_DIR=config/container
|
CONTAINER_INI=application/config/container.php
|
||||||
CONTAINER_CACHE=var/cache/container
|
CONTAINER_CACHE=var/cache/container
|
||||||
|
|
||||||
# Default page
|
# Default page
|
||||||
PAGE404=templates/error/404.tpl
|
PAGE404="/templates/error/404.tpl"
|
||||||
PAGE501=templates/error/501.tpl
|
PAGE501="/templates/error/501.tpl"
|
||||||
|
|
||||||
# Users environment
|
# 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
|
Stable version
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton
|
composer create-project rmphp/skeleton project-name
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton:"^2.0"
|
composer create-project rmphp/skeleton:"^4.6" 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
|
<?php
|
||||||
|
|
||||||
namespace App\Common\Repository;
|
|
||||||
|
namespace Base\Application;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class RepositoryException extends \Exception {
|
class ApplicationException extends \Exception {
|
||||||
|
|
||||||
public array $data;
|
public array $data;
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace App\Common\Services;
|
namespace Base\Application;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class ServiceException extends \Exception {
|
class DTOException extends \Exception {
|
||||||
|
|
||||||
public array $data;
|
public array $data;
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Common\Controllers;
|
namespace Base\Controllers;
|
||||||
|
|
||||||
use Laminas\Diactoros\Response\HtmlResponse;
|
use Laminas\Diactoros\Response\HtmlResponse;
|
||||||
use Laminas\Diactoros\Response\JsonResponse;
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
@@ -79,16 +79,6 @@ abstract class AbstractController extends Main {
|
|||||||
return new RedirectResponse($url, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
return new RedirectResponse($url, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $status
|
|
||||||
* @param array $headers
|
|
||||||
* @return ResponseInterface
|
|
||||||
*/
|
|
||||||
public function renderResponse(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 $point
|
||||||
* @param string $subtemplate
|
* @param string $subtemplate
|
||||||
@@ -97,9 +87,63 @@ abstract class AbstractController extends Main {
|
|||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function render(string $point, string $subtemplate, array $data = [], int $status = 200, array $headers = []) : ResponseInterface {
|
public function renderResponse(string $point, string $subtemplate, array $data = [], int $status = 200, array $headers = []) : ResponseInterface {
|
||||||
$this->template()->setSubtemple($point, $subtemplate, $data);
|
$this->template()->setSubtemplate($point, $this->getTemplatePath($subtemplate), $data);
|
||||||
return new HtmlResponse($this->template()->getResponse(), $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Common\Controllers;
|
namespace Base\Controllers;
|
||||||
|
|
||||||
class NotFoundException extends \Exception {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
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';
|
||||||
33
application/bin/cli.php
Normal file
33
application/bin/cli.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use DI\Container;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Log\LoggerInterface;use Rmphp\Kernel\ResponseEmitter;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__,2).'/vendor/autoload.php';
|
||||||
|
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__,2).'/.env');
|
||||||
|
|
||||||
|
/** @var LoggerInterface $logger */
|
||||||
|
$logger = require_once dirname(__DIR__,2).'/application/config/components/loggerFactory.php';
|
||||||
|
/** @var Container $container */
|
||||||
|
$container = require_once dirname(__DIR__,2).'/application/config/components/containerFactory.php';
|
||||||
|
$container->set(LoggerInterface::class, $logger);
|
||||||
|
|
||||||
|
if(str_contains($argv[1], ':')) {
|
||||||
|
list($className, $method) = explode(':', $argv[1]);
|
||||||
|
if(class_exists($className)) {
|
||||||
|
try {
|
||||||
|
$controllers = $container->get($className);
|
||||||
|
if(method_exists($controllers, $method)) {
|
||||||
|
$response = $controllers->$method();
|
||||||
|
}
|
||||||
|
if(isset($response)) {
|
||||||
|
if($response instanceof ResponseInterface) (new ResponseEmitter())->emit($response);
|
||||||
|
elseif(!is_bool($response)) echo $response;
|
||||||
|
}
|
||||||
|
} catch(Throwable $throwable){
|
||||||
|
$logger->error($throwable->getMessage()." on ".$throwable->getFile().":".$throwable->getLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else echo "Class $className does not exist";
|
||||||
|
}
|
||||||
13
application/config/app.php
Normal file
13
application/config/app.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Правила для точек монтирования слоев
|
||||||
|
*/
|
||||||
|
|
||||||
|
# Example:
|
||||||
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
|
# ['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
|
||||||
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
|
return [
|
||||||
|
['key'=>'/', 'router'=>'application/config/routes/routes.php'],
|
||||||
|
];
|
||||||
@@ -4,18 +4,17 @@ return [
|
|||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию RouterInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Rmphp\Foundation\RouterInterface::class => 'config/factories/routerFactory.php',
|
\Rmphp\Foundation\RouterInterface::class => 'application/config/components/routerFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию TemplateInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Rmphp\Foundation\TemplateInterface::class => 'config/factories/templateFactory.php',
|
\Rmphp\Foundation\TemplateInterface::class => 'application/config/components/templateFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию PSR-3 LoggerInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Psr\Log\LoggerInterface::class => 'config/factories/loggerFactory.php',
|
\Psr\Log\LoggerInterface::class => 'application/config/components/loggerFactory.php',
|
||||||
/**
|
/**
|
||||||
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
* Путь к файлу фабрики возвращающий реализацию PSR-11 ContainerInterface или сам экземпляр класса
|
||||||
*/
|
*/
|
||||||
\Psr\Container\ContainerInterface::class => 'config/factories/containerFactory.php',
|
\Psr\Container\ContainerInterface::class => 'application/config/components/containerFactory.php',
|
||||||
];
|
];
|
||||||
|
|
||||||
19
application/config/components/containerFactory.php
Normal file
19
application/config/components/containerFactory.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
|
$containerIni = (getenv("CONTAINER_INI")) ?: "application/config/container.php";
|
||||||
|
$containerCache = (getenv("CONTAINER_CACHE")) ?: "var/cache/container";
|
||||||
|
|
||||||
|
$dependencies = require dirname(__DIR__,3).'/'.$containerIni;
|
||||||
|
|
||||||
|
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||||
|
return require dirname(__DIR__,3)."/".$dependenciesFile;
|
||||||
|
}, $dependencies);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$builder = new ContainerBuilder();
|
||||||
|
if(getenv("APP_MODE") == "PROD") $builder->enableCompilation(dirname(__DIR__,3)."/".$containerCache);
|
||||||
|
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||||
|
return $builder->build();
|
||||||
|
} catch (Exception $e) {echo $e->getMessage();}
|
||||||
2
application/config/components/loggerFactory.php
Normal file
2
application/config/components/loggerFactory.php
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
return (new \Monolog\Logger('system'))->pushHandler(new \Monolog\Handler\StreamHandler(dirname(__DIR__, 3).'/var/logs/log'.date('Ymd').'.log'));
|
||||||
4
application/config/components/templateFactory.php
Normal file
4
application/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
application/config/container.php
Normal file
5
application/config/container.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
"application/config/container/services.php",
|
||||||
|
"application/config/container/settings.php",
|
||||||
|
];
|
||||||
10
application/config/container/services.php
Normal file
10
application/config/container/services.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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\Infrastructure\Repository\*Repository'),
|
||||||
|
'App\*\Domain\Repository\*RepositoryInterface' => DI\autowire('App\*\Infrastructure\Repository\*Repository'),
|
||||||
|
];
|
||||||
13
application/config/routes/99-main.yaml
Normal file
13
application/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: ""
|
||||||
16
application/config/routes/routes.php
Normal file
16
application/config/routes/routes.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$cashFile = preg_replace("'.application.*$'",'', __DIR__).'/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;
|
||||||
|
}
|
||||||
@@ -11,17 +11,19 @@
|
|||||||
"laminas/laminas-diactoros": "^2.5",
|
"laminas/laminas-diactoros": "^2.5",
|
||||||
"monolog/monolog": "^2.3",
|
"monolog/monolog": "^2.3",
|
||||||
"php-di/php-di": "^6.3",
|
"php-di/php-di": "^6.3",
|
||||||
"symfony/dotenv": "^6.2",
|
"ramsey/uuid": "^4.7",
|
||||||
"rmphp/kernel": "^2.0",
|
"rmphp/content": "^3.1",
|
||||||
"rmphp/router": "^1.0",
|
"rmphp/kernel": "^5.0",
|
||||||
"rmphp/content": "^2.0",
|
"rmphp/router": "^1.2",
|
||||||
"rmphp/storage": "^2.0",
|
"rmphp/session": "^1.1",
|
||||||
"rmphp/session": "^1.0",
|
"rmphp/redis": "^1.0",
|
||||||
"rmphp/cache-file": "^1.0"
|
"rmphp/storage": "^6.0",
|
||||||
|
"symfony/dotenv": "^6.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "src"
|
"App\\": "src",
|
||||||
|
"Base\\": "application/base"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
<?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'),
|
|
||||||
];
|
|
||||||
@@ -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'],
|
|
||||||
];
|
|
||||||
|
|
||||||
@@ -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));
|
|
||||||
@@ -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-width: thin;
|
||||||
scrollbar-color: #CCC #FFF
|
scrollbar-color: #CCC #FFF
|
||||||
@@ -16,3 +22,19 @@ body{font-family: Arimo, sans-serif; font-size: 15px; margin: 0; padding: 0;}
|
|||||||
}
|
}
|
||||||
|
|
||||||
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');
|
(new Symfony\Component\Dotenv\Dotenv())->usePutenv()->loadEnv(dirname(__DIR__).'/.env');
|
||||||
|
|
||||||
error_reporting(0); ini_set('display_errors','Off');
|
if(getenv("APP_MODE") == 'DEBUG'){
|
||||||
if(getenv("APP_MODE") == 'DEV'){
|
|
||||||
error_reporting(E_ALL); ini_set('display_errors','On');
|
error_reporting(E_ALL); ini_set('display_errors','On');
|
||||||
|
} else {
|
||||||
|
error_reporting(0); ini_set('display_errors','Off');
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals();
|
$request = ServerRequestFactory::fromGlobals();
|
||||||
|
|
||||||
$app = new App();
|
$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);
|
(new ResponseEmitter())->emit($response);
|
||||||
|
|
||||||
|
if(($response->getStatusCode() !== 200 && getenv("APP_MODE") == 'DEV') || in_array("Dev", $response->getHeader("App-Mode"))){
|
||||||
if(getenv("APP_MODE") == 'DEV' && in_array("Dev", $response->getHeader("App-Mode"))){
|
|
||||||
$app->syslogger()->dump("Response", $response);
|
$app->syslogger()->dump("Response", $response);
|
||||||
addShutdownInfo($app->syslogger()->getLogs());
|
addShutdownInfo($app->syslogger()->getLogs());
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Common\Services;
|
|
||||||
|
|
||||||
use Rmphp\Kernel\Main;
|
|
||||||
|
|
||||||
class AbstractService extends Main {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
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,25 +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", [
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
catch(ServiceException $exception){}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,38 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="utf-8">
|
||||||
<title>404</title>
|
<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>
|
</head>
|
||||||
<body>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,10 +1,38 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="utf-8">
|
||||||
<title>500</title>
|
<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>
|
</head>
|
||||||
<body>
|
<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>
|
</body>
|
||||||
</html>
|
</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>Hellow</h1>
|
|
||||||
</main>
|
|
||||||
</article>
|
|
||||||
Reference in New Issue
Block a user