Skip to content

Commit 847da9a

Browse files
committed
Merge pull request #73 from symfony-cmf/interface-cleanup
rename RouteAwareInterface to RouteReferrersInterface to be consistent
2 parents b76d6b0 + 2a1d4ee commit 847da9a

7 files changed

+45
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
1.1
55
---
66

7+
* **2013-07-29**: Renamed RouteAwareInterface to RouteReferrersInterface for naming consistency
78
* **2013-07-13**: NestedMatcher now expects a FinalMatcherInterface as second argument of the constructor
89
* **2013-04-30**: Dropped Symfony 2.1 support and got rid of ConfigurableUrlMatcher class
910
* **2013-04-05**: [ContentAwareGenerator] Fix locale handling to always respect locale but never have unnecessary ?locale=

ContentAwareGenerator.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
4242
* @param string $name ignored
4343
* @param array $parameters must either contain the field 'route' with a
4444
* RouteObjectInterface or the field 'content_id' with a document
45-
* id to get the route for (implementing RouteAwareInterface)
45+
* id to get the route for (implementing RouteReferrersInterface)
4646
*
4747
* @throws RouteNotFoundException If there is no such route in the database
4848
*/
@@ -104,7 +104,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
104104
$locale = $this->getLocale($parameters);
105105
if (! $this->checkLocaleRequirement($route, $locale)) {
106106
$content = $route->getContent();
107-
if ($content instanceof RouteAwareInterface) {
107+
if ($content instanceof RouteReferrersInterface) {
108108
$routes = $content->getRoutes();
109109
$contentRoute = $this->getRouteByLocale($routes, $locale);
110110
if ($contentRoute) {
@@ -117,8 +117,8 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
117117
}
118118

119119
/**
120-
* Get the route based on the $name that is a RouteAwareInterface or a
121-
* RouteAwareInterface content found in the content repository with the
120+
* Get the route based on the $name that is a RouteReferrersInterface or a
121+
* RouteReferrersInterface content found in the content repository with the
122122
* content_id specified in parameters.
123123
*
124124
* Called in generate when there is no route given in the parameters.
@@ -131,15 +131,16 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
131131
* first route.
132132
*
133133
* @param mixed $name
134-
* @param array $parameters which should contain a content field containing a RouteAwareInterface object
134+
* @param array $parameters which should contain a content field containing
135+
* a RouteReferrersInterface object
135136
*
136137
* @return SymfonyRoute the route instance
137138
*
138139
* @throws RouteNotFoundException if no route can be determined
139140
*/
140141
protected function getRouteByContent($name, &$parameters)
141142
{
142-
if ($name instanceof RouteAwareInterface) {
143+
if ($name instanceof RouteReferrersInterface) {
143144
$content = $name;
144145
} elseif (isset($parameters['content_id'])
145146
&& null !== $this->contentRepository
@@ -148,12 +149,12 @@ protected function getRouteByContent($name, &$parameters)
148149
if (empty($content)) {
149150
throw new RouteNotFoundException('The content repository found nothing at id ' . $parameters['content_id']);
150151
}
151-
if (!$content instanceof RouteAwareInterface) {
152-
throw new RouteNotFoundException('Content repository did not return a RouteAwareInterface for id ' . $parameters['content_id']);
152+
if (!$content instanceof RouteReferrersInterface) {
153+
throw new RouteNotFoundException('Content repository did not return a RouteReferrersInterface for id ' . $parameters['content_id']);
153154
}
154155
} else {
155156
$hint = is_object($name) ? get_class($name) : gettype($name);
156-
throw new RouteNotFoundException("The route name argument '$hint' is not RouteAwareInterface and there is no 'content_id' parameter");
157+
throw new RouteNotFoundException("The route name argument '$hint' is not RouteReferrersInterface and there is no 'content_id' parameter");
157158
}
158159

159160
$routes = $content->getRoutes();
@@ -233,7 +234,7 @@ protected function getLocale($parameters)
233234
*/
234235
public function supports($name)
235236
{
236-
return ! $name || parent::supports($name) || $name instanceof RouteAwareInterface;
237+
return ! $name || parent::supports($name) || $name instanceof RouteReferrersInterface;
237238
}
238239

239240
/**
@@ -245,7 +246,7 @@ public function getRouteDebugMessage($name, array $parameters = array())
245246
return 'Content id ' . $parameters['content_id'];
246247
}
247248

248-
if ($name instanceof RouteAwareInterface) {
249+
if ($name instanceof RouteReferrersInterface) {
249250
return 'Route aware content ' . $name;
250251
}
251252

ContentRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ContentRepositoryInterface
1616
/**
1717
* Return a content object by it's id or null if there is none.
1818
*
19-
* If the returned content implements RouteAwareInterface, it will be used
19+
* If the returned content implements RouteReferrersInterface, it will be used
2020
* to get the route from it to generate an URL.
2121
*
2222
* @param string $id id of the content object

RouteAwareInterface.php renamed to RouteReferrersInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Interface to be implemented by content that wants to be compatible with the
77
* DynamicRouter
88
*/
9-
interface RouteAwareInterface
9+
interface RouteReferrersInterface
1010
{
1111
/**
1212
* Get the routes that point to this content.

RouteReferrersWriteInterface.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Component\Routing;
4+
5+
use Symfony\Component\Routing\Route;
6+
7+
/**
8+
* Interface to be implemented by content that exposes editable route
9+
* referrers.
10+
*/
11+
interface RouteReferrersWriteInterface extends RouteReferrersInterface
12+
{
13+
/**
14+
* Add a route to the collection.
15+
*
16+
* @param Route $route
17+
*/
18+
public function addRoute($route);
19+
20+
/**
21+
* Remove a route from the collection.
22+
*
23+
* @param Route $route
24+
*/
25+
public function removeRoute($route);
26+
}

Tests/Routing/ContentAwareGeneratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
44

5-
use Symfony\Cmf\Component\Routing\RouteAwareInterface;
5+
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
66

77
use Symfony\Cmf\Component\Routing\ContentAwareGenerator;
88
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
@@ -22,7 +22,7 @@ class ContentAwareGeneratorTest extends CmfUnitTestCase
2222

2323
public function setUp()
2424
{
25-
$this->contentDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteAwareInterface');
25+
$this->contentDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteReferrersInterface');
2626
$this->routeDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array('getDefaults', 'compile'));
2727
$this->routeCompiled = $this->buildMock('Symfony\\Component\\Routing\\CompiledRoute');
2828
$this->provider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface");
@@ -367,7 +367,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
367367
}
368368
}
369369

370-
class RouteAware implements RouteAwareInterface
370+
class RouteAware implements RouteReferrersInterface
371371
{
372372
public function getRoutes()
373373
{

VersatileGeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function supports($name);
2929
*
3030
* @param mixed $name
3131
* @param array $parameters which should contain a content field containing
32-
* a RouteAwareInterface object
32+
* a RouteReferrersInterface object
3333
*
3434
* @return string
3535
*/

0 commit comments

Comments
 (0)