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

Commit 0cc9f7f

Browse files
committed
Added comments
1 parent 77b7f69 commit 0cc9f7f

File tree

7 files changed

+210
-1
lines changed

7 files changed

+210
-1
lines changed

AutoRoute/AutoRouteMaker.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Symfony\Cmf\Bundle\RoutingAutoBundle\Document\AutoRoute;
77

88
/**
9+
* This class is responsible for creating and updating the actual
10+
* AutoRoute documents.
11+
*
912
* @author Daniel Leech <[email protected]>
1013
*/
1114
class AutoRouteMaker

AutoRoute/AutoRouteStack.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function close()
2626

2727
public function addRoute($route)
2828
{
29+
// note that we can't type hint here as this method is overridden.
30+
if (!$route instanceof AutoRoute) {
31+
throw new \BadMethodCallException('You must pass an AutoRoute document to addRoute');
32+
}
33+
2934
parent::addRoute($route);
3035
}
3136
}

AutoRoute/BuilderContext.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
use Symfony\Cmf\Bundle\RoutingExtraBundle\Document\Route;
66

77
/**
8+
* This class might better be called AutoRouteRequest.
9+
* It holds all the RouteStack objects and the content document.
10+
*
11+
* All data needed to create the auto route is contained in this
12+
* class and everything involved in the route building process has
13+
* access to this class.
14+
*
815
* @author Daniel Leech <[email protected]>
916
*/
1017
class BuilderContext
@@ -13,6 +20,12 @@ class BuilderContext
1320
protected $stagedRouteStack;
1421
protected $content;
1522

23+
/**
24+
* Return an ordered array of all routes from
25+
* all stacks.
26+
*
27+
* @return array
28+
*/
1629
public function getRoutes()
1730
{
1831
$routes = array();
@@ -23,11 +36,20 @@ public function getRoutes()
2336
return $routes;
2437
}
2538

39+
/**
40+
* Stage a route stack. TBH this is probably not
41+
* required now. Could probably be replaced simply
42+
* with addRouteStack.
43+
*/
2644
public function stageRouteStack(RouteStack $routeStack)
2745
{
2846
$this->stagedRouteStack = $routeStack;
2947
}
3048

49+
/**
50+
* As with above. This can probably be replaced with something
51+
* simpler.
52+
*/
3153
public function commitRouteStack()
3254
{
3355
if (null === $this->stagedRouteStack) {
@@ -47,17 +69,36 @@ public function commitRouteStack()
4769
$this->stagedRouteStack = null;
4870
}
4971

72+
/**
73+
* Return all route stacks.
74+
*
75+
* @return array
76+
*/
5077
public function getRouteStacks()
5178
{
5279
return $this->routeStacks;
5380
}
5481

82+
/**
83+
* Return the "top" route (last added) in
84+
* the stack.
85+
*
86+
* @return object
87+
*/
5588
public function getTopRoute()
5689
{
5790
$routes = $this->getRoutes();
5891
return end($routes);
5992
}
6093

94+
/**
95+
* Returns the complete path as determined
96+
* by the route stacks.
97+
*
98+
* Note that this path is not absolute.
99+
*
100+
* @return string
101+
*/
61102
public function getFullPath()
62103
{
63104
$paths = array();
@@ -71,11 +112,21 @@ public function getFullPath()
71112

72113
}
73114

115+
/**
116+
* Set the content object (e.g. a blog post)
117+
*
118+
* @param object
119+
*/
74120
public function setContent($content)
75121
{
76122
$this->content = $content;
77123
}
78124

125+
/**
126+
* Returns the content object (e.g. a blog post)
127+
*
128+
* @return object
129+
*/
79130
public function getContent()
80131
{
81132
return $this->content;

AutoRoute/Factory.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,27 @@ public function __construct(ContainerInterface $container, Builder $builder)
3333
$this->builder = $builder;
3434
}
3535

36+
/**
37+
* Register an auto route mapping for the given class.
38+
*
39+
* @param string $classFqn Class to map
40+
* @param array $mapping Mapping configuration
41+
*/
3642
public function registerMapping($classFqn, $mapping)
3743
{
3844
$this->validateMapping($classFqn, $mapping);
3945
$this->mapping[$classFqn] = $mapping;
4046
}
4147

48+
/**
49+
* Register an alias for a service ID of the specified type.
50+
*
51+
* e.g. registerAlias('path_provider', 'specified', 'symfony_cmf_[...]');
52+
*
53+
* @param string $type
54+
* @param string $alias
55+
* @param string $id
56+
*/
4257
public function registerAlias($type, $alias, $id)
4358
{
4459
if (!isset($this->serviceIds[$type])) {
@@ -48,6 +63,16 @@ public function registerAlias($type, $alias, $id)
4863
$this->serviceIds[$type][$alias] = $id;
4964
}
5065

66+
/**
67+
* Creates the route stack builder chain for the given class FQN.
68+
*
69+
* The RouteStackBuilderUnitChain will provide all the route components
70+
* for the content path.
71+
*
72+
* Note that we cache it.
73+
*
74+
* @return RouteStackBuilderUnitChain
75+
*/
5176
public function getRouteStackBuilderUnitChain($classFqn)
5277
{
5378
if (!isset($this->routeStackChains[$classFqn])) {
@@ -57,6 +82,14 @@ public function getRouteStackBuilderUnitChain($classFqn)
5782
return $this->routeStackChains[$classFqn];
5883
}
5984

85+
/**
86+
* Return the build unit which will generate the content name
87+
* route for the given class FQN.
88+
*
89+
* @param string $classFqn
90+
*
91+
* @return BuilderUnit
92+
*/
6093
public function getContentNameBuilderUnit($classFqn)
6194
{
6295
if (!isset($this->contentNameBuilderUnits[$classFqn])) {
@@ -69,6 +102,13 @@ public function getContentNameBuilderUnit($classFqn)
69102
return $this->contentNameBuilderUnits[$classFqn];
70103
}
71104

105+
/**
106+
* Return true if the given class FQN is mapped.
107+
*
108+
* @param string $classFqn
109+
*
110+
* @return boolean
111+
*/
72112
public function hasMapping($classFqn)
73113
{
74114
// @todo: Do we need to support inheritance?

AutoRoute/PathActionInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,28 @@
55
use Symfony\Cmf\Bundle\RoutingExtraBundle\Document\Route;
66

77
/**
8+
* The job of classes implementing this interface is to add
9+
* a Route for each path element in the given RouteStack.
10+
*
11+
* The two scenarios are path "exists" and path "not_exists""
12+
*
813
* @author Daniel Leech <[email protected]>
914
*/
1015
interface PathActionInterface
1116
{
1217
/**
1318
* Initialize with config options
19+
*
20+
* @param array $options
1421
*/
1522
public function init(array $options);
1623

24+
/**
25+
* Perform the action. When the method has finished the
26+
* RouteStack should contain an equal number of routes and
27+
* path elements.
28+
*
29+
* @param RouteStack $stack
30+
*/
1731
public function execute(RouteStack $stack);
1832
}

AutoRoute/PathProviderInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
44

55
/**
6+
* Classes implementing this interface add path elements
7+
* to the RouteStack which are later resolved to routes.
8+
*
69
* @author Daniel Leech <[email protected]>
710
*/
811
interface PathProviderInterface
@@ -13,7 +16,7 @@ interface PathProviderInterface
1316
public function init(array $options);
1417

1518
/**
16-
* Provide a URL
19+
* Add path elements to the route stack
1720
*
1821
* @return string
1922
*/

0 commit comments

Comments
 (0)