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

Commit 7fd6fd3

Browse files
committed
Namespaced all the RouteStack* classes
1 parent f2ba880 commit 7fd6fd3

File tree

9 files changed

+73
-52
lines changed

9 files changed

+73
-52
lines changed

AutoRoute/Factory.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function registerAlias($type, $alias, $id)
4444
$this->serviceIds[$type][$alias] = $id;
4545
}
4646

47-
public function getChain($classFqn)
47+
public function getRouteStackBuilderChain($classFqn)
4848
{
4949
if (!isset($this->routeStackChains[$classFqn])) {
5050
$this->routeStackChains[$classFqn] = $this->generateRouteStackChain($classFqn);
@@ -53,6 +53,12 @@ public function getChain($classFqn)
5353
return $this->routeStackChains[$classFqn];
5454
}
5555

56+
public function getContentRouteBuilder($classFqn)
57+
{
58+
$mapping = $this->getMapping($classFqn);
59+
return $this->generateBuilderUnit($mapping['content_name']);
60+
}
61+
5662
public function hasMapping($classFqn)
5763
{
5864
// @todo: Do we need to support inheritance?
@@ -66,22 +72,28 @@ protected function generateRouteStackChain($classFqn)
6672
$routeStackChain = new RouteStackBuilderUnitChain($this->builder);
6773

6874
foreach ($mapping['content_path'] as $builderName => $builderConfig) {
69-
$pathProvider = $this->getBuilderService($builderConfig, 'provider', 'name');
70-
$existsAction = $this->getBuilderService($builderConfig, 'exists_action', 'strategy');
71-
$notExistsAction = $this->getBuilderService($builderConfig, 'not_exists_action', 'strategy');
72-
73-
$stackBuilderUnit = new RouteStackBuilderUnit(
74-
$pathProvider,
75-
$existsAction,
76-
$notExistsAction
77-
);
78-
79-
$routeStackChain->addRouteStackBuilderUnit($builderName, $stackBuilderUnit);
75+
$builderUnit = $this->generateBuilderUnit($builderConfig);
76+
$routeStackChain->addRouteStackBuilderUnit($builderName, $builderUnit);
8077
}
8178

8279
return $routeStackChain;
8380
}
8481

82+
protected function generateBuilderUnit($config)
83+
{
84+
$pathProvider = $this->getBuilderService($builderConfig, 'provider', 'name');
85+
$existsAction = $this->getBuilderService($builderConfig, 'exists_action', 'strategy');
86+
$notExistsAction = $this->getBuilderService($builderConfig, 'not_exists_action', 'strategy');
87+
88+
$builderUnit = new RouteStackBuilderUnit(
89+
$pathProvider,
90+
$existsAction,
91+
$notExistsAction
92+
);
93+
94+
return $builderUnit;
95+
}
96+
8597
protected function getMapping($classFqn)
8698
{
8799
if (!isset($this->mapping[$classFqn])) {

AutoRoute/RouteStackBuilder.php renamed to AutoRoute/RouteStack/Builder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
44

55
use PHPCR\SessionInterface as PhpcrSession;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
68

79
/**
810
* This class is responsible for building and closing
911
* a RouteStack from a given RouteStackBuilderUnit.
1012
*
1113
* @author Daniel Leech <[email protected]>
1214
*/
13-
class RouteStackBuilder
15+
class Builder
1416
{
1517
protected $phpcrSession;
1618

@@ -19,7 +21,7 @@ public function __construct(PhpcrSession $phpcrSession)
1921
$this->phpcrSession = $phpcrSession;
2022
}
2123

22-
public function build(RouteStack $routeStack, RouteStackBuilderUnitInterface $rsbu, BuilderContext $context)
24+
public function build(RouteStack $routeStack, BuilderUnitInterface $rsbu, BuilderContext $context)
2325
{
2426
$rsbu->pathAction($routeStack, $context);
2527

AutoRoute/RouteStackBuilderUnit.php renamed to AutoRoute/RouteStack/BuilderUnit.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
44

55
use PHPCR\SessionInterface as PhpcrSession;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProviderInterface;
8+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathActionInterface;
9+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
610

711
/**
812
* Represents a route stack builder /unit/.
@@ -12,7 +16,7 @@
1216
*
1317
* @author Daniel Leech <[email protected]>
1418
*/
15-
class RouteStackBuilderUnit implements RouteStackBuilderUnitInterface
19+
class BuilderUnit implements BuilderUnitInterface
1620
{
1721
protected $pathProvider;
1822
protected $existsAction;

AutoRoute/RouteStackBuilderUnitChain.php renamed to AutoRoute/RouteStack/BuilderUnitChain.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
44

5-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Builder;
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
67

78
/**
89
* This class is responsible for aggregating route stack
910
* builder units and executing them sequentially.
1011
*
1112
* @author Daniel Leech <[email protected]>
1213
*/
13-
class RouteStackBuilderUnitChain
14+
class BuilderUnitChain
1415
{
1516
protected $chain;
1617
protected $builder;
1718

18-
public function __construct(RouteStackBuilder $builder)
19+
public function __construct(Builder $builder)
1920
{
2021
$this->builder = $builder;
2122
}
2223

23-
public function addRouteStackBuilderUnit($name, RouteStackBuilderUnitInterface $unit)
24+
public function addBuilderUnit($name, BuilderUnitInterface $unit)
2425
{
2526
$this->chain[$name] = $unit;
2627
}

AutoRoute/RouteStackBuilderUnitInterface.php renamed to AutoRoute/RouteStack/BuilderUnitInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
44

55
use PHPCR\SessionInterface as PhpcrSession;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
68

79
/**
810
* Represents a route stack builder /unit/.
@@ -11,12 +13,12 @@
1113
* build and close a RouteStack.
1214
*
1315
* By design the class implementing this would be the
14-
* RouteStackBuilder which would implement the methods
16+
* RouteStack\Builder which would implement the methods
1517
* with configurable classes.
1618
*
1719
* @author Daniel Leech <[email protected]>
1820
*/
19-
interface RouteStackBuilderUnitInterface
21+
interface BuilderUnitInterface
2022
{
2123
/**
2224
* Provide an ordered list of route names, e.g.

Tests/AutoRoute/RouteStackBuilderTest.php renamed to Tests/AutoRoute/RouteStack/BuilderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\RouteStack\RouteStack;
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\AutoRouteManager;
66
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
77
use Doctrine\Common\Collections\ArrayCollection;
8-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilder;
8+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\Builder;
99

10-
class RouteStackBuilderTest extends \PHPUnit_Framework_TestCase
10+
class BuilderTest extends \PHPUnit_Framework_TestCase
1111
{
1212
public function setUp()
1313
{
1414
$this->phpcrSession = $this->getMock('PHPCR\SessionInterface');
15-
$this->routeStackBuilder = new RouteStackBuilder($this->phpcrSession);
15+
$this->routeStackBuilder = new Builder($this->phpcrSession);
1616
$this->routeStackBuilderUnit = $this->getMock(
17-
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilderUnitInterface'
17+
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\BuilderUnitInterface'
1818
);
1919
$this->builderContext = $this->getMock(
2020
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext'

Tests/AutoRoute/RouteStackBuilderUnitChainTest.php renamed to Tests/AutoRoute/RouteStack/BuilderUnitChainTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\RouteStack\RouteStack;
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
6-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilderUnitChain;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\BuilderUnitChain;
77

8-
class RouteStackBuilderUnitChainTest extends \PHPUnit_Framework_TestCase
8+
class BuilderUnitChainTest extends \PHPUnit_Framework_TestCase
99
{
1010
public function setUp()
1111
{
1212
$this->builder = $this->getMockBuilder(
13-
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilder'
13+
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\Builder'
1414
)->disableOriginalConstructor()->getMock();
1515

16-
$this->builderUnitChain = new RouteStackBuilderUnitChain($this->builder);
16+
$this->builderUnitChain = new BuilderUnitChain($this->builder);
1717
$this->builderUnit1 = $this->getMock(
18-
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilderUnitInterface'
18+
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\BuilderUnitInterface'
1919
);
2020
$this->builderUnit2 = $this->getMockBuilder(
21-
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilderUnitInterface'
21+
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\BuilderUnitInterface'
2222
)->disableOriginalConstructor()->getMock();
2323
$this->builderContext = $this->getMock(
2424
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext'
@@ -36,8 +36,8 @@ public function testExecute()
3636
->method('build');
3737
// ->with($this->builderUnit2, $this->builderContext);
3838

39-
$this->builderUnitChain->addRouteStackBuilderUnit('builder_1', $this->builderUnit1);
40-
$this->builderUnitChain->addRouteStackBuilderUnit('builder_2', $this->builderUnit2);
39+
$this->builderUnitChain->addBuilderUnit('builder_1', $this->builderUnit1);
40+
$this->builderUnitChain->addBuilderUnit('builder_2', $this->builderUnit2);
4141
$this->builderUnitChain->executeChain($this->builderContext);
4242
}
4343
}

Tests/AutoRoute/RouteStackBuilderUnitTest.php renamed to Tests/AutoRoute/RouteStack/BuilderUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\RouteStack;
44

5-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStackBuilderUnit;
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\BuilderUnit;
66

7-
class RouteStackBuilderUnitTest extends \PHPUnit_Framework_TestCase
7+
class BuilderUnitTest extends \PHPUnit_Framework_TestCase
88
{
99
public function setUp()
1010
{
@@ -23,7 +23,7 @@ public function setUp()
2323
$this->routeStack = $this->getMock(
2424
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack'
2525
);
26-
$this->builderUnit = new RouteStackBuilderUnit(
26+
$this->builderUnit = new BuilderUnit(
2727
$this->pathProvider,
2828
$this->pathExists,
2929
$this->pathNotExists

Tests/AutoRoute/RouteStackTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\RouteStack;
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\AutoRouteManager;
6-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\RouteStack;
77

88
class RouteStackTest extends \PHPUnit_Framework_TestCase
99
{
@@ -18,18 +18,18 @@ public function testRouteStack()
1818
$this->rs->addPathElement('bar');
1919
$this->rs->addPathElements(array('foo', 'bar'));
2020

21-
$this->rs->addRouteNode($r1 = new \stdClass);
22-
$this->rs->addRouteNode($r2 = new \stdClass);
23-
$this->rs->addRouteNode($r3 = new \stdClass);
24-
$this->rs->addRouteNode($r4 = new \stdClass);
21+
$this->rs->addRoute($r1 = new \stdClass);
22+
$this->rs->addRoute($r2 = new \stdClass);
23+
$this->rs->addRoute($r3 = new \stdClass);
24+
$this->rs->addRoute($r4 = new \stdClass);
2525

2626
$this->assertFalse($this->rs->isClosed());
2727

2828
$this->rs->close();
2929

3030
$this->assertTrue($this->rs->isClosed());
3131

32-
$res = $this->rs->getRouteNodes();
32+
$res = $this->rs->getRoutes();
3333
$this->assertEquals(array($r1, $r2, $r3, $r4), $res);
3434

3535

@@ -46,9 +46,9 @@ public function testRouteStack()
4646
/**
4747
* @expectedException \RuntimeException
4848
*/
49-
public function testGetRouteNodesOnOpenRouteStack()
49+
public function testGetRoutesOnOpenRouteStack()
5050
{
51-
$this->rs->getRouteNodes();
51+
$this->rs->getRoutes();
5252
}
5353

5454
/**

0 commit comments

Comments
 (0)