- Ignore most method of ControllerTrait
This commit is contained in:
parent
45ffc6e128
commit
34ca18f34c
|
@ -3,6 +3,7 @@
|
||||||
namespace Lean;
|
namespace Lean;
|
||||||
|
|
||||||
use Lean\Factory\HttpFactory;
|
use Lean\Factory\HttpFactory;
|
||||||
|
use Notes\Attribute\Ignore;
|
||||||
use Notes\Route\Attribute\Object\Route;
|
use Notes\Route\Attribute\Object\Route;
|
||||||
use Notes\Security\Attribute\Security;
|
use Notes\Security\Attribute\Security;
|
||||||
use Picea, Picea\Ui\Method\FormContext;
|
use Picea, Picea\Ui\Method\FormContext;
|
||||||
|
@ -26,6 +27,7 @@ trait ControllerTrait {
|
||||||
|
|
||||||
public array $contextList = [];
|
public array $contextList = [];
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface
|
public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface
|
||||||
{
|
{
|
||||||
foreach($entityClass::repository()->filterServerRequest( $entityClass::searchRequest()->fromRequest($request->withQueryParams($request->getQueryParams() + ['limit' => PHP_INT_MAX,])) )->loadAll() as $entity) {
|
foreach($entityClass::repository()->filterServerRequest( $entityClass::searchRequest()->fromRequest($request->withQueryParams($request->getQueryParams() + ['limit' => PHP_INT_MAX,])) )->loadAll() as $entity) {
|
||||||
|
@ -35,6 +37,7 @@ trait ControllerTrait {
|
||||||
return $this->renderJson( array_filter($data ?? [], function($row) { return $row !== null; }));
|
return $this->renderJson( array_filter($data ?? [], function($row) { return $row !== null; }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderRawView(string $view, ?array $variables = null) : string
|
public function renderRawView(string $view, ?array $variables = null) : string
|
||||||
{
|
{
|
||||||
if ( null === $content = $this->picea->renderHtml($view, $variables ?? [], $this) ) {
|
if ( null === $content = $this->picea->renderHtml($view, $variables ?? [], $this) ) {
|
||||||
|
@ -44,6 +47,7 @@ trait ControllerTrait {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderView(string $view, ?array $variables = null) : ResponseInterface
|
public function renderView(string $view, ?array $variables = null) : ResponseInterface
|
||||||
{
|
{
|
||||||
return static::renderHtml(
|
return static::renderHtml(
|
||||||
|
@ -51,6 +55,7 @@ trait ControllerTrait {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderError(string $errorCode, ?array $variables = null) : ResponseInterface
|
public function renderError(string $errorCode, ?array $variables = null) : ResponseInterface
|
||||||
{
|
{
|
||||||
return static::renderHtml(
|
return static::renderHtml(
|
||||||
|
@ -58,55 +63,66 @@ trait ControllerTrait {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderDocumentation(string $filename) : ResponseInterface
|
public function renderDocumentation(string $filename) : ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->renderMarkdown( file_get_contents(getenv("PROJECT_PATH") . "/meta/doc/$filename.md") );
|
return $this->renderMarkdown( file_get_contents(getenv("PROJECT_PATH") . "/meta/doc/$filename.md") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
protected function redirect(string $url, int $code = 302, array $headers = []) {
|
protected function redirect(string $url, int $code = 302, array $headers = []) {
|
||||||
return HttpFactory::createRedirectResponse($url, $code, $headers);
|
return HttpFactory::createRedirectResponse($url, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderNothing(int $code = 204, array $headers = []) : ResponseInterface
|
public static function renderNothing(int $code = 204, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createEmptyResponse($code, $headers);
|
return HttpFactory::createEmptyResponse($code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderText(string $text, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderText(string $text, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createTextResponse($text, $code, $headers);
|
return HttpFactory::createTextResponse($text, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderHtml(string $html, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderHtml(string $html, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createHtmlResponse($html, $code, $headers);
|
return HttpFactory::createHtmlResponse($html, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderJson(mixed $data, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderJson(mixed $data, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createJsonResponse($data, $code, $headers);
|
return HttpFactory::createJsonResponse($data, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderPdf($rawdata, int $status = 200, array $headers = []) : ResponseInterface
|
public function renderPdf($rawdata, int $status = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createPdfResponse($rawdata, $status, $headers);
|
return HttpFactory::createPdfResponse($rawdata, $status, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createDownloadableResponse($data, $filename, $code, $headers);
|
return HttpFactory::createDownloadableResponse($data, $filename, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderImage(string $data, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderImage(string $data, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createImageResponse($data, $code, $headers);
|
return HttpFactory::createImageResponse($data, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public static function renderAsset(string $path, int $code = 200, array $headers = []) : ResponseInterface
|
public static function renderAsset(string $path, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
return HttpFactory::createFileDownloadResponse($path, $code, $headers);
|
return HttpFactory::createFileDownloadResponse($path, $code, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderMarkdown(string $filepath, int $code = 200, array $headers = []) : ResponseInterface
|
public function renderMarkdown(string $filepath, int $code = 200, array $headers = []) : ResponseInterface
|
||||||
{
|
{
|
||||||
if ( ! class_exists(CommonMarkConverter::class)) {
|
if ( ! class_exists(CommonMarkConverter::class)) {
|
||||||
|
@ -118,6 +134,7 @@ trait ControllerTrait {
|
||||||
return $this->renderView("docs", get_defined_vars());
|
return $this->renderView("docs", get_defined_vars());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
|
public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface
|
||||||
{
|
{
|
||||||
if ($data instanceof \JsonSerializable ) {
|
if ($data instanceof \JsonSerializable ) {
|
||||||
|
@ -134,6 +151,7 @@ trait ControllerTrait {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function fromResponse(ResponseInterface $response)
|
public function fromResponse(ResponseInterface $response)
|
||||||
{
|
{
|
||||||
if ( $response->getStatusCode() === 200 ) {
|
if ( $response->getStatusCode() === 200 ) {
|
||||||
|
@ -145,6 +163,7 @@ trait ControllerTrait {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function asset(string $url, array $parameters = []) : string
|
public function asset(string $url, array $parameters = []) : string
|
||||||
{
|
{
|
||||||
if (! $this->picea ) {
|
if (! $this->picea ) {
|
||||||
|
@ -154,6 +173,7 @@ trait ControllerTrait {
|
||||||
return $this->picea->compiler->getExtensionFromToken('asset')->buildAssetUrl($url, $parameters);
|
return $this->picea->compiler->getExtensionFromToken('asset')->buildAssetUrl($url, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function url(string $url, array $parameters = []) : string
|
public function url(string $url, array $parameters = []) : string
|
||||||
{
|
{
|
||||||
if (! $this->picea ) {
|
if (! $this->picea ) {
|
||||||
|
@ -163,6 +183,7 @@ trait ControllerTrait {
|
||||||
return $this->picea->compiler->getExtensionFromToken('url')->buildUrl($url, $parameters);
|
return $this->picea->compiler->getExtensionFromToken('url')->buildUrl($url, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function route(string $name, array $parameters = []) : string
|
public function route(string $name, array $parameters = []) : string
|
||||||
{
|
{
|
||||||
if (! $this->picea ) {
|
if (! $this->picea ) {
|
||||||
|
@ -172,11 +193,13 @@ trait ControllerTrait {
|
||||||
return $this->picea->compiler->getExtensionFromToken('route')->buildRouteUrl($name, $parameters);
|
return $this->picea->compiler->getExtensionFromToken('route')->buildRouteUrl($name, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function json($data, int $flags = 0) : string
|
public function json($data, int $flags = 0) : string
|
||||||
{
|
{
|
||||||
return htmlentities(json_encode($data, $flags), ENT_QUOTES, 'UTF-8');
|
return htmlentities(json_encode($data, $flags), ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function pushContext(FormContext $context) : FormContext
|
public function pushContext(FormContext $context) : FormContext
|
||||||
{
|
{
|
||||||
$this->contextList[$context->formName ?? uniqid("context_")] = $context;
|
$this->contextList[$context->formName ?? uniqid("context_")] = $context;
|
||||||
|
@ -184,11 +207,13 @@ trait ControllerTrait {
|
||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function context(? string $name = null) : ? FormContext
|
public function context(? string $name = null) : ? FormContext
|
||||||
{
|
{
|
||||||
return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null;
|
return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Ignore]
|
||||||
public function isRoute(mixed $name, ServerRequestInterface $request) : bool
|
public function isRoute(mixed $name, ServerRequestInterface $request) : bool
|
||||||
{
|
{
|
||||||
foreach((array) $name as $item) {
|
foreach((array) $name as $item) {
|
||||||
|
|
Loading…
Reference in New Issue