1414use Doctrine \Common \Persistence \ManagerRegistry ;
1515use Doctrine \ODM \PHPCR \DocumentManager ;
1616use Jackalope \Session ;
17- use Knp \Menu \FactoryInterface ;
1817use Knp \Menu \ItemInterface ;
1918use Knp \Menu \Loader \NodeLoader ;
2019use Knp \Menu \NodeInterface ;
2120use Knp \Menu \Provider \MenuProviderInterface ;
2221use PHPCR \PathNotFoundException ;
2322use PHPCR \RepositoryException ;
2423use PHPCR \Util \PathHelper ;
25- use Symfony \Component \HttpFoundation \Request ;
2624
2725class PhpcrMenuProvider implements MenuProviderInterface
2826{
2927 /**
3028 * @var NodeLoader
3129 */
32- protected $ loader ;
33-
34- /**
35- * @var Request
36- */
37- protected $ request ;
30+ private $ loader ;
3831
3932 /**
4033 * base for menu ids.
4134 *
4235 * @var string
4336 */
44- protected $ menuRoot ;
37+ private $ menuRoot ;
4538
4639 /**
4740 * Depth to use to prefetch all menu nodes. Only used if > 0, otherwise
4841 * no prefetch is attempted.
4942 *
5043 * @var int
5144 */
52- protected $ prefetch = 10 ;
53-
54- /**
55- * doctrine document class name.
56- *
57- * @var string
58- */
59- protected $ className ;
45+ private $ prefetch = 10 ;
6046
6147 /**
6248 * If this is null, the manager registry will return the default manager.
6349 *
6450 * @var string|null Name of object manager to use
6551 */
66- protected $ managerName ;
52+ private $ managerName ;
6753
6854 /**
6955 * @var ManagerRegistry
7056 */
71- protected $ managerRegistry ;
57+ private $ managerRegistry ;
7258
7359 /**
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
7964 */
8065 public function __construct (
8166 NodeLoader $ loader ,
@@ -127,7 +112,7 @@ public function getMenuRoot()
127112 */
128113 public function setPrefetch ($ depth )
129114 {
130- $ this ->prefetch = intval ( $ depth) ;
115+ $ this ->prefetch = ( int ) $ depth ;
131116 }
132117
133118 /**
@@ -140,16 +125,6 @@ public function getPrefetch()
140125 return $ this ->prefetch ;
141126 }
142127
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-
153128 /**
154129 * Create the menu subtree starting from name.
155130 *
@@ -167,10 +142,10 @@ public function setRequest(Request $request = null)
167142 */
168143 public function get ($ name , array $ options = [])
169144 {
170- $ menu = $ this ->find ($ name , $ options , true );
145+ $ menu = $ this ->find ($ name , true );
171146
172147 $ menuItem = $ this ->loader ->load ($ menu );
173- if (empty ( $ menuItem) ) {
148+ if (! $ menuItem ) {
174149 throw new \InvalidArgumentException ("Menu at ' $ name' is misconfigured (f.e. the route might be incorrect) and could therefore not be instanciated " );
175150 }
176151
@@ -191,25 +166,24 @@ public function get($name, array $options = [])
191166 */
192167 public function has ($ name , array $ options = [])
193168 {
194- return $ this ->find ($ name , $ options , false ) instanceof NodeInterface;
169+ return $ this ->find ($ name , false ) instanceof NodeInterface;
195170 }
196171
197172 /**
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
203177 *
204178 * @return object|bool The menu root found with $name or false if $throw
205179 * is false and the menu was not found
206180 *
207181 * @throws \InvalidArgumentException Only if $throw is true throws this
208182 * exception if the name is empty or no menu found
209183 */
210- protected function find ($ name, array $ options , $ throw )
184+ private function find ($ name , $ throw )
211185 {
212- if (empty ( $ name) ) {
186+ if (! $ name ) {
213187 if ($ throw ) {
214188 throw new \InvalidArgumentException ('The menu name may not be empty ' );
215189 }
@@ -232,22 +206,24 @@ protected function find($name, array $options, $throw)
232206 }
233207
234208 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+ ) {
240213 // 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+ )) ;
250223 }
224+
225+ return false ;
226+ }
251227 } else {
252228 try {
253229 $ session ->getNode ($ path , $ this ->getPrefetch ());
0 commit comments