Skip to content

Commit

Permalink
Fixed dispatching in submitting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomFlidr committed Apr 3, 2024
1 parent 6fe3938 commit 13b0858
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/MvcCore/Ext/Form/Dispatching.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ public function DispatchStateCheck ($state, $submit = FALSE) {
// here is always `$this->dispatchState < $state`:
$this->dispatchStateSemaphore = TRUE;

if ($submit === NULL) {
if ($this->submit === NULL)
$this->submit = $this->initDetectSubmit();
$submit = $this->submit;
}
if ($submit === NULL && $this->submit === NULL)
$this->submit = $this->initDetectSubmit();

if ($state > static::DISPATCH_STATE_INITIALIZED)
$this->dispatchMethods(
Expand All @@ -110,28 +107,33 @@ public function DispatchStateCheck ($state, $submit = FALSE) {
}

/**
* Dispatch form template based method.
* This is usually used to call form methods like
* `$form->Init($submit)` or `$form->PreDispatch($submit)`.
* @internal
* @param mixed $methodName
* Called method full name, base values are `Init` or `PreDispatch`.
* @param mixed $targetDispatchState
* Dispatch state, that is required to be completed. Base values are:
* Execute given controller method and move dispatch state.
* This method doesn't check if method exists on given controller context.
* @param \MvcCore\IController $controller
* Any level controller context.
* @param string $methodName
* Controller public method name, possible values are:
* - `Init`,
* - `<action>Init`,
* - `PreDispatch`,
* - `<action>Action`.
* @param int $targetDispatchState
* Dispatch state, that is required to be completed. Possible values are:
* - `\MvcCore\IController::DISPATCH_STATE_INITIALIZED`,
* - `\MvcCore\IController::DISPATCH_STATE_PRE_DISPATCHED`.
* @param bool $submit
* Submit boolean from `Init($submit)` or `PreDispatch($submit)` method.
* `FALSE` by default.
* - `\MvcCore\IController::DISPATCH_STATE_ACTION_INITIALIZED`,
* - `\MvcCore\IController::DISPATCH_STATE_PRE_DISPATCHED`,
* - `\MvcCore\IController::DISPATCH_STATE_ACTION_EXECUTED`.
* @return void
*/
protected function dispatchTemplateMethod ($methodName, $targetDispatchState, $submit = FALSE) {
// Call `PreDispatch()` method only if dispatch state is not pre-dispatched yet:
if ($this->dispatchState < $targetDispatchState) {
// execute template method `Init()` or `PreDispatch()`:
$this->{$methodName}($submit);
// For cases somebody forget to call parent template method:
$this->dispatchMoveState($targetDispatchState);
protected function dispatchMethod (\MvcCore\IController $controller, $methodName, $targetDispatchState) {
if ($targetDispatchState === static::DISPATCH_STATE_ACTION_EXECUTED) {
// This dispatch state is exceptional and it's necessary to set it before execution:
$controller->dispatchMoveState($targetDispatchState);
}
$controller->{$methodName}($this->submit);
if ($targetDispatchState !== static::DISPATCH_STATE_ACTION_EXECUTED) {
// For cases somebody forget to call parent action method:
$controller->dispatchMoveState($targetDispatchState);
}
}

Expand Down

0 comments on commit 13b0858

Please sign in to comment.