1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace ApacheSolrForTypo3\Solr\Event\Routing; |
18
|
|
|
|
19
|
|
|
use Psr\Http\Message\UriInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This event will triggered before process variable keys and values |
23
|
|
|
* |
24
|
|
|
* @author Lars Tode <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class BeforeProcessCachedVariablesEvent |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The uri, used to identify, what placeholder is part of the path and which one is part of the query |
30
|
|
|
* |
31
|
|
|
* @var UriInterface |
32
|
|
|
*/ |
33
|
|
|
protected $uri; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* A list of router configurations, containing information how to process variables |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $routerConfiguration = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* List of variable keys |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $variableKeys = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* List of variable values |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected $variableValues = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* BeforeReplaceVariableInCachedUrlEvent constructor. |
58
|
|
|
* |
59
|
|
|
* @param UriInterface $variableKeys |
60
|
|
|
* @param array $routerConfiguration |
61
|
|
|
* @param array $variableKeys |
62
|
|
|
* @param array $variableValues |
63
|
|
|
*/ |
64
|
35 |
|
public function __construct( |
65
|
|
|
UriInterface $uri, |
66
|
|
|
array $routerConfiguration, |
67
|
|
|
array $variableKeys, |
68
|
|
|
array $variableValues |
69
|
|
|
) { |
70
|
35 |
|
$this->uri = $uri; |
71
|
35 |
|
$this->routerConfiguration = $routerConfiguration; |
72
|
35 |
|
$this->variableKeys = $variableKeys; |
73
|
35 |
|
$this->variableValues = $variableValues; |
74
|
35 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the variable keys |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getVariableKeys(): array |
82
|
|
|
{ |
83
|
|
|
return $this->variableKeys; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Sets the variable keys |
88
|
|
|
* |
89
|
|
|
* @param array $variableKeys |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function setVariableKeys(array $variableKeys): self |
93
|
|
|
{ |
94
|
|
|
$this->variableKeys = $variableKeys; |
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the variable values |
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
35 |
|
public function getVariableValues(): array |
104
|
|
|
{ |
105
|
35 |
|
return $this->variableValues; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Sets the variable values |
110
|
|
|
* |
111
|
|
|
* @param array $variableValues |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setVariableValues(array $variableValues): self |
115
|
|
|
{ |
116
|
|
|
$this->variableValues = $variableValues; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
35 |
|
public function hasRouting(): bool |
124
|
|
|
{ |
125
|
35 |
|
return !empty($this->routerConfiguration); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* The URI containing placeholder |
130
|
|
|
* |
131
|
|
|
* @return UriInterface |
132
|
|
|
*/ |
133
|
|
|
public function getUri(): UriInterface |
134
|
|
|
{ |
135
|
|
|
return $this->uri; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Available router configurations |
140
|
|
|
* |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
|
public function getRouterConfiguration(): array |
144
|
|
|
{ |
145
|
|
|
if (!isset($this->routerConfiguration['type']) && isset($this->routerConfiguration['0'])) { |
146
|
|
|
return $this->routerConfiguration[0]; |
147
|
|
|
} |
148
|
|
|
return $this->routerConfiguration; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Return all the configuration settings |
153
|
|
|
* |
154
|
|
|
* @return array[] |
155
|
|
|
*/ |
156
|
|
|
public function getRouterConfigurations(): array |
157
|
|
|
{ |
158
|
|
|
if (isset($this->routerConfiguration['type'])) { |
159
|
|
|
return [$this->routerConfiguration]; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $this->routerConfiguration; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|