Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 2f53bab

Browse files
committed
remove unused request object from PhpcrMenuProvider
1 parent 8b48c37 commit 2f53bab

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
=========
33

4+
* **2017-02-17**: [BC BREAK] Removed unused setRequest from PhpcrMenuProvider and changed properties to private.
5+
46
2.0.0-RC2
57
---------
68

src/Provider/PhpcrMenuProvider.php

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,53 @@
1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Doctrine\ODM\PHPCR\DocumentManager;
1616
use Jackalope\Session;
17-
use Knp\Menu\FactoryInterface;
1817
use Knp\Menu\ItemInterface;
1918
use Knp\Menu\Loader\NodeLoader;
2019
use Knp\Menu\NodeInterface;
2120
use Knp\Menu\Provider\MenuProviderInterface;
2221
use PHPCR\PathNotFoundException;
2322
use PHPCR\RepositoryException;
2423
use PHPCR\Util\PathHelper;
25-
use Symfony\Component\HttpFoundation\Request;
2624

2725
class 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());

src/Resources/config/persistence-phpcr.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<argument>%cmf_menu.persistence.phpcr.menu_basepath%</argument>
1414
<call method="setManagerName"><argument>%cmf_menu.persistence.phpcr.manager_name%</argument></call>
1515
<call method="setPrefetch"><argument>%cmf_menu.persistence.phpcr.prefetch%</argument></call>
16-
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false"/></call>
1716
</service>
1817

1918
<service id="cmf_menu.initializer" class="Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer">

tests/Unit/Provider/PhpcrMenuProviderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use PHPCR\SessionInterface;
2020
use Prophecy\Argument;
2121
use Symfony\Cmf\Bundle\MenuBundle\Provider\PhpcrMenuProvider;
22-
use Symfony\Component\HttpFoundation\Request;
2322

2423
class PhpcrMenuProviderTest extends \PHPUnit_Framework_Testcase
2524
{
@@ -49,7 +48,6 @@ public function testGet($menuRoot, $name, $expectedPath)
4948
->willReturn($this->item->reveal());
5049

5150
$provider = $this->createProvider($menuRoot);
52-
$provider->setRequest(Request::create('/'));
5351
$item = $provider->get($name);
5452

5553
$this->assertSame($this->item->reveal(), $item);

0 commit comments

Comments
 (0)