Init
This commit is contained in:
0
src/Common/Components/.gitkeep
Normal file
0
src/Common/Components/.gitkeep
Normal file
94
src/Common/Controllers/AbstractController.php
Normal file
94
src/Common/Controllers/AbstractController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Controllers;
|
||||
|
||||
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;
|
||||
|
||||
abstract class AbstractController 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 array $data
|
||||
* @return void
|
||||
*/
|
||||
public function logException(\Throwable $throwable, array $data = []) : void {
|
||||
$this->logger()->warning($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 {
|
||||
$this->container()->set("showDebugLogs", false);
|
||||
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 {
|
||||
$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));
|
||||
}
|
||||
|
||||
}
|
||||
38
src/Common/Controllers/AbstractPageController.php
Normal file
38
src/Common/Controllers/AbstractPageController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Controllers;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
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>"
|
||||
]);
|
||||
}
|
||||
}
|
||||
7
src/Common/Controllers/NotFoundException.php
Normal file
7
src/Common/Controllers/NotFoundException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Controllers;
|
||||
|
||||
class NotFoundException extends \Exception {
|
||||
|
||||
}
|
||||
0
src/Common/Domain/.gitkeep
Normal file
0
src/Common/Domain/.gitkeep
Normal file
15
src/Common/Repository/RepositoryException.php
Normal file
15
src/Common/Repository/RepositoryException.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Repository;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class RepositoryException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
public function __construct($message="", $code=0, array $data = [], Throwable $previous=null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
10
src/Common/Services/AbstractService.php
Normal file
10
src/Common/Services/AbstractService.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Common\Services;
|
||||
|
||||
use Rmphp\Kernel\Main;
|
||||
|
||||
class AbstractService extends Main {
|
||||
|
||||
|
||||
}
|
||||
16
src/Common/Services/ServiceException.php
Normal file
16
src/Common/Services/ServiceException.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Common\Services;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class ServiceException extends \Exception {
|
||||
|
||||
public array $data;
|
||||
|
||||
public function __construct($message="", $code=0, array $data = [], Throwable $previous=null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
0
src/Main/Components/.gitkeep
Normal file
0
src/Main/Components/.gitkeep
Normal file
25
src/Main/Controllers/IndexController.php
Normal file
25
src/Main/Controllers/IndexController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
0
src/Main/Domain/.gitkeep
Normal file
0
src/Main/Domain/.gitkeep
Normal file
0
src/Main/Repository/DTO/.gitkeep
Normal file
0
src/Main/Repository/DTO/.gitkeep
Normal file
0
src/Main/Repository/Interface/.gitkeep
Normal file
0
src/Main/Repository/Interface/.gitkeep
Normal file
0
src/Main/Repository/Mysql/.gitkeep
Normal file
0
src/Main/Repository/Mysql/.gitkeep
Normal file
0
src/Main/Services/.gitkeep
Normal file
0
src/Main/Services/.gitkeep
Normal file
Reference in New Issue
Block a user