1 Commits
2.1 ... 2.x

Author SHA1 Message Date
User
cdf9a13242 20231010#1 2023-10-10 23:13:19 +03:00
6 changed files with 48 additions and 49 deletions

View File

@@ -15,7 +15,9 @@
"rmphp/kernel": "^2.0",
"rmphp/router": "^1.0",
"rmphp/content": "^2.0",
"rmphp/storage": "^1.0"
"rmphp/storage": "^2.0",
"rmphp/session": "^1.0",
"rmphp/cache-file": "^1.0"
},
"autoload": {
"psr-4": {

View File

@@ -1,9 +1,15 @@
<?php
use Rmphp\Storage\MysqlStorage;
use Rmphp\Storage\MysqlStorageInterface;
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'),
];

View File

@@ -23,7 +23,7 @@ $response = $app->handler($request, (new Response())->withHeader("Content-Type",
(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);
addShutdownInfo($app->syslogger()->getLogs());
}

View File

@@ -6,22 +6,29 @@ 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 {
/**
* @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
@@ -49,7 +56,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));
}
@@ -60,7 +66,6 @@ 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);
}
@@ -71,8 +76,30 @@ abstract class AbstractController extends Main {
* @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));
}
/**
* @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 $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));
}
}

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,12 +1,12 @@
<?php
namespace App\Main\Controllers;
use App\Common\Controllers\AbstractPageController;
use App\Common\Controllers\AbstractController;
use App\Common\Services\ServiceException;
use Psr\Http\Message\ResponseInterface;
class IndexController extends AbstractPageController {
class IndexController extends AbstractController {
/**
* @return bool|ResponseInterface