|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* 2017 Romain CANON <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU General Public License, either |
|
8
|
|
|
* version 3 of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, see: |
|
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Romm\Formz\Persistence; |
|
15
|
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor; |
|
17
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface; |
|
18
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
|
19
|
|
|
use Romm\Formz\Form\Service\DataObject\FormIdentifierObject; |
|
20
|
|
|
use Romm\Formz\Persistence\Option\AbstractOptionDefinition; |
|
21
|
|
|
|
|
22
|
|
|
abstract class AbstractPersistence implements PersistenceInterface, DataPreProcessorInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var int |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $priority = 0; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* This is the default option class, this property can be overridden in |
|
31
|
|
|
* child classes to be mapped to another option definition. |
|
32
|
|
|
* |
|
33
|
|
|
* @var \Romm\Formz\Persistence\Option\DefaultOptionDefinition |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $options; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param AbstractOptionDefinition $options |
|
39
|
|
|
*/ |
|
40
|
|
|
final public function __construct(AbstractOptionDefinition $options) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->options = $options; |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Override if needed. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function initialize() |
|
49
|
|
|
{ |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the priority of the middleware. The higher the priority is, the |
|
54
|
|
|
* earlier the persistence will be called. |
|
55
|
|
|
* |
|
56
|
|
|
* @return int |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getPriority() { |
|
59
|
|
|
return (int)$this->priority; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Will inject empty options if no option has been defined at all. |
|
64
|
|
|
* |
|
65
|
|
|
* @param DataPreProcessor $processor |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
|
68
|
|
|
{ |
|
69
|
|
|
$data = $processor->getData(); |
|
70
|
|
|
|
|
71
|
|
|
if (false === isset($data['options'])) { |
|
72
|
|
|
$data['options'] = []; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$processor->setData($data); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Checks if the instance bound to the identifier object can be fetched, |
|
80
|
|
|
* throws an exception otherwise. |
|
81
|
|
|
* |
|
82
|
|
|
* @param FormIdentifierObject $identifierObject |
|
83
|
|
|
* @throws EntryNotFoundException |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function checkInstanceCanBeFetched(FormIdentifierObject $identifierObject) |
|
86
|
|
|
{ |
|
87
|
|
|
if (false === $this->has($identifierObject)) { |
|
88
|
|
|
throw EntryNotFoundException::persistenceSessionEntryNotFound($identifierObject); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.