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

Commit f584695

Browse files
Merge pull request #100 from symfony-cmf/cleanup-adapter-interface
remove redundant parameter from AdapterInterface
2 parents 4ae5065 + ebad357 commit f584695

File tree

7 files changed

+88
-23
lines changed

7 files changed

+88
-23
lines changed

CHANGELOG.md

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

4+
2.0.0-RC3
5+
---------
6+
7+
* **2017-08-03**: [BC Break] Removed second argument $contentDocument from `AdapterInterface::createAutoRoute`.
8+
If you call this method manually or implemented the interface, you need to adjust your code.
9+
410
2.0.0-RC2
511
---------
612

src/Adapter/EventDispatchingAdapter.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
*/
2727
class EventDispatchingAdapter implements AdapterInterface
2828
{
29+
/**
30+
* @var AdapterInterface
31+
*/
32+
private $adapter;
33+
34+
/**
35+
* @var EventDispatcherInterface
36+
*/
2937
private $dispatcher;
3038

3139
public function __construct(AdapterInterface $adapter, EventDispatcherInterface $eventDispatcher)
@@ -78,9 +86,9 @@ public function removeAutoRoute(AutoRouteInterface $autoRoute)
7886
/**
7987
* {@inheritdoc}
8088
*/
81-
public function createAutoRoute(UriContext $uriContext, $contentDocument, $autoRouteTag)
89+
public function createAutoRoute(UriContext $uriContext, $autoRouteTag)
8290
{
83-
$autoRoute = $this->adapter->createAutoRoute($uriContext, $contentDocument, $autoRouteTag);
91+
$autoRoute = $this->adapter->createAutoRoute($uriContext, $autoRouteTag);
8492
$this->dispatcher->dispatch(RoutingAutoEvents::POST_CREATE, new AutoRouteCreateEvent($autoRoute, $uriContext));
8593

8694
return $autoRoute;

src/AdapterInterface.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Cmf\Component\RoutingAuto;
1313

14+
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
1415
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
1516

1617
/**
@@ -40,16 +41,14 @@ public function getLocales($object);
4041
public function translateObject($object, $locale);
4142

4243
/**
43-
* Create a new auto route at the given path
44-
* with the given document as the content.
44+
* Create a new auto route from the given context.
4545
*
4646
* @param UriContext $uriContext
47-
* @param object $document
4847
* @param string $tag
4948
*
5049
* @return AutoRouteInterface new route document
5150
*/
52-
public function createAutoRoute(UriContext $uriContext, $document, $tag);
51+
public function createAutoRoute(UriContext $uriContext, $tag);
5352

5453
/**
5554
* Return the canonical name for the given class, this is
@@ -92,7 +91,7 @@ public function compareAutoRouteLocale(AutoRouteInterface $autoRoute, $locale);
9291
* @param string $uri The URI to find
9392
* @param UriContext $uriContext The current URI context
9493
*
95-
* @return null|Symfony\Cmf\Component\Routing\RouteObjectInterface
94+
* @return RouteObjectInterface|null
9695
*/
9796
public function findRouteForUri($uri, UriContext $uriContext);
9897

src/AutoRouteManager.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Cmf\Component\RoutingAuto;
1313

1414
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
15-
use Symfony\Component\EventDispatcher\EventDispatcher;
1615

1716
/**
1817
* This class is concerned with the automatic creation of route objects.
@@ -46,12 +45,6 @@ class AutoRouteManager
4645
*/
4746
protected $collectionBuilder;
4847

49-
/**
50-
* @param AdapterInterface $adapter Database adapter
51-
* @param UriGeneratorInterface $uriGenerator Routing auto URL generator
52-
* @param DefunctRouteHandlerInterface $defunctRouteHandler Handler for defunct routes
53-
* @param EventDispatcher $eventDispatcher Dispatcher for events
54-
*/
5548
public function __construct(
5649
AdapterInterface $adapter,
5750
UriGeneratorInterface $uriGenerator,
@@ -73,6 +66,7 @@ public function buildUriContextCollection(UriContextCollection $uriContextCollec
7366
{
7467
$this->collectionBuilder->build($uriContextCollection);
7568

69+
/** @var UriContext $uriContext */
7670
foreach ($uriContextCollection->getUriContexts() as $uriContext) {
7771
$subject = $uriContextCollection->getSubject();
7872

@@ -99,12 +93,7 @@ public function buildUriContextCollection(UriContextCollection $uriContextCollec
9993
if (null === $autoRoute) {
10094
$autoRouteTag = $this->adapter->generateAutoRouteTag($uriContext);
10195

102-
// TODO: The second argument below is now **pointless**, as the
103-
// UriContext contains both the original and translated subject
104-
// objects.
105-
//
106-
// See: https://github.com/symfony-cmf/RoutingAuto/issues/73
107-
$autoRoute = $this->adapter->createAutoRoute($uriContext, $subject, $autoRouteTag);
96+
$autoRoute = $this->adapter->createAutoRoute($uriContext, $autoRouteTag);
10897
}
10998

11099
$uriContext->setAutoRoute($autoRoute);

src/UriContext.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Cmf\Component\RoutingAuto;
1313

14+
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
15+
1416
/**
1517
* Class which holds all the necessary information to make an auto route.
1618
*

tests/Unit/Adapter/EventDispatchingAdapterTest.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,56 @@
1111

1212
namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit\Adapter;
1313

14+
use Prophecy\Prophecy\ObjectProphecy;
1415
use Symfony\Cmf\Component\RoutingAuto\Adapter\EventDispatchingAdapter;
16+
use Symfony\Cmf\Component\RoutingAuto\AdapterInterface;
1517
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent;
1618
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent;
19+
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
1720
use Symfony\Cmf\Component\RoutingAuto\RoutingAutoEvents;
21+
use Symfony\Cmf\Component\RoutingAuto\UriContext;
1822
use Symfony\Component\EventDispatcher\EventDispatcher;
1923
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2024

2125
class EventDispatchingAdapterTest extends \PHPUnit_Framework_TestCase
2226
{
27+
/**
28+
* @var AdapterInterface|ObjectProphecy
29+
*/
30+
private $realAdapter;
31+
32+
/**
33+
* @var EventDispatcher
34+
*/
35+
private $dispatcher;
36+
37+
/**
38+
* @var EventDispatchingAdapter
39+
*/
40+
private $adapter;
41+
42+
/**
43+
* @var EventDispatchingAdapterSubscriber
44+
*/
45+
private $subscriber;
46+
47+
/**
48+
* @var UriContext|ObjectProphecy
49+
*/
50+
private $uriContext;
51+
52+
/**
53+
* @var AutoRouteInterface|ObjectProphecy
54+
*/
55+
private $autoRoute;
56+
57+
/**
58+
* @var AutoRouteInterface|ObjectProphecy
59+
*/
60+
private $autoRoute2;
61+
62+
private $content;
63+
2364
public function setUp()
2465
{
2566
$this->realAdapter = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\AdapterInterface');
@@ -39,8 +80,8 @@ public function setUp()
3980

4081
public function testCreateAutoRoute()
4182
{
42-
$this->realAdapter->createAutoRoute($this->uriContext->reveal(), null, 'fr')->willReturn($this->autoRoute->reveal());
43-
$this->adapter->createAutoRoute($this->uriContext->reveal(), null, 'fr');
83+
$this->realAdapter->createAutoRoute($this->uriContext->reveal(), 'fr')->willReturn($this->autoRoute->reveal());
84+
$this->adapter->createAutoRoute($this->uriContext->reveal(), 'fr');
4485
$this->assertNotNull($this->subscriber->createEvent);
4586
$this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent', $this->subscriber->createEvent);
4687
$this->assertSame($this->autoRoute->reveal(), $this->subscriber->createEvent->getAutoRoute());

tests/Unit/AutoRouteManagerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit;
1313

1414
use Prophecy\Argument;
15+
use Prophecy\Prophecy\ObjectProphecy;
1516
use Symfony\Cmf\Component\RoutingAuto\AdapterInterface;
1617
use Symfony\Cmf\Component\RoutingAuto\AutoRouteManager;
1718
use Symfony\Cmf\Component\RoutingAuto\DefunctRouteHandlerInterface;
@@ -23,10 +24,29 @@
2324

2425
class AutoRouteManagerTest extends \PHPUnit_Framework_TestCase
2526
{
27+
/**
28+
* @var AdapterInterface|ObjectProphecy
29+
*/
2630
private $adapter;
31+
32+
/**
33+
* @var UriGeneratorInterface|ObjectProphecy
34+
*/
2735
private $uriGenerator;
36+
37+
/**
38+
* @var DefunctRouteHandlerInterface|ObjectProphecy
39+
*/
2840
private $defunctRouteHandler;
41+
42+
/**
43+
* @var UriContextCollectionBuilder|ObjectProphecy
44+
*/
2945
private $collectionBuilder;
46+
47+
/**
48+
* @var AutoRouteManager|ObjectProphecy
49+
*/
3050
private $manager;
3151
private $subject;
3252
private $collection;
@@ -494,7 +514,7 @@ private function configureAdapter(array $route)
494514
$this->adapter->generateAutoRouteTag(self::is($route['context']))
495515
->willReturn($route['locale']);
496516

497-
$this->adapter->createAutoRoute(self::is($route['context']), $route['subject'], $route['locale'])
517+
$this->adapter->createAutoRoute(self::is($route['context']), $route['locale'])
498518
->willReturn($route['createdAutoRoute']);
499519

500520
$this->adapter->findRouteForUri($route['generatedUri'], self::is($route['context']))

0 commit comments

Comments
 (0)