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

Commit c8fd23d

Browse files
committed
Fixed DI stuf
1 parent e09e182 commit c8fd23d

File tree

12 files changed

+98
-33
lines changed

12 files changed

+98
-33
lines changed

AutoRoute/AutoRouteManager.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
class AutoRouteManager
1818
{
19-
protected $bucf;
19+
protected $factory;
2020

21-
public function __construct(BuilderUnitChainFactory $bucf)
21+
public function __construct(Factory $factory)
2222
{
23-
$this->bucf = $bucf;
23+
$this->factory = $factory;
2424
}
2525

2626
/**
@@ -35,12 +35,18 @@ public function __construct(BuilderUnitChainFactory $bucf)
3535
*/
3636
public function updateAutoRouteForDocument($document)
3737
{
38+
$classFqn = ClassUtils::getClass($document);
3839
$context = new BuilderContext;
3940
$context->setContent($document);
4041

41-
$builderUnitChain = $this->bucf->getChain(ClassUtils::getClass($document));
42+
// build chain
43+
$builderUnitChain = $this->factory->getRouteStackBuilderUnitChain($classFqn);
4244
$builderUnitChain->executeChain($context);
4345

46+
// persist the auto route
47+
$arm = $this->factory->getAutoRouteMaker($classFqn);
48+
$arm->createOrUpdateAutoRoute($context);
49+
4450
return $context;
4551
}
4652

@@ -67,6 +73,6 @@ public function removeAutoRoutesForDocument($document)
6773
*/
6874
public function isAutoRouteable($document)
6975
{
70-
return $this->bucf->hasMapping(ClassUtils::getClass($document));
76+
return $this->factory->hasMapping(ClassUtils::getClass($document));
7177
}
7278
}

AutoRoute/Factory.php

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

36-
public function registerMapping($classFqn, $config)
36+
public function registerMapping($classFqn, $mapping)
3737
{
38-
$this->mapping[$classFqn] = $config;
38+
$this->validateMapping($classFqn, $mapping);
39+
$this->mapping[$classFqn] = $mapping;
3940
}
4041

4142
public function registerAlias($type, $alias, $id)
@@ -104,7 +105,6 @@ protected function getMapping($classFqn)
104105
}
105106

106107
$mapping = $this->mapping[$classFqn];
107-
$this->validateMapping($classFqn, $mapping);
108108

109109
return $mapping;
110110
}
@@ -146,9 +146,11 @@ private function getBuilderService($builderConfig, $type, $aliasKey)
146146
$alias = $builderConfig[$type][$aliasKey];
147147

148148
if (!isset($this->serviceIds[$type][$alias])) {
149-
throw new \RuntimeException(sprintf('"%s" class with alias "%s" requested, but this alias does not exist.',
149+
throw new \RuntimeException(sprintf(
150+
'"%s" class with alias "%s" requested, but this alias does not exist. Registered aliases "%s"',
150151
$type,
151-
$alias
152+
$alias,
153+
implode(',', array_keys($this->serviceIds[$type]))
152154
));
153155
}
154156

AutoRoute/PathNotExists/CreatePath.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathActionInterface;
66
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
7-
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMakerInterface;
7+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RoutePatcherInterface;
8+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
89

910
/**
1011
* @author Daniel Leech <[email protected]>
1112
*/
1213
class CreatePath implements PathActionInterface
1314
{
14-
protected $routeMaker;
15+
protected $routePatcher;
1516

16-
public function __construct(RouteMakerInterface $routeMaker)
17+
public function __construct(RoutePatcherInterface $routePatcher)
1718
{
18-
$this->routeMaker = $routeMaker;
19+
$this->routePatcher = $routePatcher;
1920
}
2021

2122
public function init(array $options)
2223
{
2324
}
2425

25-
public function execute(BuilderContext $context)
26+
public function execute(RouteStack $routeStack, BuilderContext $context)
2627
{
27-
$this->routeMaker->makeRoutes($context);
28+
$this->routePatcher->makeRoutes($routeStack, $context);
2829
}
2930
}

AutoRoute/PathProvider/SpecifiedProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProviderInterface;
66
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception\MissingOptionException;
77
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext;
8+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack;
89

910
/**
1011
* @author Daniel Leech <[email protected]>
@@ -22,8 +23,8 @@ public function init(array $options)
2223
$this->path = $options['path'];
2324
}
2425

25-
public function providePath(BuilderContext $context)
26+
public function providePath(RouteStack $routeStack, BuilderContext $context)
2627
{
27-
$context->addPath($this->path);
28+
$context->addPathElements(explode('/', $this->path));
2829
}
2930
}

AutoRoute/RouteMaker.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute;
4+
5+
/**
6+
* @author Daniel Leech <[email protected]>
7+
*/
8+
class RouteMaker
9+
{
10+
protected $patcher;
11+
12+
public function __construct(RoutePatcherInterface $patcher)
13+
{
14+
$this->patcher = $patcher;
15+
}
16+
17+
public function makeRoute(RouteStack $routeStack, BuilderContext $context)
18+
{
19+
foreach ($context->getRouteStacks() as $stack) {
20+
$this->patcher->patchStack($stack, $context);
21+
}
22+
}
23+
}

AutoRoute/RoutePatcherInterface.php

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

55
/**
6-
* Classes implementing this interface "patch"
7-
* any missing comonents in/a/routes/path
6+
* Class implementing this interface add any missing routes
7+
* between the last existing path and the terminal route.
8+
*
9+
* e.g. given the following path :
10+
*
11+
* /this/path/exists/this/one/doesnt/CONTENT
12+
*
13+
* If the path "/this/route/exists" exists in PHPCR then
14+
* this class has to add routes to the RouteStack for "this"",
15+
* "one" and "doesnt".
16+
*
17+
* The terminal route name, CONTENT, is the AutoRoute and is
18+
* handled seperately.
819
*
920
* @author Daniel Leech <[email protected]>
1021
*/

DependencyInjection/Compiler/AutoRoutePass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ class AutoRoutePass implements CompilerPassInterface
1515
public function process(ContainerBuilder $container)
1616
{
1717
if (!$container->hasDefinition(
18-
'symfony_cmf_routing_auto.builder_unit_chain_factory'
18+
'symfony_cmf_routing_auto.factory'
1919
)) {
2020
return;
2121
}
2222

2323
$builderUnitChainFactory = $container->getDefinition(
24-
'symfony_cmf_routing_auto.builder_unit_chain_factory'
24+
'symfony_cmf_routing_auto.factory'
2525
);
2626

2727

2828
$types = array(
29-
'path_provider', 'exists_action', 'not_exists_action'
29+
'provider', 'exists_action', 'not_exists_action'
3030
);
3131

3232
foreach ($types as $type) {

DependencyInjection/SymfonyCmfRoutingAutoExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function load(array $configs, ContainerBuilder $container)
2626
$loader->load('not_exists_action.xml');
2727

2828
$config = $processor->processConfiguration($configuration, $configs);
29-
$chainFactoryDef = $container->getDefinition('symfony_cmf_routing_auto.builder_unit_chain_factory');
29+
$chainFactoryDef = $container->getDefinition('symfony_cmf_routing_auto.factory');
3030

3131
// normalize configuration
3232
foreach ($config['auto_route_mapping'] as $classFqn => $config) {

Resources/config/auto_route.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<parameter key="symfony_cmf_routing_auto.phpcrodm_auto_route_listener_class">Symfony\Cmf\Bundle\RoutingAutoBundle\EventListener\AutoRouteListener</parameter>
99
<parameter key="symfony_cmf_routing_auto.auto_route_manager_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\AutoRouteManager</parameter>
10-
<parameter key="symfony_cmf_routing_auto.builder_unit_chain_factory_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderUnitChainFactory</parameter>
11-
<parameter key="symfony_cmf_routing_auto.builder_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Builder</parameter>
10+
<parameter key="symfony_cmf_routing_auto.factory_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Factory</parameter>
11+
<parameter key="symfony_cmf_routing_auto.route_stack_builder_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack\Builder</parameter>
1212
<parameter key="symfony_cmf_routing_auto.route_maker_class">Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMaker\GenericMaker</parameter>
1313

1414
</parameters>
@@ -25,20 +25,20 @@
2525
id="symfony_cmf_routing_auto.auto_route_manager"
2626
class="Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\AutoRouteManager"
2727
>
28-
<argument type="service" id="symfony_cmf_routing_auto.builder_unit_chain_factory"/>
28+
<argument type="service" id="symfony_cmf_routing_auto.factory"/>
2929
</service>
3030

3131
<service id="symfony_cmf_routing_auto.phpcrodm_auto_route_listener" class="%symfony_cmf_routing_auto.phpcrodm_auto_route_listener_class%">
3232
<argument type="service" id="service_container"/>
3333
<tag name="doctrine_phpcr.event_listener" event="onFlush"/>
3434
</service>
3535

36-
<service id="symfony_cmf_routing_auto.builder_unit_chain_factory" class="%symfony_cmf_routing_auto.builder_unit_chain_factory_class%">
36+
<service id="symfony_cmf_routing_auto.factory" class="%symfony_cmf_routing_auto.factory_class%">
3737
<argument type="service" id="service_container"/>
38-
<argument type="service" id="symfony_cmf_routing_auto.builder"/>
38+
<argument type="service" id="symfony_cmf_routing_auto.route_stack_builder"/>
3939
</service>
4040

41-
<service id="symfony_cmf_routing_auto.builder" class="%symfony_cmf_routing_auto.builder_class%">
41+
<service id="symfony_cmf_routing_auto.route_stack_builder" class="%symfony_cmf_routing_auto.route_stack_builder_class%">
4242
<argument type="service" id="doctrine_phpcr.default_session"/>
4343
</service>
4444

Resources/config/path_provider.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
class="%symfony_cmf_routing_auto.provider.specified_class%"
1818
scope="prototype"
1919
>
20-
<tag name="symfony_cmf_routing_auto.path_provider" alias="specified"/>
20+
<tag name="symfony_cmf_routing_auto.provider" alias="specified"/>
2121
</service>
2222

2323
<service
2424
id="symfony_cmf_routing_auto.path_provider.from_object_method"
2525
class="%symfony_cmf_routing_auto.provider.from_object_method_class%"
2626
scope="prototype"
2727
>
28-
<tag name="symfony_cmf_routing_auto.path_provider" alias="from_object_method"/>
28+
<tag name="symfony_cmf_routing_auto.provider" alias="from_object_method"/>
2929
</service>
3030
</services>
3131
</container>

0 commit comments

Comments
 (0)