-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from neos/feature/simple-form-initializer
FEATURE: Make formState initialization extendable
- Loading branch information
Showing
7 changed files
with
92 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Form\FormState; | ||
|
||
/* | ||
* This file is part of the Neos.Form package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Flow\Security\Cryptography\HashService; | ||
use Neos\Form\Core\Model\FormDefinition; | ||
use Neos\Form\Core\Runtime\FormState; | ||
|
||
class DefaultFormStateInitializer implements FormStateInitializerInterface | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var HashService | ||
*/ | ||
protected $hashService; | ||
|
||
public function initializeFormState(FormDefinition $formDefinition, ActionRequest $actionRequest): FormState | ||
{ | ||
$serializedFormStateWithHmac = $actionRequest->getInternalArgument('__state'); | ||
if ($serializedFormStateWithHmac !== null) { | ||
$serializedFormState = $this->hashService->validateAndStripHmac($serializedFormStateWithHmac); | ||
/** @noinspection UnserializeExploitsInspection The unserialize call is safe because of the HMAC check above */ | ||
return unserialize(base64_decode($serializedFormState)); | ||
} | ||
|
||
return new FormState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Form\FormState; | ||
|
||
/* | ||
* This file is part of the Neos.Form package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Form\Core\Model\FormDefinition; | ||
use Neos\Form\Core\Runtime\FormState; | ||
|
||
interface FormStateInitializerInterface | ||
{ | ||
public function initializeFormState(FormDefinition $formDefinition, ActionRequest $actionRequest): FormState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters