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

Commit c032047

Browse files
committed
[WIP] Route basepath provider
1 parent b4a79bb commit c032047

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception;
4+
5+
/**
6+
* @author Daniel Leech <[email protected]>
7+
*/
8+
class BadProviderPositionException extends \RuntimeException
9+
{
10+
}
11+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProvider;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProviderInterface;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception\BadProviderPositionException;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
8+
9+
/**
10+
* Provides the routing extra bundles route_basepath.
11+
*
12+
* @author Daniel Leech <[email protected]>
13+
*/
14+
class RouteBasePathObjectProvider implements PathProviderInterface
15+
{
16+
protected $routingBasePath;
17+
18+
public function __construct($routeBasePath)
19+
{
20+
$this->routeBasePath = $routeBasePath;
21+
}
22+
23+
public function init(array $options)
24+
{
25+
}
26+
27+
public function providePath(RouteStack $routeStack)
28+
{
29+
$context = $routeStack->getContext();
30+
31+
if (count($context->getRouteStacks()) > 0) {
32+
throw new BadProviderPositionException(
33+
'RouteBasePathProvider must belong to the first builder unit - adding '.
34+
'the full routing basepath at an intermediate point would be senseless.'
35+
);
36+
}
37+
38+
$id = $this->routeBasePath;
39+
$id = substr($id, 1);
40+
$pathElements = explode('/', $id);
41+
$routeStack->addPathElements($pathElements);
42+
}
43+
}
44+

0 commit comments

Comments
 (0)