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

Commit 44d69b9

Browse files
committed
Added throw exception conflict resolver
1 parent 6433b6a commit 44d69b9

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ConflictResolver\Exception;
4+
5+
/**
6+
* Exception thrown when there is an existing URL and
7+
* the "ThrowException" conflict resolver is used.
8+
*
9+
* @author Daniel Leech <[email protected]>
10+
*/
11+
class ExistingUrlException extends \Exception
12+
{
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ConflictResolver;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ConflictResolverInterface;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Adapter\AdapterInterface;
8+
9+
/**
10+
* This conflcit resolver "resolves" conflicts by throwing exceptions.
11+
*
12+
* @author Daniel Leech <[email protected]>
13+
*/
14+
class ThrowExceptionConflictResolver implements ConflictResolverInterface
15+
{
16+
/**
17+
* {@inheritDoc}
18+
*/
19+
public function resolveConflict(UrlContext $urlContext)
20+
{
21+
$url = $urlContext->getUrl();
22+
23+
throw new Exception\ExistingUrlException(sprintf(
24+
'There already exists an auto route for URL "%s" and the system is configured ' .
25+
'to throw this exception in this case. Alternatively you can choose to use a ' .
26+
'different strategy, for example, auto incrementation. Please refer to the ' .
27+
'documentation for more information.',
28+
$url
29+
));
30+
}
31+
}
32+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\AutoRoute\ConflictResolver;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ConflictResolver\ThrowExceptionConflictResolver;
7+
8+
class ThrowExceptionConflictResolverTest extends BaseTestCase
9+
{
10+
protected $adapter;
11+
12+
public function setUp()
13+
{
14+
parent::setUp();
15+
$this->conflictResolver = new ThrowExceptionConflictResolver();
16+
$this->urlContext = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext');
17+
}
18+
19+
/**
20+
* @expectedException Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ConflictResolver\Exception\ExistingUrlException
21+
* @expectedExceptionMessage There already exists an auto route for URL "/foobar"
22+
*/
23+
public function testResolveConflict()
24+
{
25+
$this->urlContext->getUrl()->willReturn('/foobar');
26+
$this->conflictResolver->resolveConflict($this->urlContext->reveal());
27+
}
28+
}
29+

0 commit comments

Comments
 (0)