Permalink
Browse files

Merge pull request #781 from doctrine/childclass-isleaf-doc

document childclasses and isleaf mapping
  • Loading branch information...
dbu committed Apr 3, 2018
2 parents 9692d76 + 613708d commit aabf473e496af9c86d5b2389d098010f322876ad
@@ -24,16 +24,24 @@ you can get timestamps on your documents by simply adding the mixins:
*/
class SomeDocument
{
- /** @PHPCR\Field(type="date", property="jcr:created") */
+ /**
+ * @PHPCR\Field(type="date", property="jcr:created")
+ */
private $created;
- /** @PHPCR\Field(type="string", property="jcr:createdBy") */
+ /**
+ * @PHPCR\Field(type="string", property="jcr:createdBy")
+ */
private $createdBy;
- /** @PHPCR\Field(type="date", property="jcr:lastModified") */
+ /**
+ * @PHPCR\Field(type="date", property="jcr:lastModified")
+ */
private $lastModified;
- /** @PHPCR\Field(type="string", property="jcr:lastModifiedBy") */
+ /**
+ * @PHPCR\Field(type="string", property="jcr:lastModifiedBy")
+ */
private $lastModifiedBy;
}
@@ -45,27 +45,31 @@ Document
Optional attributes:
-- **nodeType**: PHPCR type for this node, default ``nt:unstructured``.
-- **uniqueNodeType**: If this document has a unique node type, set to ``true``
- in order to support outer joins correctly. See
- :ref:`left outer join <_qbref_method_querybuilder_addjoinleftouter>` and
- :ref:`right outer join <_qbref_method_querybuilder_addjoinrightouter>`.
- To register a custom node type, use the ``phpcr:node-type:register`` console
- command (use ``help phpcr:node-type:register`` for the syntax; see :doc:`Tools <tools>`
- for more information). To verify that documents claiming to have unique node types
- are truly unique, use the ``doctrine:phpcr:mapping:verify-unique-node-types`` command.
-- **repositoryClass**: Name of the repository to use for this document.
-- **versionable**: *(string)* Set to ``simple`` or ``full`` to enable versioning
- (respectively simple or full level), ``false`` to disable versioning
- inheritance. Implies *referenceable*. Note that not every PHPCR implementation
- support this feature. See :doc:`Versioning <versioning>`.
-- **referenceable**: Set to true to allow this node to be referenced.
-- **translator**: Determines how translations are stored, one of ``attribute``
- or ``child``. See :ref:`langauge mapping <multilang_mapping>`
-- **mixins**: Optional list of PHPCR mixins that will be added to the node on
- creation. Note that if this field is present, it overwrites the same field
- from the anchestor documents so you have to repeat mixins you want to keep
- if you add a mixins field.
+- **nodeType**: PHPCR type for this node, default ``nt:unstructured``.
+- **uniqueNodeType**: If this document has a unique node type, set to ``true``
+ in order to support outer joins correctly. See
+ :ref:`left outer join <_qbref_method_querybuilder_addjoinleftouter>` and
+ :ref:`right outer join <_qbref_method_querybuilder_addjoinrightouter>`.
+ To register a custom node type, use the ``phpcr:node-type:register`` console
+ command (use ``help phpcr:node-type:register`` for the syntax; see :doc:`Tools <tools>`
+ for more information). To verify that documents claiming to have unique node types
+ are truly unique, use the ``doctrine:phpcr:mapping:verify-unique-node-types`` command.
+- **repositoryClass**: Name of the repository to use for this document.
+- **versionable**: *(string)* Set to ``simple`` or ``full`` to enable versioning
+ (respectively simple or full level), ``false`` to disable versioning
+ inheritance. Implies *referenceable*. Note that not every PHPCR implementation
+ support this feature. See :doc:`Versioning <versioning>`.
+- **referenceable**: Set to true to allow this node to be referenced.
+- **translator**: Determines how translations are stored, one of ``attribute``
+ or ``child``. See :ref:`langauge mapping <multilang_mapping>`
+- **mixins**: Optional list of PHPCR mixins that will be added to the node on
+ creation. Note that if this field is present, it overwrites the same field
+ from the anchestor documents so you have to repeat mixins you want to keep
+ if you add a mixins field.
+- **childClasses**: List of valid child classes (if empty any classes are
+ permitted).
+- **isLeaf**: If the document should act as a leaf (i.e. it can have no
+ children). Mutually exclusive with ``childClasses``.
Minimal example::
@@ -90,9 +94,10 @@ Full example::
* referenceable=true,
* translator="child",
* mixins={"mix:created", "mix:lastModified"}
+ * childClasses={"App\Documents\Article", "App\Documents\Page"}
* )
*/
- class SomeDocument
+ class Article
{
// ...
}
@@ -89,6 +89,70 @@ Some sample mappings:
filter: "a*"
fetchDepth: 3
+Child restriction
+~~~~~~~~~~~~~~~~~
+
+You may either specify which classes may be children of a document or that a
+document is not allowed to have children (i.e. that it is a leaf node).
+
+.. configuration-block::
+
+ .. code-block:: php
+
+ <?php
+ /**
+ * @Document(childClasses={"App\Documents\Article", "App\Documents\Page"})
+ */
+ class ContentFolder
+ {
+ // ...
+ }
+
+ .. code-block:: xml
+
+ <doctrine-mapping>
+ <document class="ContentFolder">
+ <child-class>Article</child-class>
+ <child-class>Page</child-class>
+ <!-- ... -->
+ </document>
+ </doctrine-mapping>
+
+ .. code-block:: yaml
+
+ ContentFolder:
+ # ...
+ child_classes: [ "Article", "Page" ]
+
+To specify that a document can have no children:
+
+.. configuration-block::
+
+ .. code-block:: php
+
+ <?php
+ /**
+ * @Document(isLeaf=true)
+ */
+ class LeafDocument
+ {
+ // ...
+ }
+
+ .. code-block:: xml
+
+ <doctrine-mapping>
+ <document class="LeafDocument" is-leaf="true">
+ <!-- ... -->
+ </document>
+ </doctrine-mapping>
+
+ .. code-block:: yaml
+
+ MyPersistentClass:
+ # ...
+ is_leaf: true
+
References
----------
@@ -78,7 +78,9 @@ to be designated as an document. This can be done through the
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
- /** @PHPCR\Document */
+ /**
+ * @PHPCR\Document
+ */
class MyPersistentClass
{
//...
@@ -7,14 +7,14 @@ the attribute names are slugified as opposed to being camelCase
(``referring-document`` instead of ``referringDocument``). See :doc:`annotations-mapping`.
The following example implements all of the possible XML mapping elements:
-
+
.. code-block:: xml
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
- <document name="Acme\Document\Example" referenceable="true" translator="attribute" versionable="simple">
+ <document name="App\Documents\ContentFolder" referenceable="true" translator="attribute" versionable="simple" is-leaf="false">
<!-- Identification -->
<uuid name="uuid" />
<id name="path" />
@@ -26,6 +26,10 @@ The following example implements all of the possible XML mapping elements:
<child name="block" node-name="block" />
<depth name="depth" />
+ <!-- Valid child classes !-->
+ <child-class>App\Documents\Article</child-class>
+ <child-class>App\Documents\Page</child-class>
+
<!-- PHPCR -->
<node name="phpcrNode" />

0 comments on commit aabf473

Please sign in to comment.