Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
035783e264 | ||
|
|
cdf9a13242 | ||
|
|
7df5be904f | ||
|
|
34de164e72 | ||
|
|
19731cb6fe | ||
|
|
4c087a156b | ||
|
|
4ea833db5a |
21
.env.dist
21
.env.dist
@@ -8,24 +8,15 @@
|
|||||||
#
|
#
|
||||||
# Real environment variables win over .env files.
|
# Real environment variables win over .env files.
|
||||||
|
|
||||||
# App mode (DEV, TEST, PROD)
|
|
||||||
APP_MODE=DEV
|
APP_MODE=DEV
|
||||||
|
APP_COMPONENTS_FILE=config/app.php
|
||||||
# Including file with array of componens
|
APP_NODES_FILE=config/nodes.php
|
||||||
APP_COMPONENTS_FILE="config/components.php"
|
CONTAINER_DIR=config/container
|
||||||
|
CONTAINER_CACHE=var/cache/container
|
||||||
# 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"}'
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
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}'
|
||||||
@@ -7,13 +7,7 @@ Stable version
|
|||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton
|
composer create-project rmphp/skeleton
|
||||||
```
|
```
|
||||||
```bash
|
|
||||||
composer create-project rmphp/skeleton:"^1.0"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Dev version contains the latest changes
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton:"1.0.x-dev"
|
composer create-project rmphp/skeleton:"^3.0"
|
||||||
```
|
```
|
||||||
@@ -12,10 +12,12 @@
|
|||||||
"monolog/monolog": "^2.3",
|
"monolog/monolog": "^2.3",
|
||||||
"php-di/php-di": "^6.3",
|
"php-di/php-di": "^6.3",
|
||||||
"symfony/dotenv": "^6.2",
|
"symfony/dotenv": "^6.2",
|
||||||
"rmphp/kernel": "^1.0",
|
"rmphp/kernel": "^3.0",
|
||||||
"rmphp/router": "^1.0",
|
"rmphp/router": "^1.0",
|
||||||
"rmphp/content": "^1.0",
|
"rmphp/content": "^2.0",
|
||||||
"rmphp/storage": "^1.0"
|
"rmphp/storage": "^2.0",
|
||||||
|
"rmphp/session": "^1.0",
|
||||||
|
"rmphp/cache-file": "^1.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -30,6 +32,7 @@
|
|||||||
"process-timeout":0
|
"process-timeout":0
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"symfony/var-dumper": "^5.3",
|
||||||
"rmphp/var-damper": "^1.0"
|
"rmphp/var-damper": "^1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Rmphp\Storage\MysqlStorage;
|
use Rmphp\Cache\Cache;
|
||||||
use Rmphp\Storage\MysqlStorageInterface;
|
use Rmphp\Cache\CacheInterface;
|
||||||
|
use Rmphp\Session\Session;
|
||||||
|
use Rmphp\Session\SessionInterface;
|
||||||
|
use Rmphp\Storage\Mysql\MysqlStorage;
|
||||||
|
use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
MysqlStorageInterface::class => DI\create(MysqlStorage::class)->constructor(json_decode(getenv("MYSQL_PARAM"), true)),
|
||||||
|
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\*\Repository\Mysql\*Repository'),
|
||||||
'App\*\Services\*\*Service' => DI\autowire('App\*\Services\*\*Service'),
|
|
||||||
'App\*\Services\*Service' => DI\autowire('App\*\Services\*Service'),
|
|
||||||
];
|
];
|
||||||
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
use DI\ContainerBuilder;
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
$containerDir = (getenv("CONTAINER_DIR"))?:"config/container/";
|
$containerDir = (getenv("CONTAINER_DIR"))?:"config/container";
|
||||||
|
$containerCache = (getenv("CONTAINER_CACHE"))?:"var/cache/container";
|
||||||
|
|
||||||
$dependencies = glob(dirname(__DIR__,2)."/".$containerDir."/*.php");
|
$dependencies = glob(dirname(__DIR__,2)."/".$containerDir."/*.php");
|
||||||
|
|
||||||
$dependenciesCollection = array_map(function ($dependenciesFile){
|
$dependenciesCollection = array_map(function ($dependenciesFile){
|
||||||
return require $dependenciesFile;
|
return require $dependenciesFile;
|
||||||
}, $dependencies);
|
}, $dependencies);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$builder = new ContainerBuilder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->enableCompilation(__DIR__ . '/../../var/cache/container');
|
if(getenv("APP_MODE") != "DEV") $builder->enableCompilation(dirname(__DIR__,2)."/".$containerCache);
|
||||||
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
$builder->addDefinitions(array_replace_recursive(...$dependenciesCollection));
|
||||||
return $builder->build();
|
return $builder->build();
|
||||||
} catch (Exception $e) {echo $e->getMessage();}
|
} catch (Exception $e) {echo $e->getMessage();}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
|
|
||||||
# Example:
|
# Example:
|
||||||
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
# ['key'=>'/', "action"=>"App\\Main\\Controllers\\IndexController", "method"=>"index"],
|
||||||
# ['key'=>'/', 'router'=>'config/routes/main/collection.php'],
|
# ['key'=>'/', 'router'=>'config/routes/main/routes.php'],
|
||||||
# ['key'=>'/', 'router'=>'config/routes/main.json']
|
|
||||||
# ['key'=>'/', 'router'=>'config/routes/main.yaml'],
|
# ['key'=>'/', 'router'=>'config/routes/main.yaml'],
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -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": ""}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -23,7 +23,7 @@ $response = $app->handler($request, (new Response())->withHeader("Content-Type",
|
|||||||
(new ResponseEmitter())->emit($response);
|
(new ResponseEmitter())->emit($response);
|
||||||
|
|
||||||
|
|
||||||
if(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());
|
||||||
}
|
}
|
||||||
@@ -6,38 +6,30 @@ use Laminas\Diactoros\Response\HtmlResponse;
|
|||||||
use Laminas\Diactoros\Response\JsonResponse;
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
use Laminas\Diactoros\Response\RedirectResponse;
|
use Laminas\Diactoros\Response\RedirectResponse;
|
||||||
use Laminas\Diactoros\Response\TextResponse;
|
use Laminas\Diactoros\Response\TextResponse;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Rmphp\Foundation\Exceptions\AppException;
|
||||||
use Rmphp\Kernel\Main;
|
use Rmphp\Kernel\Main;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
abstract class AbstractController extends Main {
|
abstract class AbstractController extends Main {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param Throwable $throwable
|
||||||
* @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 array $data
|
* @param array $data
|
||||||
* @return void
|
* @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);
|
$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 $name
|
||||||
@@ -65,7 +57,6 @@ abstract class AbstractController extends Main {
|
|||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function textResponse($text, int $status = 200, array $headers = []) : 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));
|
return new TextResponse($text, $status, array_merge($this->globals()->response()->getHeaders(), $headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +67,6 @@ abstract class AbstractController extends Main {
|
|||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function jsonResponse(array $array, int $status = 200, array $headers = []) : 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);
|
return new JsonResponse($array, $status, array_merge($this->globals()->response()->getHeaders(), $headers), JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,8 +77,67 @@ abstract class AbstractController extends Main {
|
|||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function redirectResponse(string $url, int $status = 302, array $headers = []) : 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));
|
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 $string
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTemplateValue(string $point, string $string) : void {
|
||||||
|
$this->template()->setValue($point, $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $point
|
||||||
|
* @param string $string
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addTemplateValue(string $point, string $string) : void {
|
||||||
|
$this->template()->addValue($point, $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $point
|
||||||
|
* @param string $subTempl
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $point
|
||||||
|
* @param string $subtemplate
|
||||||
|
* @param array $data
|
||||||
|
* @param int $status
|
||||||
|
* @param array $headers
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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>"
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Main\Controllers;
|
namespace App\Main\Controllers;
|
||||||
use App\Common\Controllers\AbstractPageController;
|
use App\Common\Controllers\AbstractController;
|
||||||
use App\Common\Services\ServiceException;
|
use App\Common\Services\ServiceException;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
|
||||||
class IndexController extends AbstractPageController {
|
class IndexController extends AbstractController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|ResponseInterface
|
* @return bool|ResponseInterface
|
||||||
@@ -16,7 +16,9 @@ class IndexController extends AbstractPageController {
|
|||||||
$this->addHeader("App-Mode", "Dev");
|
$this->addHeader("App-Mode", "Dev");
|
||||||
$this->template()->setValue("title", "Главная");
|
$this->template()->setValue("title", "Главная");
|
||||||
$this->template()->setSubtemple("main", "main/index.tpl", [
|
$this->template()->setSubtemple("main", "main/index.tpl", [
|
||||||
|
"date" => (new \DateTime())->format('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
|
return $this->renderResponse();
|
||||||
}
|
}
|
||||||
catch(ServiceException $exception){}
|
catch(ServiceException $exception){}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<article>
|
<article>
|
||||||
<main>
|
<main>
|
||||||
<h1>Hellow</h1>
|
<h1>Hello. Now is <?=$this->date?></h1>
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
Reference in New Issue
Block a user