File tree Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingBundle \Doctrine \Orm ;
4
+
5
+ /**
6
+ * Abstract content repository for PHPCR-ODM
7
+ *
8
+ * @author teito
9
+ */
10
+ class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface
11
+ {
12
+ /**
13
+ * Determine target class and id for this content
14
+ *
15
+ * @param mixed $identifier as produced by getContentId
16
+ *
17
+ * @return array with model first element, id second
18
+ */
19
+ protected function getModelAndId ($ identifier )
20
+ {
21
+ return explode (': ' , $ identifier , 2 );
22
+ }
23
+
24
+ /**
25
+ * {@inheritDoc}
26
+ */
27
+ public function findById ($ id )
28
+ {
29
+ list ($ model , $ modelId ) = $ this ->getModelAndId ($ id );
30
+
31
+ return $ this ->getObjectManager ()->getRepository ($ model )->find ($ modelId );
32
+ }
33
+
34
+ /**
35
+ * {@inheritDoc}
36
+ */
37
+ public function getContentId ($ content )
38
+ {
39
+ if (! is_object ($ content )) {
40
+ return null ;
41
+ }
42
+
43
+ try {
44
+ $ meta = $ this ->getObjectManager ()->getClassMetadata (get_class ($ content ));
45
+ $ ids = $ meta ->getIdentifierValues ($ content );
46
+ if (0 !== count ($ ids )) {
47
+ throw new \Exception ('Multi identifier values not supported in ' . get_class ($ content ));
48
+ }
49
+ return implode (': ' , array (
50
+ get_class ($ content ),
51
+ reset ($ ids )
52
+ ));
53
+ } catch (\Exception $ e ) {
54
+ return null ;
55
+ }
56
+ }
57
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Cmf \Bundle \RoutingBundle \Doctrine \Orm ;
4
+
5
+ use Symfony \Component \Routing \Route as SymfonyRoute ;
6
+ use Symfony \Component \Routing \RouteCollection ;
7
+ use Symfony \Component \Routing \Exception \RouteNotFoundException ;
8
+
9
+ use Symfony \Component \HttpFoundation \Request ;
10
+
11
+ use Symfony \Cmf \Component \Routing \RouteProviderInterface ;
12
+
13
+ /**
14
+ * Provider loading routes from Doctrine
15
+ *
16
+ * This is <strong>NOT</strong> not a doctrine repository but just the route
17
+ * provider for the NestedMatcher. (you could of course implement this
18
+ * interface in a repository class, if you need that)
19
+ *
20
+
21
+ */
22
+ class RouteProvider extends DoctrineProvider implements RouteProviderInterface
23
+ {
24
+ protected function getCandidates ($ url )
25
+ {
26
+ $ candidates = array ();
27
+ if ('/ ' !== $ url ) {
28
+ if (preg_match ('/(.+)\.[a-z]+$/i ' , $ url , $ matches )) {
29
+ $ candidates [] = $ url ;
30
+ $ url = $ matches [1 ];
31
+ }
32
+
33
+ $ part = $ url ;
34
+ while (false !== ($ pos = strrpos ($ part , '/ ' ))) {
35
+ $ candidates [] = $ part ;
36
+ $ part = substr ($ url , 0 , $ pos );
37
+ }
38
+ }
39
+
40
+ $ candidates [] = '/ ' ;
41
+
42
+ return $ candidates ;
43
+ }
44
+
45
+ /**
46
+ * {@inheritDoc}
47
+ */
48
+ public function getRouteByName ($ name , $ parameters = array ())
49
+ {
50
+ }
51
+
52
+ public function getRoutesByNames ($ names , $ parameters = array ())
53
+ {
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments