14
14
use Doctrine \Common \Persistence \ManagerRegistry ;
15
15
use Doctrine \ODM \PHPCR \DocumentManager ;
16
16
use Jackalope \Session ;
17
- use Knp \Menu \FactoryInterface ;
18
17
use Knp \Menu \ItemInterface ;
19
18
use Knp \Menu \Loader \NodeLoader ;
20
19
use Knp \Menu \NodeInterface ;
21
20
use Knp \Menu \Provider \MenuProviderInterface ;
22
21
use PHPCR \PathNotFoundException ;
23
22
use PHPCR \RepositoryException ;
24
23
use PHPCR \Util \PathHelper ;
25
- use Symfony \Component \HttpFoundation \Request ;
26
24
27
25
class PhpcrMenuProvider implements MenuProviderInterface
28
26
{
29
27
/**
30
28
* @var NodeLoader
31
29
*/
32
- protected $ loader ;
33
-
34
- /**
35
- * @var Request
36
- */
37
- protected $ request ;
30
+ private $ loader ;
38
31
39
32
/**
40
33
* base for menu ids.
41
34
*
42
35
* @var string
43
36
*/
44
- protected $ menuRoot ;
37
+ private $ menuRoot ;
45
38
46
39
/**
47
40
* Depth to use to prefetch all menu nodes. Only used if > 0, otherwise
48
41
* no prefetch is attempted.
49
42
*
50
43
* @var int
51
44
*/
52
- protected $ prefetch = 10 ;
53
-
54
- /**
55
- * doctrine document class name.
56
- *
57
- * @var string
58
- */
59
- protected $ className ;
45
+ private $ prefetch = 10 ;
60
46
61
47
/**
62
48
* If this is null, the manager registry will return the default manager.
63
49
*
64
50
* @var string|null Name of object manager to use
65
51
*/
66
- protected $ managerName ;
52
+ private $ managerName ;
67
53
68
54
/**
69
55
* @var ManagerRegistry
70
56
*/
71
- protected $ managerRegistry ;
57
+ private $ managerRegistry ;
72
58
73
59
/**
74
- * @param FactoryInterface $factory the menu factory to create the menu
75
- * item with the root document (usually ContentAwareFactory)
76
- * @param ManagerRegistry $managerRegistry manager registry service to use in conjunction
77
- * with the manager name to load the load menu root document
78
- * @param string $menuRoot root id of the menu
60
+ * @param NodeLoader $loader Factory for the menu items
61
+ * @param ManagerRegistry $managerRegistry manager registry service to use in conjunction
62
+ * with the manager name to load the load menu root document
63
+ * @param string $menuRoot root id of the menu
79
64
*/
80
65
public function __construct (
81
66
NodeLoader $ loader ,
@@ -127,7 +112,7 @@ public function getMenuRoot()
127
112
*/
128
113
public function setPrefetch ($ depth )
129
114
{
130
- $ this ->prefetch = intval ( $ depth) ;
115
+ $ this ->prefetch = ( int ) $ depth ;
131
116
}
132
117
133
118
/**
@@ -140,16 +125,6 @@ public function getPrefetch()
140
125
return $ this ->prefetch ;
141
126
}
142
127
143
- /**
144
- * Set the request.
145
- *
146
- * @param Request $request
147
- */
148
- public function setRequest (Request $ request = null )
149
- {
150
- $ this ->request = $ request ;
151
- }
152
-
153
128
/**
154
129
* Create the menu subtree starting from name.
155
130
*
@@ -167,10 +142,10 @@ public function setRequest(Request $request = null)
167
142
*/
168
143
public function get ($ name , array $ options = [])
169
144
{
170
- $ menu = $ this ->find ($ name , $ options , true );
145
+ $ menu = $ this ->find ($ name , true );
171
146
172
147
$ menuItem = $ this ->loader ->load ($ menu );
173
- if (empty ( $ menuItem) ) {
148
+ if (! $ menuItem ) {
174
149
throw new \InvalidArgumentException ("Menu at ' $ name' is misconfigured (f.e. the route might be incorrect) and could therefore not be instanciated " );
175
150
}
176
151
@@ -191,25 +166,24 @@ public function get($name, array $options = [])
191
166
*/
192
167
public function has ($ name , array $ options = [])
193
168
{
194
- return $ this ->find ($ name , $ options , false ) instanceof NodeInterface;
169
+ return $ this ->find ($ name , false ) instanceof NodeInterface;
195
170
}
196
171
197
172
/**
198
- * @param string $name Name of the menu to load
199
- * @param array $options
200
- * @param bool $throw Whether to throw an exception if the menu is not
201
- * found or no valid menu. Returns false if $throw is false and there
202
- * is no menu at $name
173
+ * @param string $name Name of the menu to load
174
+ * @param bool $throw Whether to throw an exception if the menu is not
175
+ * found or no valid menu. Returns false if $throw is
176
+ * false and there is no menu at $name
203
177
*
204
178
* @return object|bool The menu root found with $name or false if $throw
205
179
* is false and the menu was not found
206
180
*
207
181
* @throws \InvalidArgumentException Only if $throw is true throws this
208
182
* exception if the name is empty or no menu found
209
183
*/
210
- protected function find ($ name, array $ options , $ throw )
184
+ private function find ($ name , $ throw )
211
185
{
212
- if (empty ( $ name) ) {
186
+ if (! $ name ) {
213
187
if ($ throw ) {
214
188
throw new \InvalidArgumentException ('The menu name may not be empty ' );
215
189
}
@@ -232,22 +206,24 @@ protected function find($name, array $options, $throw)
232
206
}
233
207
234
208
if ($ this ->getPrefetch () > 0 ) {
235
- if (
236
- $ session instanceof Session
237
- && 0 < $ session ->getSessionOption (Session::OPTION_FETCH_DEPTH )
238
- && 0 === strncmp ($ path , $ this ->getMenuRoot (), strlen ($ this ->getMenuRoot ()))
239
- ) {
209
+ if ($ session instanceof Session
210
+ && 0 < $ session ->getSessionOption (Session::OPTION_FETCH_DEPTH )
211
+ && 0 === strncmp ($ path , $ this ->getMenuRoot (), strlen ($ this ->getMenuRoot ()))
212
+ ) {
240
213
// we have jackalope with a fetch depth. prefetch all menu
241
- // nodes of all menues.
242
- try {
243
- $ session ->getNode ($ this ->getMenuRoot (), $ this ->getPrefetch () + 1 );
244
- } catch (PathNotFoundException $ e ) {
245
- if ($ throw ) {
246
- throw new \InvalidArgumentException (sprintf (' The menu root "%s" does not exist. ' , $ this -> getMenuRoot ()));
247
- }
248
-
249
- return false ;
214
+ // nodes of all menues.
215
+ try {
216
+ $ session ->getNode ($ this ->getMenuRoot (), $ this ->getPrefetch () + 1 );
217
+ } catch (PathNotFoundException $ e ) {
218
+ if ($ throw ) {
219
+ throw new \InvalidArgumentException (sprintf (
220
+ ' The menu root "%s" does not exist. ' ,
221
+ $ this -> getMenuRoot ()
222
+ )) ;
250
223
}
224
+
225
+ return false ;
226
+ }
251
227
} else {
252
228
try {
253
229
$ session ->getNode ($ path , $ this ->getPrefetch ());
0 commit comments