@@ -19,37 +19,30 @@ An example mapper from the `symfony cmf sandbox`_
19
19
20
20
use Doctrine\ODM\PHPCR\DocumentClassMapper;
21
21
use Doctrine\ODM\PHPCR\DocumentManager;
22
+ use Doctrine\ODM\PHPCR\Document\Generic;
22
23
23
24
use PHPCR\NodeInterface;
24
25
use PHPCR\PropertyType;
25
26
26
27
class MagnoliaDocumentClassMapper extends DocumentClassMapper
27
28
{
28
- private $templateMap;
29
-
30
- /**
31
- * @param array $templateMap map from mgnl:template values to document class names
32
- */
33
- public function __construct($templateMap)
34
- {
35
- $this->templateMap = $templateMap;
29
+ public function __construct(
30
+ /**
31
+ * @var array<string, string> map from mgnl:template values to document class names
32
+ */
33
+ private array $templateMap
34
+ ) {
36
35
}
37
36
38
37
/**
39
38
* Determine the class name from a given node
40
39
*
41
- * @param DocumentManager
42
- * @param NodeInterface $node
43
- * @param string $className
44
- *
45
- * @return string
46
- *
47
40
* @throws \RuntimeException if no class name could be determined
48
41
*/
49
- public function getClassName(DocumentManager $dm, NodeInterface $node, $className = null)
42
+ public function getClassName(DocumentManager $dm, NodeInterface $node, string $className = null): string
50
43
{
51
44
$className = parent::getClassName($dm, $node, $className);
52
- if ('Doctrine\ODM\PHPCR\Document\ Generic' == $className) {
45
+ if (Generic::class = == $className) {
53
46
if ($node->hasNode('MetaData')) {
54
47
$metaData = $node->getNode('MetaData');
55
48
if ($metaData->hasProperty('mgnl:template')) {
@@ -70,7 +63,7 @@ custom mapper::
70
63
/* prepare the doctrine configuration */
71
64
$config = new \Doctrine\ODM\PHPCR\Configuration();
72
65
$map = array(
73
- 'standard-templating-kit:pages/stkSection' => ' Sandbox\MagnoliaBundle\Document\Section' ,
66
+ 'standard-templating-kit:pages/stkSection' => \ Sandbox\MagnoliaBundle\Document\Section::class ,
74
67
);
75
68
$mapper = new MagnoliaDocumentClassMapper($map);
76
69
$config->setDocumentClassMapper($mapper);
@@ -127,6 +120,8 @@ of instantiating the default one. An example from the `symfony cmf sandbox`_
127
120
128
121
use Symfony\Component\DependencyInjection\Definition;
129
122
use Symfony\Component\DependencyInjection\Reference;
123
+ use Sandbox\MagnoliaBundle\Document\MagnoliaDocumentClassMapper;
124
+ use Sandbox\MagnoliaBundle\Document\Section;
130
125
131
126
$container
132
127
->register('doctrine.odm_configuration', '%doctrine_phpcr.odm.configuration.class%')
@@ -136,10 +131,10 @@ of instantiating the default one. An example from the `symfony cmf sandbox`_
136
131
;
137
132
138
133
$container ->setDefinition('sandbox_amgnolia.odm_mapper', new Definition(
139
- 'Sandbox\MagnoliaBundle\Document\ MagnoliaDocumentClassMapper' ,
134
+ MagnoliaDocumentClassMapper::class ,
140
135
array(
141
136
array(
142
- 'standard-templating-kit:pages/stkSection' => 'Sandbox\MagnoliaBundle\Document\ Section' ,
137
+ 'standard-templating-kit:pages/stkSection' => Section::class ,
143
138
),
144
139
),
145
140
));
0 commit comments