Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.1
---

* **2013-07-29**: Renamed RouteAwareInterface to RouteReferrersInterface for naming consistency
* **2013-07-13**: NestedMatcher now expects a FinalMatcherInterface as second argument of the constructor
* **2013-04-30**: Dropped Symfony 2.1 support and got rid of ConfigurableUrlMatcher class
* **2013-04-05**: [ContentAwareGenerator] Fix locale handling to always respect locale but never have unnecessary ?locale=
23 changes: 12 additions & 11 deletions ContentAwareGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
* @param string $name ignored
* @param array $parameters must either contain the field 'route' with a
* RouteObjectInterface or the field 'content_id' with a document
* id to get the route for (implementing RouteAwareInterface)
* id to get the route for (implementing RouteReferrersInterface)
*
* @throws RouteNotFoundException If there is no such route in the database
*/
Expand Down Expand Up @@ -104,7 +104,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
$locale = $this->getLocale($parameters);
if (! $this->checkLocaleRequirement($route, $locale)) {
$content = $route->getContent();
if ($content instanceof RouteAwareInterface) {
if ($content instanceof RouteReferrersInterface) {
$routes = $content->getRoutes();
$contentRoute = $this->getRouteByLocale($routes, $locale);
if ($contentRoute) {
Expand All @@ -117,8 +117,8 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
}

/**
* Get the route based on the $name that is a RouteAwareInterface or a
* RouteAwareInterface content found in the content repository with the
* Get the route based on the $name that is a RouteReferrersInterface or a
* RouteReferrersInterface content found in the content repository with the
* content_id specified in parameters.
*
* Called in generate when there is no route given in the parameters.
Expand All @@ -131,15 +131,16 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
* first route.
*
* @param mixed $name
* @param array $parameters which should contain a content field containing a RouteAwareInterface object
* @param array $parameters which should contain a content field containing
* a RouteReferrersInterface object
*
* @return SymfonyRoute the route instance
*
* @throws RouteNotFoundException if no route can be determined
*/
protected function getRouteByContent($name, &$parameters)
{
if ($name instanceof RouteAwareInterface) {
if ($name instanceof RouteReferrersInterface) {
$content = $name;
} elseif (isset($parameters['content_id'])
&& null !== $this->contentRepository
Expand All @@ -148,12 +149,12 @@ protected function getRouteByContent($name, &$parameters)
if (empty($content)) {
throw new RouteNotFoundException('The content repository found nothing at id ' . $parameters['content_id']);
}
if (!$content instanceof RouteAwareInterface) {
throw new RouteNotFoundException('Content repository did not return a RouteAwareInterface for id ' . $parameters['content_id']);
if (!$content instanceof RouteReferrersInterface) {
throw new RouteNotFoundException('Content repository did not return a RouteReferrersInterface for id ' . $parameters['content_id']);
}
} else {
$hint = is_object($name) ? get_class($name) : gettype($name);
throw new RouteNotFoundException("The route name argument '$hint' is not RouteAwareInterface and there is no 'content_id' parameter");
throw new RouteNotFoundException("The route name argument '$hint' is not RouteReferrersInterface and there is no 'content_id' parameter");
}

$routes = $content->getRoutes();
Expand Down Expand Up @@ -233,7 +234,7 @@ protected function getLocale($parameters)
*/
public function supports($name)
{
return ! $name || parent::supports($name) || $name instanceof RouteAwareInterface;
return ! $name || parent::supports($name) || $name instanceof RouteReferrersInterface;
}

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

if ($name instanceof RouteAwareInterface) {
if ($name instanceof RouteReferrersInterface) {
return 'Route aware content ' . $name;
}

Expand Down
2 changes: 1 addition & 1 deletion ContentRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ContentRepositoryInterface
/**
* Return a content object by it's id or null if there is none.
*
* If the returned content implements RouteAwareInterface, it will be used
* If the returned content implements RouteReferrersInterface, it will be used
* to get the route from it to generate an URL.
*
* @param string $id id of the content object
Expand Down
2 changes: 1 addition & 1 deletion RouteAwareInterface.php → RouteReferrersInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Interface to be implemented by content that wants to be compatible with the
* DynamicRouter
*/
interface RouteAwareInterface
interface RouteReferrersInterface
{
/**
* Get the routes that point to this content.
Expand Down
26 changes: 26 additions & 0 deletions RouteReferrersWriteInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Symfony\Cmf\Component\Routing;

use Symfony\Component\Routing\Route;

/**
* Interface to be implemented by content that exposes editable route
* referrers.
*/
interface RouteReferrersWriteInterface extends RouteReferrersInterface
{
/**
* Add a route to the collection.
*
* @param Route $route
*/
public function addRoute($route);

/**
* Remove a route from the collection.
*
* @param Route $route
*/
public function removeRoute($route);
}
6 changes: 3 additions & 3 deletions Tests/Routing/ContentAwareGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

use Symfony\Cmf\Component\Routing\RouteAwareInterface;
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;

use Symfony\Cmf\Component\Routing\ContentAwareGenerator;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
Expand All @@ -22,7 +22,7 @@ class ContentAwareGeneratorTest extends CmfUnitTestCase

public function setUp()
{
$this->contentDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteAwareInterface');
$this->contentDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteReferrersInterface');
$this->routeDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array('getDefaults', 'compile'));
$this->routeCompiled = $this->buildMock('Symfony\\Component\\Routing\\CompiledRoute');
$this->provider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface");
Expand Down Expand Up @@ -367,7 +367,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
}
}

class RouteAware implements RouteAwareInterface
class RouteAware implements RouteReferrersInterface
{
public function getRoutes()
{
Expand Down
2 changes: 1 addition & 1 deletion VersatileGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function supports($name);
*
* @param mixed $name
* @param array $parameters which should contain a content field containing
* a RouteAwareInterface object
* a RouteReferrersInterface object
*
* @return string
*/
Expand Down