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

Commit 4989bad

Browse files
committed
Started refactoring route patcher / makers
- Patchers and makers are basically the same thing - The "default" patcher is the old route patcher class - All these things implement a single RouteMakerInterface - Will add a "maker" option to the builder unit to specify which maker to use - Defaults to "default" which will delegate depending on the context.
1 parent 32af460 commit 4989bad

File tree

6 files changed

+107
-37
lines changed

6 files changed

+107
-37
lines changed

AutoRoute/RouteMaker.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

AutoRoute/AutoRouteMaker.php renamed to AutoRoute/RouteMaker/AutoRouteMaker.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
44

55
use Doctrine\ODM\PHPCR\DocumentManager;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMakerInterface;
67
use Symfony\Cmf\Bundle\RoutingAutoBundle\Document\AutoRoute;
78

89
/**
@@ -11,7 +12,7 @@
1112
*
1213
* @author Daniel Leech <[email protected]>
1314
*/
14-
class AutoRouteMaker
15+
class AutoRouteMaker implements RouteMakerInterface
1516
{
1617
protected $dm;
1718

@@ -20,7 +21,7 @@ public function __construct(DocumentManager $dm)
2021
$this->dm = $dm;
2122
}
2223

23-
public function createOrUpdateAutoRoute(AutoRouteStack $autoRouteStack)
24+
public function make(RouteStack $routeStack)
2425
{
2526
$context = $autoRouteStack->getContext();
2627
$content = $context->getContent();

AutoRoute/RouteMaker/DefaultMaker.php

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;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMakerInterface;
6+
7+
/**
8+
* Default route maker class - automatically delegates to an
9+
* appropriate maker depending on the context.
10+
*
11+
* @author Daniel Leech <[email protected]>
12+
*/
13+
class RouteMaker implements RouteMakerInterface
14+
{
15+
protected $autoRouteMaker;
16+
protected $patcher;
17+
18+
public function __construct(RouteMakerInterface $autoRouteMaker, RouteMakerInterface $patcher)
19+
{
20+
$this->autoRouteMaker = $autoRouteMaker;
21+
$this->patcher = $patcher;
22+
}
23+
24+
public function make(RouteStack $routeStack)
25+
{
26+
if ($routeStack instanceOf AutoRouteStack) {
27+
$this->autoRouteMaker->make($routeStack);
28+
} else {
29+
$this->patcher->make($routeStack);
30+
}
31+
}
32+
}

AutoRoute/RoutePatcher/GenericPatcher.php renamed to AutoRoute/RouteMaker/GenericMaker.php

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

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

5-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RoutePatcherInterface;
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMakerInterface;
66
use Doctrine\ODM\PHPCR\DocumentManager;
77
use Doctrine\ODM\PHPCR\Document\Generic;
88
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
@@ -13,14 +13,14 @@
1313
*
1414
* @author Daniel Leech <[email protected]>
1515
*/
16-
class GenericPatcher implements RoutePatcherInterface
16+
class GenericMaker implements RouteMakerInterface
1717
{
1818
public function __construct(DocumentManager $dm)
1919
{
2020
$this->dm = $dm;
2121
}
2222

23-
public function patch(RouteStack $routeStack)
23+
public function make(RouteStack $routeStack)
2424
{
2525
$paths = $routeStack->getFullPaths();
2626

AutoRoute/RouteMaker/RouteMaker.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMaker;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMakerInterface;
6+
use Doctrine\ODM\PHPCR\DocumentManager;
7+
use Doctrine\ODM\PHPCR\Document\Generic;
8+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
9+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception\MissingOptionException;
10+
use Symfony\Cmf\Bundle\RoutingExtraBundle\Document\Route;
11+
12+
/**
13+
* This class will make the Route classes using
14+
* Generic documents using.
15+
*
16+
* @author Daniel Leech <[email protected]>
17+
*/
18+
class RouteMaker implements RouteMakerInterface
19+
{
20+
protected $defaults = array();
21+
22+
public function __construct(DocumentManager $dm)
23+
{
24+
$this->dm = $dm;
25+
}
26+
27+
public function init(array $options)
28+
{
29+
$this->defaults = $defaults;
30+
}
31+
32+
public function make(RouteStack $routeStack)
33+
{
34+
$paths = $routeStack->getFullPaths();
35+
36+
foreach ($paths as $path) {
37+
$absPath = '/'.$path;
38+
$doc = $this->dm->find(null, $absPath);
39+
40+
if (null === $doc) {
41+
$doc = new Route;
42+
$doc->setDefaults($this->defaults);
43+
$doc->setId($absPath);
44+
}
45+
46+
$routeStack->addRoute($doc);
47+
}
48+
}
49+
}
50+

AutoRoute/RouteMakerInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
6+
7+
/**
8+
* Classes implementing this interface complete a route stack
9+
* by adding one PHPCR-ODM document for each path element contained
10+
* in the RouteStack.
11+
*
12+
* @author Daniel Leech <[email protected]>
13+
* @date 13/03/24
14+
*/
15+
class RouteMakerInterface
16+
{
17+
public function make(RouteStack $routeStack);
18+
}

0 commit comments

Comments
 (0)