1<?php
2
3declare(strict_types=1);
4
5/*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18namespace TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators;
19
20use TYPO3\CMS\Core\Utility\GeneralUtility;
21use TYPO3\CMS\Extbase\Object\ObjectManager;
22use TYPO3\CMS\Form\Domain\Configuration\ConfigurationService;
23use TYPO3\CMS\Form\Domain\Configuration\FormDefinitionValidationService;
24
25/**
26 * @internal
27 */
28abstract class AbstractValidator implements ValidatorInterface
29{
30
31    /**
32     * @var ConfigurationService
33     */
34    protected $configurationService;
35
36    /**
37     * @var array
38     */
39    protected $currentElement;
40
41    /**
42     * @var string
43     */
44    protected $sessionToken;
45
46    /**
47     * @var ValidationDto
48     */
49    protected $validationDto;
50
51    /**
52     * @param array $currentElement
53     * @param string $sessionToken
54     * @param ValidationDto $validationDto
55     */
56    public function __construct(array $currentElement, string $sessionToken, ValidationDto $validationDto)
57    {
58        $this->currentElement = $currentElement;
59        $this->sessionToken = $sessionToken;
60        $this->validationDto = $validationDto;
61    }
62
63    /**
64     * Builds the path in which the hmac value is expected based on the property path.
65     *
66     * @param string $propertyPath
67     * @return string
68     */
69    protected function buildHmacDataPath(string $propertyPath): string
70    {
71        $pathParts = explode('.', $propertyPath);
72        $lastPathSegment = array_pop($pathParts);
73        $pathParts[] = '_orig_' . $lastPathSegment;
74
75        return implode('.', $pathParts);
76    }
77
78    /**
79     * @return FormDefinitionValidationService
80     */
81    protected function getFormDefinitionValidationService(): FormDefinitionValidationService
82    {
83        return GeneralUtility::makeInstance(FormDefinitionValidationService::class);
84    }
85
86    /**
87     * @return ConfigurationService
88     */
89    protected function getConfigurationService(): ConfigurationService
90    {
91        if (!($this->configurationService instanceof ConfigurationService)) {
92            $this->configurationService = $this->getObjectManager()->get(ConfigurationService::class);
93        }
94        return $this->configurationService;
95    }
96
97    /**
98     * @return ObjectManager
99     */
100    protected function getObjectManager(): ObjectManager
101    {
102        return GeneralUtility::makeInstance(ObjectManager::class);
103    }
104}
105