20231010#1
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user