Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11756bdfd2 |
No files matched your search
@@ -76,17 +76,6 @@ class FormContext implements FormContextInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formExecute($returnValue) : void
|
|
||||||
{
|
|
||||||
$this->formExecutionStatus = $returnValue;
|
|
||||||
$this->formExecuted = true;
|
|
||||||
|
|
||||||
if ($returnValue) {
|
|
||||||
$this->consumeCsrfToken();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function executed() : bool
|
public function executed() : bool
|
||||||
{
|
{
|
||||||
return $this->formExecutionStatus === false ? false : $this->formExecuted;
|
return $this->formExecutionStatus === false ? false : $this->formExecuted;
|
||||||
@@ -120,17 +109,6 @@ class FormContext implements FormContextInterface
|
|||||||
return $this->formExecutionStatus;
|
return $this->formExecutionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function consumeCsrfToken() {
|
|
||||||
if (! $this->formSkipCsrf) {
|
|
||||||
$token = $this->get('picea-ui-form')[$this->formName] ?? false;
|
|
||||||
|
|
||||||
if ( $token ) {
|
|
||||||
# token is consumed
|
|
||||||
$_SESSION["picea-ui.form:{$this->formName}"] = array_diff($_SESSION["picea-ui.form:{$this->formName}"], [ $token ]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRequest() : ServerRequestInterface
|
public function getRequest() : ServerRequestInterface
|
||||||
{
|
{
|
||||||
return $this->formContextRequest;
|
return $this->formContextRequest;
|
||||||
@@ -248,7 +226,7 @@ class FormContext implements FormContextInterface
|
|||||||
is_null($value) => null,
|
is_null($value) => null,
|
||||||
enum_exists($e) => ( $value instanceof \BackedEnum ? $value : $e::tryFrom($value) ) ?? throw new \InvalidArgumentException(sprintf("Field '\$$property' awaiting values : '%s'.", implode("', '", array_map(fn($e) => $e->value, $e::cases())))),
|
enum_exists($e) => ( $value instanceof \BackedEnum ? $value : $e::tryFrom($value) ) ?? throw new \InvalidArgumentException(sprintf("Field '\$$property' awaiting values : '%s'.", implode("', '", array_map(fn($e) => $e->value, $e::cases())))),
|
||||||
function_exists($e) => $e($value),
|
function_exists($e) => $e($value),
|
||||||
class_exists($e) => is_array($value) ? new $e(...$value) : new $e($value),
|
class_exists($e) => new $e(...$value),
|
||||||
interface_exists($e) => throw new \InvalidArgumentException("There is no way provided to match an interface object yet."),
|
interface_exists($e) => throw new \InvalidArgumentException("There is no way provided to match an interface object yet."),
|
||||||
default => $value
|
default => $value
|
||||||
};
|
};
|
||||||
@@ -260,12 +238,11 @@ class FormContext implements FormContextInterface
|
|||||||
}
|
}
|
||||||
elseif ($types instanceof \ReflectionIntersectionType || $types instanceof \ReflectionUnionType) {
|
elseif ($types instanceof \ReflectionIntersectionType || $types instanceof \ReflectionUnionType) {
|
||||||
foreach($types->getTypes() as $type) {
|
foreach($types->getTypes() as $type) {
|
||||||
$value = $cast($type->getName());
|
return $cast($type->getName());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($types->isBuiltin()) {
|
elseif ($types->isBuiltin()) {
|
||||||
$value = $cast($types->getName());
|
return $cast($types->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class FormHandler {
|
|||||||
|
|
||||||
public bool $validateCsrfToken = true;
|
public bool $validateCsrfToken = true;
|
||||||
|
|
||||||
# in PHP 8.5, value should be taken directly from a property get within $context->formExecutionStatus
|
|
||||||
public /* mixed */ $executionStatus = null;
|
public /* mixed */ $executionStatus = null;
|
||||||
|
|
||||||
public ? bool $validationStatus = null;
|
public ? bool $validationStatus = null;
|
||||||
@@ -50,8 +49,8 @@ class FormHandler {
|
|||||||
|
|
||||||
if ( $this->sent && $this->context->formSent() ) {
|
if ( $this->sent && $this->context->formSent() ) {
|
||||||
if ( $this->validationStatus = $this->form->validate($this->context) ) {
|
if ( $this->validationStatus = $this->form->validate($this->context) ) {
|
||||||
$this->executionStatus = $this->form->execute($this->context);
|
$this->context->formExecutionStatus = $this->executionStatus = $this->form->execute($this->context);
|
||||||
$this->context->formExecute($this->executionStatus);
|
$this->context->formExecuted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user