This repository was archived by the owner on Sep 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 18 files changed +2769
-6
lines changed Expand file tree Collapse file tree 18 files changed +2769
-6
lines changed Original file line number Diff line number Diff line change 16
16
class AutoRouteManager
17
17
{
18
18
protected $ dm ;
19
- protected $ metadataFactory ;
19
+ protected $ mapping ;
20
20
protected $ defaultPath ;
21
21
protected $ slugifier ;
22
22
@@ -34,7 +34,7 @@ class AutoRouteManager
34
34
*/
35
35
public function __construct (
36
36
DocumentManager $ dm ,
37
- $ mapping ,
37
+ array $ mapping ,
38
38
SlugifierInterface $ slugifier ,
39
39
$ defaultPath
40
40
)
@@ -231,6 +231,11 @@ public function fetchAutoRoutesForDocument($document)
231
231
return $ routes ;
232
232
}
233
233
234
+ public function getDefaultPath ()
235
+ {
236
+ return $ this ->defaultPath ;
237
+ }
238
+
234
239
protected function isDocumentPersisted ($ document )
235
240
{
236
241
$ metadata = $ this ->dm ->getClassMetadata (get_class ($ document ));
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingAutoRouteBundle \DependencyInjection ;
4
+
5
+ use Symfony \Component \Config \Definition \ConfigurationInterface ;
6
+ use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
7
+
8
+ class Configuration implements ConfigurationInterface
9
+ {
10
+ /**
11
+ * Returns the config tree builder.
12
+ *
13
+ * @return TreeBuilder
14
+ */
15
+ public function getConfigTreeBuilder ()
16
+ {
17
+ $ treeBuilder = new TreeBuilder ();
18
+ $ treeBuilder ->root ('symfony_cmf_routing_auto_route ' )
19
+ ->children ()
20
+ ->scalarNode ('basepath ' )
21
+ ->defaultValue ('/cms/auto-routes ' )
22
+ ->end ()
23
+ ->arrayNode ('auto_route_by_class ' )
24
+ ->useAttributeAsKey ('class ' )
25
+ ->prototype ('array ' )
26
+ ->children ()
27
+ ->scalarNode ('base_path ' )->end ()
28
+ ->scalarNode ('route_method_name ' )->end ()
29
+ ->end ()
30
+ ->end ();
31
+
32
+ return $ treeBuilder ;
33
+ }
34
+ }
35
+
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingAutoRouteBundle \DependencyInjection ;
4
+
5
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
6
+ use Symfony \Component \Config \FileLocator ;
7
+ use Symfony \Component \Config \Definition \Processor ;
8
+ use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
9
+ use Symfony \Component \DependencyInjection \Reference ;
10
+ use Symfony \Component \Config \Loader \LoaderInterface ;
11
+ use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
12
+
13
+ class SymfonyCmfRoutingAutoRouteExtension extends Extension
14
+ {
15
+ /**
16
+ * {@inheritDoc}
17
+ */
18
+ public function load (array $ configs , ContainerBuilder $ container )
19
+ {
20
+ $ processor = new Processor ();
21
+ $ configuration = new Configuration ();
22
+ $ loader = new XmlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
23
+ $ loader ->load ('auto_route.xml ' );
24
+
25
+ $ config = $ processor ->processConfiguration ($ configuration , $ configs );
26
+
27
+ $ keys = array (
28
+ 'basepath ' ,
29
+ 'auto_route_by_class '
30
+ );
31
+
32
+ foreach ($ keys as $ key ) {
33
+ $ container ->setParameter ('symfony_cmf_routing_auto_route. ' .$ key , $ config [$ key ]);
34
+ }
35
+ }
36
+ }
37
+
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <container xmlns =" http://symfony.com/schema/dic/services"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
5
+
6
+ <parameters >
7
+ <parameter key =" symfony_cmf_routing_auto_route.phpcrodm_auto_route_subscriber_class" >Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Subscriber\AutoRouteSubscriber</parameter >
8
+ <parameter key =" symfony_cmf_routing_auto_route.auto_route_manager_class" >Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager</parameter >
9
+ <parameter key =" symfony_cmf_routing_auto_route.basepath" ></parameter >
10
+ <parameter key =" symfony_cmf_routing_auto_route.auto_route_by_class" ></parameter >
11
+ </parameters >
12
+
13
+ <services >
14
+ <service
15
+ id =" symfony_cmf_routing_auto_route.slugifier"
16
+ class =" Symfony\Cmf\Bundle\CoreBundle\Slugifier\CallbackSlugifier"
17
+ >
18
+ <argument >URLify::filter</argument >
19
+ </service >
20
+
21
+ <service
22
+ id =" symfony_cmf_routing_auto_route.auto_route_manager"
23
+ class =" Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager"
24
+ >
25
+ <argument type =" service" id =" doctrine_phpcr.odm.default_document_manager" />
26
+ <argument >%symfony_cmf_routing_auto_route.auto_route_by_class%</argument >
27
+ <argument type =" service" id =" symfony_cmf_routing_auto_route.slugifier" />
28
+ <argument >%symfony_cmf_routing_auto_route.basepath%</argument >
29
+ </service >
30
+ </services >
31
+ </container >
32
+
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingAutoRouteBundle ;
4
+
5
+ use Symfony \Component \HttpKernel \Bundle \Bundle ;
6
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
7
+
8
+ class SymfonyCmfRoutingAutoRouteBundle extends Bundle
9
+ {
10
+ public function build (ContainerBuilder $ container )
11
+ {
12
+ parent ::build ($ container );
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingAutoRouteBundle \Tests \Functional \AutoRoute ;
4
+ use Symfony \Cmf \Bundle \RoutingAutoRouteBundle \Tests \Functional \BaseTestCase ;
5
+
6
+ /**
7
+ * Description here
8
+ *
9
+ * @author Daniel Leech <[email protected] >
10
+ * @date 13/03/08
11
+ */
12
+ class AutoRouteManagerTest extends BaseTestCase
13
+ {
14
+ public function setUp ()
15
+ {
16
+ parent ::setUp ();
17
+ $ this ->arm = $ this ->getContainer ()->get (
18
+ 'symfony_cmf_routing_auto_route.auto_route_manager '
19
+ );
20
+ }
21
+
22
+ public function testContainer ()
23
+ {
24
+ $ res = $ this ->arm ->getDefaultPath ();
25
+ $ this ->assertEquals ('/cms/auto-routes ' , $ res );
26
+
27
+ $ refl = new \ReflectionClass (get_class ($ this ->arm ));
28
+ $ prop = $ refl ->getProperty ('mapping ' );
29
+ $ prop ->setAccessible (true );
30
+ $ res = $ prop ->getValue ($ this ->arm );
31
+
32
+ $ this ->assertEquals (array (
33
+ 'Symfony\Cmf\Bundle\AutoRouteBundle\Tests\Functional\app\Document\Post ' => array (
34
+ 'base_path ' => '/test/posts/test-post ' ,
35
+ 'route_method_name ' => 'getTitle '
36
+ )
37
+ ), $ res );
38
+ }
39
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace Symfony \Cmf \Bundle \RoutingAutoRouteBundle \Tests \Functional ;
4
4
5
+ require __DIR__ .'/app/AppKernel.php ' ;
6
+
5
7
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
6
8
7
9
class BaseTestCase extends WebTestCase
@@ -11,26 +13,31 @@ class BaseTestCase extends WebTestCase
11
13
*/
12
14
protected $ dm ;
13
15
14
- protected function createKernel (array $ options = array ())
16
+ static protected function createKernel (array $ options = array ())
15
17
{
16
18
return new AppKernel (
17
19
isset ($ options ['config ' ]) ? $ options ['config ' ] : 'default.yml '
18
20
);
19
21
}
20
22
21
- public static function setUp (array $ options = array (), $ routebase = null )
23
+ public function getContainer ()
24
+ {
25
+ return self ::$ kernel ->getContainer ();
26
+ }
27
+
28
+ public function setUp (array $ options = array (), $ routebase = null )
22
29
{
23
30
self ::$ kernel = self ::createKernel ($ options );
24
31
self ::$ kernel ->init ();
25
32
self ::$ kernel ->boot ();
26
33
27
- $ this ->dm = self :: $ kernel ->getContainer ()->get ('doctrine_phpcr.odm.document_manager ' );
34
+ $ this ->dm = $ this ->getContainer ()->get ('doctrine_phpcr.odm.document_manager ' );
28
35
29
36
if (null == $ routebase ) {
30
37
return ;
31
38
}
32
39
33
- $ session = self :: $ kernel ->getContainer ()->get ('doctrine_phpcr.session ' );
40
+ $ session = $ this ->getContainer ()->get ('doctrine_phpcr.session ' );
34
41
35
42
if ($ session ->nodeExists ("/test/ $ routebase " )) {
36
43
$ session ->getNode ("/test/ $ routebase " )->remove ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingExtraBundle \Tests \Functional \Testdoc ;
4
+
5
+ use Doctrine \ODM \PHPCR \Mapping \Annotations as PHPCR ;
6
+ use Symfony \Cmf \Bundle \RoutingExtraBundle \Mapping \Annotations as CMFRouting ;
7
+
8
+ /**
9
+ * @PHPCR\Document(
10
+ * referenceable=true
11
+ * )
12
+ */
13
+ class Post
14
+ {
15
+ /**
16
+ * @PHPCR\Id()
17
+ */
18
+ public $ path ;
19
+
20
+ /**
21
+ * @PHPCR\Referrers(filter="routeContent")
22
+ */
23
+ public $ routes ;
24
+
25
+ /**
26
+ * @PHPCR\String()
27
+ */
28
+ public $ title ;
29
+
30
+ public function getTitle ()
31
+ {
32
+ return $ this ->title ;
33
+ }
34
+ }
35
+
Original file line number Diff line number Diff line change
1
+ imports :
2
+ - { resource: parameters.yml }
3
+ - { resource: framework.yml }
4
+ - { resource: monolog.yml }
5
+ - { resource: doctrine.yml }
6
+ - { resource: phpcrodm.yml }
7
+ - { resource: routingautoroute.yml }
Original file line number Diff line number Diff line change
1
+ doctrine :
2
+ dbal :
3
+ driver : %database_driver%
4
+ path : %database_path%
5
+ charset : UTF8
You can’t perform that action at this time.
0 commit comments