1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DnViewSnapshots\Subscriber; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
6
|
|
|
use Enlight\Event\SubscriberInterface; |
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Dispatch |
10
|
|
|
* @package DnViewSnapshots\Subscriber |
11
|
|
|
*/ |
12
|
|
|
class Dispatch implements SubscriberInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \Enlight_Components_Session_Namespace |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
private $session; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Connection |
21
|
|
|
*/ |
22
|
|
|
private $connection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Dispatch constructor. |
26
|
|
|
* @param \Enlight_Components_Session_Namespace $session |
27
|
|
|
* @param Connection $connection |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
\Enlight_Components_Session_Namespace $session, |
31
|
|
|
Connection $connection |
32
|
|
|
) |
33
|
|
|
{ |
34
|
|
|
$this->session = $session; |
35
|
|
|
$this->connection = $connection; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public static function getSubscribedEvents() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'onPostDispatchSecureFrontend', |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \Enlight_Controller_ActionEventArgs $args |
50
|
|
|
*/ |
51
|
|
|
public function onPostDispatchSecureFrontend(\Enlight_Controller_ActionEventArgs $args) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$view = $args->getSubject()->View(); |
54
|
|
|
$request = $args->getSubject()->Request(); |
55
|
|
|
$params = $request->getParams(); |
56
|
|
|
$sessionID = $this->session->get('sessionId'); |
57
|
|
|
|
58
|
|
|
$isSessionRecorded = strtolower($request->getControllerName()) !== 'snapshots' ? |
59
|
|
|
$this->session->get('isSessionRecorded') : |
60
|
|
|
false; |
61
|
|
|
|
62
|
|
|
$snapshotSessionID = $view->getAssign('snapshotSessionID'); |
63
|
|
|
|
64
|
|
|
$view->assign( |
65
|
|
|
[ |
66
|
|
|
'snapshotSessionID' => $snapshotSessionID ? : $sessionID, |
67
|
|
|
'isSessionRecorded' => $isSessionRecorded, |
68
|
|
|
] |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
if ( |
72
|
|
|
$snapshotSessionID || |
73
|
|
|
!$isSessionRecorded || |
74
|
|
|
$request->isXmlHttpRequest() |
75
|
|
|
) |
76
|
|
|
{ |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$template = $view->Template()->template_resource; |
81
|
|
|
|
82
|
|
|
$variables = $view->getAssign(); |
83
|
|
|
|
84
|
|
|
array_walk_recursive($variables, function (&$value) { |
85
|
|
|
if (is_object($value)) { |
86
|
|
|
try { |
87
|
|
|
// workaround for PDOException when trying to serialize PDO instances |
88
|
|
|
serialize($value); |
89
|
|
|
} |
90
|
|
|
catch (\Throwable $e) { |
91
|
|
|
// as we only need a snapshot for the view, remove the PDO instance |
92
|
|
|
$value = null; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
$variables = serialize($variables); |
98
|
|
|
|
99
|
|
|
$params['__controller'] = $request->getControllerName(); |
100
|
|
|
$params['__action'] = $request->getActionName(); |
101
|
|
|
$params = json_encode($params); |
102
|
|
|
|
103
|
|
|
$step = (int)$this->connection->fetchColumn( |
104
|
|
|
'SELECT MAX(`step`) FROM `view_snapshots` WHERE `sessionID` = :sessionID', |
105
|
|
|
['sessionID' => $sessionID] |
106
|
|
|
); |
107
|
|
|
$step++; |
108
|
|
|
|
109
|
|
|
$this->connection->insert( |
110
|
|
|
'view_snapshots', |
111
|
|
|
[ |
112
|
|
|
'sessionID' => $sessionID, |
113
|
|
|
'template' => $template, |
114
|
|
|
'variables' => $variables, |
115
|
|
|
'params' => $params, |
116
|
|
|
'step' => $step, |
117
|
|
|
] |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths