- Added request method to context
This commit is contained in:
parent
804deb69a2
commit
0a7b1cdc12
|
@ -7,8 +7,10 @@ use Psr\Http\Message\ServerRequestInterface,
|
||||||
|
|
||||||
class FormContext implements FormContextInterface
|
class FormContext implements FormContextInterface
|
||||||
{
|
{
|
||||||
|
public string $method;
|
||||||
|
|
||||||
public string $formName;
|
public string $formName;
|
||||||
|
|
||||||
public bool $formSent = false;
|
public bool $formSent = false;
|
||||||
|
|
||||||
public bool $formExecuted = false;
|
public bool $formExecuted = false;
|
||||||
|
@ -22,7 +24,9 @@ class FormContext implements FormContextInterface
|
||||||
public array $messages = [];
|
public array $messages = [];
|
||||||
|
|
||||||
public bool $skipCsrf = false;
|
public bool $skipCsrf = false;
|
||||||
|
|
||||||
|
protected array $catchedMethods = [ 'POST', 'PUT', 'PATCH', 'DELETE', ];
|
||||||
|
|
||||||
public ServerRequestInterface $request;
|
public ServerRequestInterface $request;
|
||||||
|
|
||||||
public ? ResponseInterface $response = null;
|
public ? ResponseInterface $response = null;
|
||||||
|
@ -37,6 +41,8 @@ class FormContext implements FormContextInterface
|
||||||
|
|
||||||
$this->values = $request->getParsedBody() ?: [];
|
$this->values = $request->getParsedBody() ?: [];
|
||||||
|
|
||||||
|
$this->method = $this->request->getMethod();
|
||||||
|
|
||||||
if ( ! $this->values ) {
|
if ( ! $this->values ) {
|
||||||
$content = mb_convert_encoding((string) $request->getBody(), 'UTF-8');
|
$content = mb_convert_encoding((string) $request->getBody(), 'UTF-8');
|
||||||
|
|
||||||
|
@ -66,7 +72,7 @@ class FormContext implements FormContextInterface
|
||||||
|
|
||||||
public function formSent() : bool
|
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) ) {
|
if ( ! $this->skipCsrf && ($this->formName ?? false) ) {
|
||||||
$token = $this->get('picea-ui-form')[$this->formName] ?? false;
|
$token = $this->get('picea-ui-form')[$this->formName] ?? false;
|
||||||
|
@ -87,6 +93,11 @@ class FormContext implements FormContextInterface
|
||||||
return $this->formSent = $valid;
|
return $this->formSent = $valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function requestMethod() : string
|
||||||
|
{
|
||||||
|
return $this->method;
|
||||||
|
}
|
||||||
|
|
||||||
public function __set($key, $value)
|
public function __set($key, $value)
|
||||||
{
|
{
|
||||||
return $this->set($key, $value);
|
return $this->set($key, $value);
|
||||||
|
|
|
@ -6,4 +6,6 @@ interface FormContextInterface {
|
||||||
public function valid() : bool;
|
public function valid() : bool;
|
||||||
|
|
||||||
public function formSent() : bool;
|
public function formSent() : bool;
|
||||||
|
|
||||||
|
public function requestMethod() : string;
|
||||||
}
|
}
|
Loading…
Reference in New Issue