diff --git a/src/Method/FormContext.php b/src/Method/FormContext.php index 7120270..6f1ca19 100644 --- a/src/Method/FormContext.php +++ b/src/Method/FormContext.php @@ -7,8 +7,10 @@ use Psr\Http\Message\ServerRequestInterface, class FormContext implements FormContextInterface { + public string $method; + public string $formName; - + public bool $formSent = false; public bool $formExecuted = false; @@ -22,7 +24,9 @@ class FormContext implements FormContextInterface public array $messages = []; public bool $skipCsrf = false; - + + protected array $catchedMethods = [ 'POST', 'PUT', 'PATCH', 'DELETE', ]; + public ServerRequestInterface $request; public ? ResponseInterface $response = null; @@ -37,6 +41,8 @@ class FormContext implements FormContextInterface $this->values = $request->getParsedBody() ?: []; + $this->method = $this->request->getMethod(); + if ( ! $this->values ) { $content = mb_convert_encoding((string) $request->getBody(), 'UTF-8'); @@ -66,7 +72,7 @@ class FormContext implements FormContextInterface public function formSent() : bool { - $valid = in_array($this->request->getMethod(), [ 'POST', 'PUT', 'PATCH', 'DELETE', ]); + $valid = in_array($this->method, $this->catchedMethods); if ( ! $this->skipCsrf && ($this->formName ?? false) ) { $token = $this->get('picea-ui-form')[$this->formName] ?? false; @@ -87,6 +93,11 @@ class FormContext implements FormContextInterface return $this->formSent = $valid; } + public function requestMethod() : string + { + return $this->method; + } + public function __set($key, $value) { return $this->set($key, $value); diff --git a/src/Method/FormContextInterface.php b/src/Method/FormContextInterface.php index 13fc1ea..e0ca0c4 100644 --- a/src/Method/FormContextInterface.php +++ b/src/Method/FormContextInterface.php @@ -6,4 +6,6 @@ interface FormContextInterface { public function valid() : bool; public function formSent() : bool; + + public function requestMethod() : string; } \ No newline at end of file