TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Form\Domain\Runtime\Exception;
|
||||
|
||||
use TYPO3\CMS\Form\Domain\Exception;
|
||||
|
||||
/**
|
||||
* This Exception is thrown in the FormRuntime if the PropertyMapper throws
|
||||
* a \TYPO3\CMS\Extbase\Property\Exception. It adds some more Information to
|
||||
* better understand why the PropertyMapper failed to map the properties
|
||||
*/
|
||||
class PropertyMappingException extends Exception {}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
|
||||
|
||||
use TYPO3\CMS\Core\Crypto\HashAlgo;
|
||||
use TYPO3\CMS\Core\Crypto\HashService;
|
||||
use TYPO3\CMS\Core\Crypto\Random;
|
||||
use TYPO3\CMS\Core\Error\Http\BadRequestException;
|
||||
use TYPO3\CMS\Core\Exception\Crypto\InvalidHashStringException;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Form\Security\HashScope;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class FormSession
|
||||
{
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Factory to create the form session from the current state
|
||||
*
|
||||
* @param string|null $authenticatedIdentifier
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function __construct(?string $authenticatedIdentifier = null)
|
||||
{
|
||||
if ($authenticatedIdentifier === null) {
|
||||
$this->identifier = $this->generateIdentifier();
|
||||
} else {
|
||||
$this->identifier = $this->validateIdentifier($authenticatedIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumed by TYPO3\CMS\Form\ViewHelpers\FormViewHelper
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getAuthenticatedIdentifier(): string
|
||||
{
|
||||
return GeneralUtility::makeInstance(HashService::class)
|
||||
// restrict string expansion by adding some char ('|')
|
||||
->appendHmac($this->identifier . '|', HashScope::FormSession->prefix(), HashAlgo::SHA3_256);
|
||||
}
|
||||
|
||||
protected function generateIdentifier(): string
|
||||
{
|
||||
return GeneralUtility::makeInstance(Random::class)->generateRandomHexString(40);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
protected function validateIdentifier(string $authenticatedIdentifier): string
|
||||
{
|
||||
try {
|
||||
$identifier = GeneralUtility::makeInstance(HashService::class)
|
||||
->validateAndStripHmac($authenticatedIdentifier, HashScope::FormSession->prefix(), HashAlgo::SHA3_256);
|
||||
return rtrim($identifier, '|');
|
||||
} catch (InvalidHashStringException $e) {
|
||||
throw new BadRequestException('The HMAC of the form session could not be validated.', 1613300274);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/*
|
||||
* Inspired by and partially taken from the Neos.Form package (www.neos.io)
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Form\Domain\Runtime;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
||||
|
||||
/**
|
||||
* The current state of the form which is attached to the {@link FormRuntime}
|
||||
* and saved in a session or the client.
|
||||
*
|
||||
* Scope: frontend
|
||||
* **This class is NOT meant to be sub classed by developers.**
|
||||
* @internal
|
||||
*/
|
||||
class FormState
|
||||
{
|
||||
/**
|
||||
* Constant which means that we are currently not on any page; i.e. the form
|
||||
* has never rendered before.
|
||||
*/
|
||||
public const NOPAGE = -1;
|
||||
|
||||
/**
|
||||
* The last displayed page index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lastDisplayedPageIndex = self::NOPAGE;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $formValues = [];
|
||||
|
||||
/**
|
||||
* @return bool FALSE if the form has never been submitted before, TRUE otherwise
|
||||
*/
|
||||
public function isFormSubmitted(): bool
|
||||
{
|
||||
return $this->lastDisplayedPageIndex !== self::NOPAGE;
|
||||
}
|
||||
|
||||
public function getLastDisplayedPageIndex(): int
|
||||
{
|
||||
return $this->lastDisplayedPageIndex;
|
||||
}
|
||||
|
||||
public function setLastDisplayedPageIndex(int $lastDisplayedPageIndex)
|
||||
{
|
||||
$this->lastDisplayedPageIndex = $lastDisplayedPageIndex;
|
||||
}
|
||||
|
||||
public function getFormValues(): array
|
||||
{
|
||||
return $this->formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setFormValue(string $propertyPath, $value)
|
||||
{
|
||||
$this->formValues = ArrayUtility::setValueByPath(
|
||||
$this->formValues,
|
||||
$propertyPath,
|
||||
$value,
|
||||
'.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFormValue(string $propertyPath)
|
||||
{
|
||||
try {
|
||||
return ArrayUtility::getValueByPath($this->formValues, $propertyPath, '.');
|
||||
} catch (MissingArrayPathException $exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user