From ff57fed6994af0d3b66545b9f4f05aa7b2638586 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 31 Mar 2020 11:09:08 -0400 Subject: [PATCH] - Fixed a bug where a custom form context would never be applied --- src/Component/UiPopup.php | 4 +-- src/Method/Form.php | 2 +- src/Method/FormHandler.php | 6 ++-- src/Method/Message/ErrorMessage.php | 2 +- src/Method/Pagination.php | 37 +++++++++++++++++++++++ src/Method/PaginationHandler.php | 47 +++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 src/Method/Pagination.php create mode 100644 src/Method/PaginationHandler.php diff --git a/src/Component/UiPopup.php b/src/Component/UiPopup.php index 4c0b692..e9a794e 100644 --- a/src/Component/UiPopup.php +++ b/src/Component/UiPopup.php @@ -19,12 +19,12 @@ class UiPopup extends UiElement implements Extension { public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string { - return "buildAttributes($arguments) ?>"; + return "buildAttributes($arguments) . '\"' ?>"; } public function buildAttributes(string $name, array $variables = []) : string { - return json_encode([ "name" => $name, "vars" => $variables ], JSON_HEX_APOS | JSON_HEX_QUOT); + return htmlentities(json_encode([ "name" => $name, "vars" => $variables ], JSON_HEX_APOS | JSON_HEX_QUOT), ENT_QUOTES, 'UTF-8'); } } diff --git a/src/Method/Form.php b/src/Method/Form.php index 0f6a253..256e0ef 100644 --- a/src/Method/Form.php +++ b/src/Method/Form.php @@ -50,6 +50,6 @@ class Form implements Extension { public function formClass(FormInterface $form, ? FormContext $formContext = null) : FormHandler { - return new FormHandler($this->request, $form, $formContext ?? $this->formContext ?? null); + return new FormHandler($this->request, $form, $formContext); } } diff --git a/src/Method/FormHandler.php b/src/Method/FormHandler.php index 64acb60..a6a821d 100644 --- a/src/Method/FormHandler.php +++ b/src/Method/FormHandler.php @@ -7,6 +7,8 @@ use Psr\Http\Message\ServerRequestInterface; class FormHandler { public bool $sent = false; + public ? bool $executionStatus = null; + public FormContext $context; protected ServerRequestInterface $request; @@ -18,7 +20,7 @@ class FormHandler { $this->request = $request; $this->sent = $this->requestSent(); $this->form = $form; - + if ( $context ) { $this->context = $context; } @@ -45,7 +47,7 @@ class FormHandler { if ( $this->sent ) { if ( $this->form->validate($this->context) ) { - $this->form->execute($this->context); + $this->executionStatus = $this->form->execute($this->context); } } } diff --git a/src/Method/Message/ErrorMessage.php b/src/Method/Message/ErrorMessage.php index 799fe66..f66506a 100644 --- a/src/Method/Message/ErrorMessage.php +++ b/src/Method/Message/ErrorMessage.php @@ -2,7 +2,7 @@ namespace Picea\Ui\Method\Message; -use Picea\Ui\Metohd\FormMessage; +use Picea\Ui\Method\FormMessage; class ErrorMessage implements FormMessage { diff --git a/src/Method/Pagination.php b/src/Method/Pagination.php new file mode 100644 index 0000000..c5a5216 --- /dev/null +++ b/src/Method/Pagination.php @@ -0,0 +1,37 @@ +request = $request; + $this->register($context); + } + + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string { } + + public function register(Context $context) : void + { + $context->pushFunction("pagination", [ $this, 'paginationClass' ]); + } + + public function paginationClass(string $name, ?string $url = null, ?array $params = null) : PaginationHandler + { + return new PaginationHandler($this->request, $name, $url, $params); + } +} diff --git a/src/Method/PaginationHandler.php b/src/Method/PaginationHandler.php new file mode 100644 index 0000000..46dfe9c --- /dev/null +++ b/src/Method/PaginationHandler.php @@ -0,0 +1,47 @@ +request = $request; + + $query = $request->getQueryParams(); + + $this->page = $query['page'] ?? 1; + $this->limit = 15; + $this->offset = 1; + $this->count = $this->page * $this->limit; + + if ( $url ) { + $this->url = $url; + } + + $this->params = $params ?? []; + } + + public function __toString() { + return "hello world"; + } + +}