Skip to content

Commit 94fb4bf

Browse files
committed
remove obsolete annotation mapping doc, modernize code in examples
1 parent 7df4651 commit 94fb4bf

13 files changed

+161
-891
lines changed

docs/en/cookbook/custom_documentclass_mapper.rst

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,30 @@ An example mapper from the `symfony cmf sandbox`_
1919

2020
use Doctrine\ODM\PHPCR\DocumentClassMapper;
2121
use Doctrine\ODM\PHPCR\DocumentManager;
22+
use Doctrine\ODM\PHPCR\Document\Generic;
2223

2324
use PHPCR\NodeInterface;
2425
use PHPCR\PropertyType;
2526

2627
class MagnoliaDocumentClassMapper extends DocumentClassMapper
2728
{
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+
) {
3635
}
3736

3837
/**
3938
* Determine the class name from a given node
4039
*
41-
* @param DocumentManager
42-
* @param NodeInterface $node
43-
* @param string $className
44-
*
45-
* @return string
46-
*
4740
* @throws \RuntimeException if no class name could be determined
4841
*/
49-
public function getClassName(DocumentManager $dm, NodeInterface $node, $className = null)
42+
public function getClassName(DocumentManager $dm, NodeInterface $node, string $className = null): string
5043
{
5144
$className = parent::getClassName($dm, $node, $className);
52-
if ('Doctrine\ODM\PHPCR\Document\Generic' == $className) {
45+
if (Generic::class === $className) {
5346
if ($node->hasNode('MetaData')) {
5447
$metaData = $node->getNode('MetaData');
5548
if ($metaData->hasProperty('mgnl:template')) {
@@ -70,7 +63,7 @@ custom mapper::
7063
/* prepare the doctrine configuration */
7164
$config = new \Doctrine\ODM\PHPCR\Configuration();
7265
$map = array(
73-
'standard-templating-kit:pages/stkSection' => 'Sandbox\MagnoliaBundle\Document\Section',
66+
'standard-templating-kit:pages/stkSection' => \Sandbox\MagnoliaBundle\Document\Section::class,
7467
);
7568
$mapper = new MagnoliaDocumentClassMapper($map);
7669
$config->setDocumentClassMapper($mapper);
@@ -127,6 +120,8 @@ of instantiating the default one. An example from the `symfony cmf sandbox`_
127120
128121
use Symfony\Component\DependencyInjection\Definition;
129122
use Symfony\Component\DependencyInjection\Reference;
123+
use Sandbox\MagnoliaBundle\Document\MagnoliaDocumentClassMapper;
124+
use Sandbox\MagnoliaBundle\Document\Section;
130125
131126
$container
132127
->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`_
136131
;
137132
138133
$container ->setDefinition('sandbox_amgnolia.odm_mapper', new Definition(
139-
'Sandbox\MagnoliaBundle\Document\MagnoliaDocumentClassMapper',
134+
MagnoliaDocumentClassMapper::class,
140135
array(
141136
array(
142-
'standard-templating-kit:pages/stkSection' => 'Sandbox\MagnoliaBundle\Document\Section',
137+
'standard-templating-kit:pages/stkSection' => Section::class,
143138
),
144139
),
145140
));

docs/en/cookbook/last-modified.rst

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,22 @@ you can get timestamps on your documents by simply adding the mixins:
1515

1616
.. code-block:: php
1717
18-
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
18+
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;
1919
20-
/**
21-
* @PHPCR\Document(
22-
* mixins={"mix:created", "mix:lastModified"}
23-
* )
24-
*/
20+
#[PHPCR\Document(mixins: ["mix:created", "mix:lastModified"])]
2521
class SomeDocument
2622
{
27-
/**
28-
* @PHPCR\Field(type="date", property="jcr:created")
29-
*/
30-
private $created;
23+
#[PHPCR\Field(type: 'date', property: 'jcr:created')]
24+
private ?\DateTimeInterface $created;
3125
32-
/**
33-
* @PHPCR\Field(type="string", property="jcr:createdBy")
34-
*/
35-
private $createdBy;
26+
#[PHPCR\Field(type: 'string', property: 'jcr:createdBy')]
27+
private ?string $createdBy;
3628
37-
/**
38-
* @PHPCR\Field(type="date", property="jcr:lastModified")
39-
*/
40-
private $lastModified;
29+
#[PHPCR\Field(type: 'date', property: 'jcr:lastModified')]
30+
private ?\DateTimeInterface $lastModified;
4131
42-
/**
43-
* @PHPCR\Field(type="string", property="jcr:lastModifiedBy")
44-
*/
45-
private $lastModifiedBy;
32+
#[PHPCR\Field(type: 'string', property: 'jcr:lastModifiedBy')]
33+
private ?string $lastModifiedBy;
4634
}
4735
4836
.. code-block:: xml
@@ -113,29 +101,21 @@ date, write an event listener as follows and register it with the EventManager::
113101
*/
114102
class LastModified
115103
{
116-
/**
117-
* @param LifecycleEventArgs $e
118-
*/
119-
public function prePersist(LifecycleEventArgs $e)
104+
public function prePersist(LifecycleEventArgs $e): void
120105
{
121106
$this->updateLastModifiedProperty($e);
122107
}
123108

124-
/**
125-
* @param LifecycleEventArgs $e
126-
*/
127-
public function preUpdate(LifecycleEventArgs $e)
109+
public function preUpdate(LifecycleEventArgs $e): void
128110
{
129111
$this->updateLastModifiedProperty($e);
130112
}
131113

132114
/**
133115
* If the document has the mixin mix:lastModified then update the field
134116
* that is mapped to jcr:lastModified.
135-
*
136-
* @param LifecycleEventArgs $e
137117
*/
138-
protected function updateLastModifiedProperty(LifecycleEventArgs $e)
118+
private function updateLastModifiedProperty(LifecycleEventArgs $e): void
139119
{
140120
$document = $e->getObject();
141121

docs/en/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Mapping Objects onto a Document Repository
3737

3838
* **Mapping Driver References**:
3939
:doc:`PHP Attributes <reference/attributes-mapping>` |
40-
:doc:`Docblock Annotations (deprecated) <reference/annotations-mapping>` |
4140
:doc:`XML <reference/xml-mapping>` |
4241
:doc:`YAML <reference/yml-mapping>` |
4342
:doc:`Metadata Drivers <reference/metadata-drivers>`

0 commit comments

Comments
 (0)