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\Middleware\Item\Persistence; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Core\Core; |
17
|
|
|
use Romm\Formz\Form\Service\DataObject\FormIdentifierObject; |
18
|
|
|
use Romm\Formz\Form\Service\DataObject\WrongFormIdentifierObjectDataException; |
19
|
|
|
use Romm\Formz\Middleware\Argument\Arguments; |
20
|
|
|
use Romm\Formz\Middleware\Item\AbstractMiddleware; |
21
|
|
|
use Romm\Formz\Middleware\Item\InjectForm\InjectFormSignal; |
22
|
|
|
use Romm\Formz\Middleware\Signal\After; |
23
|
|
|
use Romm\Formz\Middleware\Signal\Before; |
24
|
|
|
use Romm\Formz\Persistence\PersistenceInterface; |
25
|
|
|
use Romm\Formz\Persistence\SessionPersistence; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @todo |
29
|
|
|
*/ |
30
|
|
|
class PersistenceMiddleware extends AbstractMiddleware implements Before, After, InjectFormSignal |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var \Romm\Formz\Middleware\Item\Persistence\PersistenceMiddlewareOption |
34
|
|
|
*/ |
35
|
|
|
protected $options; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var PersistenceInterface |
39
|
|
|
*/ |
40
|
|
|
protected $persistence; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var FormIdentifierObject |
44
|
|
|
*/ |
45
|
|
|
protected $identifierObject; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @todo |
49
|
|
|
*/ |
50
|
|
|
public function initializeMiddleware() |
51
|
|
|
{ |
52
|
|
|
$this->persistence = Core::instantiate(SessionPersistence::class); |
53
|
|
|
|
54
|
|
|
if ($this->getRequest()->hasArgument('fz-identifier')) { |
55
|
|
|
$identifier = $this->getRequest()->getArgument('fz-identifier'); |
56
|
|
|
|
57
|
|
|
try { |
58
|
|
|
$this->identifierObject = $this->getFormObject()->getFormIdentifierObject($identifier); |
59
|
|
|
} catch (WrongFormIdentifierObjectDataException $exception) { |
60
|
|
|
$action = $this->options->getForwardToActionOnHashError(); |
|
|
|
|
61
|
|
|
// @todo forward |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Arguments $arguments |
68
|
|
|
*/ |
69
|
|
|
public function after(Arguments $arguments) |
70
|
|
|
{ |
71
|
|
|
if ($this->identifierObject) { |
72
|
|
|
$this->persistence->save($this->identifierObject, $this->getFormObject()->getForm()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param Arguments $arguments |
78
|
|
|
*/ |
79
|
|
|
public function before(Arguments $arguments) |
80
|
|
|
{ |
81
|
|
|
if ($this->identifierObject |
82
|
|
|
&& $this->persistence->has($this->identifierObject) |
83
|
|
|
) { |
84
|
|
|
$form = $this->persistence->fetch($this->identifierObject); |
85
|
|
|
$this->getFormObject()->setForm($form); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.