diff --git a/README.md b/README.md index e2112d04c..4712afcea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHPCR ODM for Doctrine2 +# PHPCR ODM for Doctrine [![Build Status](https://github.com/doctrine/phpcr-odm/actions/workflows/test-application.yaml/badge.svg?branch=1.x)](https://github.com/doctrine/phpcr-odm/actions/workflows/test-application.yaml) [![Latest Stable Version](https://poser.pugx.org/doctrine/phpcr-odm/version.png)](https://packagist.org/packages/doctrine/phpcr-odm) diff --git a/docs/en/reference/annotations-mapping.rst b/docs/en/reference/annotations-mapping.rst index ee167ecc3..912392c09 100644 --- a/docs/en/reference/annotations-mapping.rst +++ b/docs/en/reference/annotations-mapping.rst @@ -4,6 +4,10 @@ Annotation Mapping In this chapter a reference of every PHPCR-ODM annotation is given with short explanations on their context and usage. +.. warning:: + + Annotations have been deprecated in favor of :doc:`Attributes` + Note on usage ------------- @@ -230,12 +234,12 @@ Examples:: /** * @PHPCR\Field(type="string", multivalue=true) */ - protected $keywords; // e.g. array('dog', 'cat', 'mouse') + protected $keywords; // e.g. ['dog', 'cat', 'mouse'] /** * @PHPCR\Field(type="double", assoc="") */ - protected $exchangeRates; // e.g. array('GBP' => 0.810709, 'EUR' => 1, 'USD' => 1.307460) + protected $exchangeRates; // e.g. ['GBP' => 0.810709, 'EUR' => 1, 'USD' => 1.307460] Hierarchy --------- diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index 9b201abbc..6585ef3c9 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -14,7 +14,7 @@ Hierarchy mappings ------------------ We have already seen the ``ParentDocument`` in the previous chapter in the section about -identifier generation. The field with this annotation maps the parent document of this document +identifier generation. The field with this mapping contains the parent document of this document (``PHPCR\NodeInterface::getParent()``). If the repository can determine the document class of the parent, it will use it, otherwise ``Doctrine\ODM\PHPCR\Document\Generic`` is used. @@ -51,21 +51,15 @@ Some sample mappings: .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Parentdocument - */ + #[PHPCR\ParentDocument] private $parent; - /** - * @PHPCR\Child - */ + #[PHPCR\Child] private $mychild; - /** - * @PHPCR\Children(filter="a*", fetchDepth=3) - */ + #[PHPCR\Children(filter: 'a*', fetchDepth: 3)] private $children; .. code-block:: xml @@ -100,9 +94,7 @@ document is not allowed to have children (i.e. that it is a leaf node). .. code-block:: php - Article - Page + Fqn\Article + Fqn\Page @@ -122,7 +114,7 @@ document is not allowed to have children (i.e. that it is a leaf node). ContentFolder: # ... - child_classes: [ "Article", "Page" ] + child_classes: [ "Fqn\Article", "Fqn\Page" ] To specify that a document can have no children: @@ -131,9 +123,7 @@ To specify that a document can have no children: .. code-block:: php ` 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 ` + 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 `. +- **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 ` +- **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:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Document] + class User + { + // ... + } + +Full example:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Document( + repositoryClass: UserRepository::class, + versionable: 'full', + referenceable: true, + translator: 'child', + mixins: ['mix:created', 'mix:lastModified'], + childClasses: [Article::class, Page::class] + )] + class Article + { + // ... + } + +.. note:: + + The ``uniqueNodeType`` attribute is not supported with the sqlite database. + +.. _attref_mappedsuperclass: + +#[MappedSuperclass] +~~~~~~~~~~~~~~~~~~~ + +A mapped superclass is an abstract or concrete class that provides +persistent document state and mapping information for its subclasses +but which is not itself a document. + +.. note:: + + Contrary to ORM, the PHPCR-ODM with its NoSQL nature can handle documents + that extend each other just like any other document, so you only need mapped + superclasses in special situations. See also :doc:`Inheritance Mapping `. + + +Optional parameters: + +- **nodeType**: PHPCR type for this node. Default ``nt:unstructured``. +- **repositoryClass**: Fully qualified name of the repository to use for + documents extending this superclass. +- **translator**: Determines how translations are stored, one of ``attribute`` + or ``child``. See :ref:`language mapping `. + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\MappedSuperclass] + class MappedSuperclassBase + { + // ... fields and methods + } + + #[PHPCR\Document] + class DocumentSubClassFoo extends MappedSuperclassBase + { + // ... fields and methods + } + + +Mapping Fields +-------------- + +You can attribute an instance variable with the ``#[Field]`` attributeto make it +"persistent". + +.. _attref_field: + + +#[Field] +~~~~~~~~ + +parameters: + +- **property**: The PHPCR property name to which this field is stored. + Defaults to the field name. +- **assoc**: Specify that this attribute should be an associative array. The value should + be a string which will be used by the PHPCR node. Set to an empty string to automatically + use the name of the property with that attribute appended by "Keys". +- **multivalue**: ``true`` to specify that this property should be treated as a simple array. + See :ref:`Mapping multivalue properties `. +- **translated**: ``true`` to specify that the property should be translatable, requires the + ``translator`` attribute to be specified in :ref:`#[Document]`. +- **nullable**: ``true`` to specifiy that this property doesn't have a required value, used + when loading a translation, to allow loading a node with a missing translated property. +- **type**: Type of the field, see table below. + +Types: + +- **binary**: Sets the type of the property to binary. +- **boolean**: Sets the type of the property to boolean. +- **date**: Sets the type of the property to DateTime. +- **decimal**: Sets the type of the property to decimal, + the decimal field uses the BCMath library which supports numbers of any size + or precision. +- **double**: Sets the type of the property to double. The PHP type will be **float**. +- **long**: Sets the type of the property to long. The PHP type will be **integer**. +- **name**: The property must be a valid XML CNAME value + and can be used to store a valid node name. +- **path**: The property must be a valid PHPCR node path + and can be used to store an arbitrary reference to another node. +- **string**: Sets the type of the property to string. +- **uri**: The property will be validated as an URI. + +Examples:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Field(type: 'string')] + protected $author; + + #[PHPCR\Field(type: 'string', translated: true)] + protected $title; + + #[PHPCR\Field(type: 'string', translated: true, nullable: true)] + protected $subTitle; + + #[PHPCR\Field(type: 'boolean')] + protected $enabled; + + #[PHPCR\Field(type: 'string', multivalue: true)] + protected $keywords; // e.g. ['dog', 'cat', 'mouse'] + + #[PHPCR\Field(type: 'double', assoc: '')] + protected $exchangeRates; // e.g. ['GBP' => 0.810709, 'EUR' => 1, 'USD' => 1.307460] + +Hierarchy +--------- + +These mappings mark the properties to contain instances of Documents +above or below the current Document in the document hierarchy, or information +about the state of the document within the hierarchy. They need to be +specified inside the instance variables associated PHP DocBlock comment. + +.. _attref_child: + +#[Child] +~~~~~~~~ + +The property will be populated with the named document +directly below the instance variables document class in the document hierarchy. + +Required parameters: + +- **nodeName**: PHPCR Node name of the child document to map, this should be a string. + +Optional parameters: + +- **cascade**: |cascade_definition| See :ref:`assocmap_cascading` + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Child(name: 'Preferences')] + protected $preferences; + +.. _attref_children: + +#[Children] +~~~~~~~~~~~ + +The property will be populated with Documents directly below the +instance variables document class in the document hierarchy. + +Optional parameters: + +- **filter**: Child name filter; only return children whose names match the given filter. +- **fetchDepth**: Performance optimisation, number of levels to pre-fetch and cache, + this should be an integer. +- **ignoreUntranslated**: Set to false to *not* throw exceptions on untranslated child + documents. +- **cascade**: |cascade_definition| See :ref:`assocmap_cascading` + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Children(filter: 'a*', fetchDepth: 3)] + private $children; + +.. _attref_depth: + +#[Depth] +~~~~~~~~ + +The property will be populated with an integer value +representing the depth of the document within the document hierarchy:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Depth] + private $depth; + +.. _attref_parentdocument: + +#[ParentDocument] +~~~~~~~~~~~~~~~~~ + +Optional parameters: + +- **cascade**: |cascade_definition| See :ref:`assocmap_cascading` + +The property will contain the nodes parent document. Assigning +a different parent will result in a move operation:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\ParentDocument] + private $parent; + +Identification +-------------- + +These mappings help to manage the identification of the document class. + +.. _attref_id: + +#[Id] +~~~~~ + +The property will be marked with the documents +identifier. The ID is the **full path** to the document in the document hierarchy. +See :ref:`identifiers `. + +Required parameters: + +- **strategy**: How to generate IDs, one of ``NONE``, ``REPOSITORY``, ``ASSIGNED`` or ``PARENT``, default + is ``PARENT`` See :ref:`generation strategies `. + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Id] + protected $id; // e.g. /path/to/mydocument + +.. _attref_nodename: + +#[Nodename] +~~~~~~~~~~~ + +Mark the property as representing the name of the node. The name +of the node is the last part of the :ref:`ID `. Changing the marked variable will update +the nodes ID:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Id] + protected $id; // e.g. /path/to/mydocument + + #[PHPCR\Nodename] + protected $nodeName; // e.g. mydocument + +.. _attref_uuid: + +#[Uuid] +~~~~~~~ + +The property will be populated with a UUID +(Universally Unique Identifier). The UUID is immutable. For +this field to be reliably populated the document should be +*referenceable*:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Uuid] + protected $uuid; // e.g. 508d6621-0c20-4972-bf0e-0278ccabe6e5 + +Lifcycle callbacks +------------------ + +These attributes are used to map information on methods of a document. +The method is called automatically by the ODM on the +:ref:`lifecycle event ` corresponding to the attribute. + +.. note:: + + Unlike the Doctrine ORM it is **not** necessary to specify a ``#[HasLifecycleCallbacks]`` + attribute. + +.. _attref_postload: + +#[PostLoad] +~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``postLoad`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PostLoad] + public function doSomethingOnPostLoad() + { + // ... do something after the Document has been loaded + } + +.. _attref_postpersist: + +#[PostPersist] +~~~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``postPersist`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PostPersist] + public function doSomethingOnPostPersist() + { + // ... do something after the document has been persisted + } + +.. _attref_postremove: + +#[PostRemove] +~~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``postRemove`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PostRemove] + public function doSomethingOnPostRemove() + { + // ... do something after the document has been removed + } + +.. _attref_postupdate: + +#[PostUpdate] +~~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``postUpdate`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PostUpdate] + public function doSomethingOnPostUpdate() + { + // ... do something after the document has been updated + } + +.. _attref_prepersist: + +#[PrePersist] +~~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``prePersist`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PrePersist] + public function doSomethingOnPrePersist() + { + // ... do something before the document has been persisted + } + +.. _attref_preremove: + +#[PreRemove] +~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``preRemove`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PreRemove] + public function doSomethingOnPreRemove() + { + // ... do something before the document has been removed + } + +.. _attref_preupdate: + +#[PreUpdate] +~~~~~~~~~~~~ + +Life cycle callback. The marked method will be called automatically on the ``preUpdate`` +event. See :ref:`lifecycle callbacks ` for further explanations:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\PreUpdate] + public function doSomethingOnPreUpdate() + { + // ... do something before the document has been updated + } + +PHPCR +----- + +.. _attref_node: + +#[Node] +~~~~~~~ + +The property will be populated with the underlying +PHPCR node. See :ref:`node field mapping `. + +References +---------- + +.. _attref_referencemany: + +#[ReferenceMany] +~~~~~~~~~~~~~~~~ + +Optional parameters: + +- **targetDocument**: Specify type of target document class. Note that this + is an optional parameter and by default you can associate *any* document. +- **strategy**: One of ``weak``, ``hard`` or ``path``. See :ref:`reference other documents `. + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\ReferenceMany(targetDocument: PhoneNumber::class, strategy: 'hard')] + protected $phoneNumbers; + +.. _attref_referenceone: +.. _attref_reference: + +#[ReferenceOne] +~~~~~~~~~~~~~~~ + +Optional parameters: + +- **targetDocument**: Specify type of target document class. Note that this + is an optional parameter and by default you can associate *any* document. +- **strategy**: One of `weak`, `hard` or `path`. See :ref:`reference other documents `. +- **cascade**: |cascade_definition| See :ref:`assocmap_cascading` + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\ReferenceOne(targetDocument: Contact::class, strategy: 'hard')] + protected $contact; + +.. _attref_referrers: + +#[Referrers] +~~~~~~~~~~~~ + +Mark the property to contain a collection of the documents +of the given document class which refer to this document. + +Required parameters: + +- **referringDocument**: Full class name of referring document, the instances + of which should be collected in the property. +- **referencedBy**: Name of the property from the referring document class + which refers to this document class. + +Optional parameters: + +- **cascade**: |cascade_definition| See :ref:`assocmap_cascading` + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Referrers(referringDocument: Address::class, referencedBy: 'addressbook')] + protected $addresses; + +#[MixedReferrers] +~~~~~~~~~~~~~~~~~ + +Mark the property to hold a collection of *all* documents +which refer to this document, regardless of document class. + +Optional parameters: + +- **referenceType**: One of ``weak`` or ``hard``. + +.. code-block:: php + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\MixedReferrers] + protected $referrers; + +Translation +----------- + +These attributes only apply to documents where the ``translator`` attribute is +specified in :ref:`#[Document]`. + +Example:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Document(translator: 'attribute')] + class MyDocument + { + #[PHPCR\Locale] + protected $locale; + + #[PHPCR\Field(type: 'string', translated: true)] + protected $title; + } + +.. _attref_locale: + +#[Locale] +~~~~~~~~~ + +Identifies the property as the field in which to store +the documents current locale. + +Versioning +---------- + +These attributes only apply to documents where the ``versionable`` attribute is +specified in :ref:`#[Document]`. + +See :ref:`versioning mappings `. + +Example:: + + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; + + #[PHPCR\Document(versionable: 'simple')] + class MyPersistentClass + { + #[PHPCR\VersionName] + private $versionName; + + #[PHPCR\VersionCreated] + private $versionCreated; + } + +.. _attref_versioncreated: + +#[VersionCreated] +~~~~~~~~~~~~~~~~~ + +The property will be populated with the date +that the current document version was created. Applies only to +documents with the versionable attribute. + +.. _attref_versionname: + +#[VersionName] +~~~~~~~~~~~~~~ + +The property will be populated with the name +of the current version as given by PHPCR. + +.. |cascade_definition| replace:: One of ``persist``, ``remove``, ``merge``, ``detach``, ``refresh``, ``translation`` or ``all``. diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index d6d298779..f8e7ae06a 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -10,23 +10,23 @@ Mapping Drivers Doctrine provides several different ways for specifying object-document mapping metadata: +- PHP Attributes +- Docblock Annotations (deprecated) +- XML +- YAML -- Docblock Annotations -- XML -- YAML - -This manual usually mentions docblock annotations in all the examples +This manual usually mentions PHP attributes in all the examples that are spread throughout all chapters, however for many examples alternative YAML and XML examples are given as well. There are dedicated reference chapters for XML and YAML mapping, respectively that explain them -in more detail. There is also an Annotation reference chapter. +in more detail. There is also an Attribute and an Annotation reference chapter. .. note:: If you're wondering which mapping driver gives the best performance, the answer is: They all give exactly the same performance. Once the metadata of a class has - been read from the source (annotations, xml or yaml) it is stored + been read from the source (attributes, xml or yaml) it is stored in an instance of the ``Doctrine\ODM\PHPCR\Mapping\ClassMetadata`` class and these instances are stored in the metadata cache. Therefore at the end of the day all drivers perform equally well. If you're not @@ -35,52 +35,29 @@ in more detail. There is also an Annotation reference chapter. support in PHP. -Introduction to Docblock Annotations ------------------------------------- - -You've probably used docblock annotations in some form already, -most likely to provide documentation metadata for a tool like -``PHPDocumentor`` (@author, @link, ...). Docblock annotations are a -tool to embed metadata inside the documentation section which can -then be processed by some tool. Doctrine generalizes the concept -of docblock annotations so that they can be used for any kind of -metadata and so that it is easy to define new docblock annotations. -In order to allow more involved annotation values and to reduce the -chances of clashes with other docblock annotations, the Doctrine -docblock annotations feature an alternative syntax that is heavily -inspired by the Annotation syntax introduced in Java 5. - -The implementation of these enhanced docblock annotations is -located in the ``Doctrine\Common\Annotations`` namespace and -therefore part of the Common package. Doctrine docblock -annotations support namespaces and nested annotations among other -things. The Doctrine PHPCR-ODM defines its own set of docblock -annotations for supplying object-document mapping metadata. - -.. note:: +Introduction to PHP Attributes +------------------------------ - If you're not comfortable with the concept of docblock - annotations, don't worry, as mentioned earlier Doctrine provides - XML and YAML alternatives and you could easily implement your own - favourite mechanism for defining PHPCR-ODM metadata. +PHP attributes are an official language replacement for the informal +docblock annotations. They allow to embed metadata next to the code. +The Doctrine PHPCR-ODM defines its own set of attributes to supply +object-document mapping metadata. Persistent classes ------------------ In order to mark a class for object-document persistence it needs to be designated as an document. This can be done through the -``@Document`` marker annotation. +``#[Document]`` marker attribute. .. configuration-block:: .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class MyPersistentClass { //... @@ -99,7 +76,7 @@ to be designated as an document. This can be done through the MyPersistentClass: # ... -There is a couple of options you can specify for the document mapping. +There is a couple of parameters you can specify for the document mapping. Some of them are explained here, the rest in the chapters on :ref:`References `, :doc:`Multilanguage ` and :doc:`Versioning `. @@ -146,7 +123,7 @@ information. .. note:: - DateTime types are compared by reference, not by value. Doctrine updates this values + DateTime types are compared by reference, not by value. Doctrine updates these values if the reference changes and therefore behaves as if these objects are immutable value objects. .. warning:: @@ -172,12 +149,11 @@ that hold scalar values like strings, numbers, etc, or arrays thereof. Although references are also stored as properties in PHPCR, they have their own mappings - see the chapter "Association Mapping". -To mark a property for relational persistence the ``@Field`` -docblock annotation is used. This annotation requires at least 1 attribute -to be set, the ``type``. The ``type`` attribute -specifies the Doctrine Mapping Type to use for the field. If the -type is not specified, PHPCR-ODM will try to let the PHPCR implementation determine -a suitable type. +To mark a property for relational persistence the ``#[Field]`` attribute +is used. This attribute requires at least the ``type`` parameter to be set. +The ``type`` parameter specifies the Doctrine Mapping Type to use for the +field. If the type is not specified, PHPCR-ODM will try to let the PHPCR +implementation determine a suitable type. Example: @@ -185,21 +161,15 @@ Example: .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class MyPersistentClass { - /** - * @PHPCR\Field(type="long") - */ + #[PHPCR\Field(type: 'long')] private $count; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: 'string')] private $name; // type defaults to string //... } @@ -231,19 +201,16 @@ as the field names. Mapping to a differently named PHPCR property ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -To specify a different name for the column, you -can use the ``property`` attribute of the Column annotation as -follows: +To specify a different name for the column, you can use the ``property`` +parameter of the Column attribute follows: .. configuration-block:: .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Field(property="db_name") - */ + #[PHPCR\Field(property: 'db_name'"')] private $myField; .. code-block:: xml @@ -276,11 +243,9 @@ Unless specified as true, properties are considered single value. .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Field(type="string", multivalue=true) - */ + #[PHPCR\Field(type: 'string', multivalue: true)] private $names; .. code-block:: xml @@ -311,16 +276,12 @@ the list keys. .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Field(type="string", assoc="") - */ + #[PHPCR\Field(type: 'string', assoc: '')] private $names; - /** - * @PHPCR\Field(type="string", assoc="listArraykeys") - */ + #[PHPCR\Field(type: 'string', assoc: 'listArraykeys')] private $list; .. code-block:: xml @@ -345,7 +306,7 @@ the list keys. Summary ~~~~~~~ -These are all attributes of the Property annotation. The ORM knows quite a few validation attributes +These are all parameters of the property mapping. The ORM knows quite a few validation parameters because they are used to generate the database schema. As PHPCR-ODM does not (yet) generate PHPCR node type definitions, there is no need for validation. @@ -374,18 +335,21 @@ Every document has an identifier. The id in PHPCR-ODM is the PHPCR path. .. note:: - The id being the path, it is not totally immutable. When the document is moved either explicitly - with DocumentManager::move() or by assignment of a different @Field(type="name") or @ParentDocument, the - id will change. This was discussed thoroughly and is considered the best solution. + The id being the path, it is not totally immutable. When the document is + moved either explicitly with ``DocumentManager::move()`` or by assignment + of a different ``#[Field(type: 'name')]`` or ``#[ParentDocument]``, the id + will change. This was discussed thoroughly and is considered the best solution. - If you need to reference a document reliably even when moving, look at the @ReferenceOne and the @Uuid - annotations explained in the :doc:`next chapter `. + If you need to reference a document reliably even when moving, look at the + ``#[ReferenceOne]`` and the ``#[Uuid]`` attributes explained in the + :doc:`next chapter `. -While you can manually assign the id, this is not recommended. When manually assigning, you need -to ensure that the parent document resulting from the assigned path exists. The recommended way -is to use the @Parentdocument and @Nodename annotations to place the document in the tree. -When using that strategy, you need not have a property with the @Id annotation - though you can -if you want to have access to the path for something. +While you can manually assign the id, this is not recommended. When manually +assigning, you need to ensure that the parent document defined in the assigned +path exists. The recommended way is to use the ``#[ParentDocument]`` and +``#[Nodename]`` attributes to place the document in the tree. When using that +strategy, you need not have a property with the ``#[Id]`` attribute - though if +you need access to the path for something, you can also map the id. .. _basicmapping_identifier_generation_strategies: @@ -397,13 +361,13 @@ You can specify one of them explicitly on the id mapping, or let the PHPCR-ODM pick a fitting one. The order is: - Explicitly specified strategy on the ``id`` mapping, for example - ``@Id(strategy="repository");`` -- If the document has a @ParentDocument and a @Nodename field, the + ``#[PHPCR\Id(strategy: 'repository')]`` +- If the document has a ``#[ParentDocument]`` and a ``#[Nodename]`` field, the ``parent`` is used to determine the id from this information. This is the most failsave strategy as it will ensure that there is a PHPCR parent existing for the document; -- If only an @ParentDocument field is present, the ``auto`` takes - the path from the @ParentDocument as the parent id generator does, but +- If only an ``#[ParentDocument]`` field is present, the ``auto`` takes + the path from the ``#[ParentDocument]`` as the parent id generator does, but generates the node name automatically using the PHPCR ``addNodeAutoNamed`` method; - If there is only an id field, the ``assigned`` is used. It expects @@ -418,11 +382,11 @@ implement any logic you might need. Parent and name strategy (recommended) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -This strategy uses the @Nodename (name of this node) and -@ParentDocument (PHPCR-ODM document that is the parent). The id is generated +This strategy uses the ``#[Nodename]`` (name of this node) and +``#[ParentDocument]`` (PHPCR-ODM document that is the parent). The id is generated as the id of the parent concatenated with '/' and the Nodename. -If you supply a ParentDocument annotation, the strategy is automatically set to +If you supply a ParentDocument attribute, the strategy is automatically set to parent. This strategy will check the parent and the name and will fall back to the assigned id if either is missing. @@ -431,16 +395,12 @@ the assigned id if either is missing. .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Parentdocument - */ + #[PHPCR\ParentDocument] private $parent; - /** - * @PHPCR\Nodename - */ + #[PHPCR\Nodename] private $nodename; .. code-block:: xml @@ -480,11 +440,9 @@ representing any PHPCR-ODM document, though.) .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Id - */ + #[PHPCR\Id] private $id; .. code-block:: xml @@ -521,11 +479,9 @@ This gives you full control how you want to build the id path. .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Id(strategy="repository") - */ + #[PHPCR\Id(strategy: 'repository')] private $id; .. code-block:: xml @@ -545,40 +501,33 @@ This gives you full control how you want to build the id path. generator: strategy: repository -The corresponding code could look like this:: +The document code could look like this:: namespace Demo; - use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface; - use Doctrine\ODM\PHPCR\DocumentRepository as BaseDocumentRepository; - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document(repositoryClass="Demo\DocumentRepository") - */ + #[PHPCR\Document(repositoryClass: DocumentRepository::class)] class Document { - /** - * @PHPCR\Id(strategy="repository") - */ + #[PHPCR\Id(strategy: 'repository')] private $id; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: 'string')] private $title; //... } +And the corresponding repository like this:: + + namespace Demo; + + use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface; + use Doctrine\ODM\PHPCR\DocumentRepository as BaseDocumentRepository; + class DocumentRepository extends BaseDocumentRepository implements RepositoryIdInterface { - /** - * Generate a document id - * - * @param object $document - * @return string - */ - public function generateId($document, $parent = null) + public function generateId(Document $document, object $parent = null): string { return '/functional/'.$document->getTitle(); } diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index a56512ffd..78ca88e5d 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -41,7 +41,7 @@ the life-time of their registered documents. all references to documents have been removed from the unit of work. This event is not a lifecycle callback; - loadClassMetadata - occurs after mapping metadata for a class has been loaded - from a mapping source (annotations/xml/yaml). This event is not a lifecycle + from a mapping source (attributes/xml/yaml). This event is not a lifecycle callback. - postLoadTranslation - occurs when a translation of a document has been loaded from the repository. @@ -142,81 +142,61 @@ event occurs. .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\PrePersist - */ + #[PHPCR\PrePersist] public function doStuffOnPrePersist() { $this->createdAt = date('Y-m-d H:m:s'); } - /** - * @PHPCR\PrePersist - */ + #[PHPCR\PrePersist] public function doOtherStuffOnPrePersist() { $this->value = 'changed from prePersist callback!'; } - /** - * @PHPCR\PostPersist - */ + #[PHPCR\PostPersist] public function doStuffOnPostPersist() { $this->value = 'changed from postPersist callback!'; } - /** - * @PHPCR\PostLoad - */ + #[PHPCR\PostLoad] public function doStuffOnPostLoad() { $this->value = 'changed from postLoad callback!'; } - /** - * @PHPCR\PreUpdate - */ + #[PHPCR\PreUpdate] public function doStuffOnPreUpdate() { $this->value = 'changed from preUpdate callback!'; } - /** - * @PHPCR\PreBindTranslation - */ + #[PHPCR\PreBindTranslation] public function doStuffOnPreBindTranslation() { $this->value = 'changed from preBindTranslation callback!'; } - /** - * @PHPCR\PostBindTranslation - */ + #[PHPCR\PostBindTranslation] public function doStuffOnPostBindTranslation() { $this->value = 'changed from postBindTranslation callback!'; } - /** - * @PHPCR\postLoadTranslation - */ + #[PHPCR\postLoadTranslation] public function doStuffOnPostLoadTranslation() { $this->value = 'changed from postLoadTranslation callback!'; } - /** - * @PHPCR\PreRemoveTranslation - */ + #[PHPCR\PreRemoveTranslation] public function doStuffOnPreRemoveTranslation() { $this->value = 'changed from preRemoveTranslation callback!'; } - /** - * @PHPCR\PostRemoveTranslation - */ + #[PHPCR\PostRemoveTranslation] public function doStuffOnPostRemoveTranslation() { $this->value = 'changed from postRemoveTranslation callback!'; @@ -251,7 +231,7 @@ listed in the previous Lifecycle Events section. .. note:: - Contrary to the ORM, PHPCR-ODM does **not** use the @HasLifecycleCallbacks marker. + Contrary to the ORM, PHPCR-ODM does **not** use the ``HasLifecycleCallbacks`` marker. Listening to Lifecycle Events diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index 2f0e0d3de..0d106d3b6 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -13,7 +13,7 @@ to semantically broken data structures. Overwriting mixins works as overwriting any other setting. This means that if your mapping has any mixins, you need to explicitly repeat any mixins - from anchestor classes that you want to keep. + from ancestor classes that you want to keep. Typically, the purpose of such inheritance is to model the is-a relationship in your models and to reuse the mappings and functions of the base class. diff --git a/docs/en/reference/installation-configuration.rst b/docs/en/reference/installation-configuration.rst index 77c70b655..0ae7fc8e1 100644 --- a/docs/en/reference/installation-configuration.rst +++ b/docs/en/reference/installation-configuration.rst @@ -52,8 +52,9 @@ Bootstrap will roughly look like this:: $workspace = 'default'; $user = 'admin'; $pass = 'admin'; - $repository = \Jackalope\RepositoryFactoryJackrabbit::getRepository( - array('jackalope.jackrabbit_uri' => 'http://localhost:8080/server')); + $repository = \Jackalope\RepositoryFactoryJackrabbit::getRepository([ + 'jackalope.jackrabbit_uri' => 'http://localhost:8080/server', + ]); $credentials = new \PHPCR\SimpleCredentials($user, $pass); $session = $repository->login($credentials, $workspace); @@ -75,20 +76,20 @@ Bootstrap will roughly look like this when using mysql as storage backend:: $user = 'admin'; $pass = 'admin'; - $params = array( + $params = [ 'driver' => 'pdo_mysql', // or pdo_pgsql 'host' => 'localhost', 'user' => $user, 'password' => $pass, 'dbname' => 'phpcr_odm_tutorial', - ); + ]; // Bootstrap Doctrine DBAL $dbConn = \Doctrine\DBAL\DriverManager::getConnection($params); - $repository = \Jackalope\RepositoryFactoryDoctrineDBAL::getRepository( - array('jackalope.doctrine_dbal_connection' => $dbConn) - ); + $repository = \Jackalope\RepositoryFactoryDoctrineDBAL::getRepository([ + 'jackalope.doctrine_dbal_connection' => $dbConn, + ]); // dummy credentials to comply with the API $credentials = new \PHPCR\SimpleCredentials(null, null); $session = $repository->login($credentials, $workspace); @@ -99,11 +100,11 @@ credentials are ignored. Jackalope Doctrine DBAL also works with sqlite. Use the following parameters:: - $params = array( + $params = [ 'driver' => 'pdo_sqlite', 'dbname' => 'odm', 'path' => '/tmp/jackalope.db', - ); + ]; Install Midgard2 PHPCR provider @@ -123,7 +124,7 @@ Bootstrap will roughly look like this when using mysql as storage backend:: $user = 'admin'; $pass = 'password'; - $params = array( + $params = [ 'midgard2.configuration.db.type' => 'MySQL', 'midgard2.configuration.db.name' => 'phpcr', 'midgard2.configuration.db.host' => 'localhost', @@ -131,7 +132,7 @@ Bootstrap will roughly look like this when using mysql as storage backend:: 'midgard2.configuration.db.password' => 'midgard', 'midgard2.configuration.blobdir' => '/some/path/for/blobs', 'midgard2.configuration.db.init' => true, - ); + ]; $repository = \Midgard\PHPCR\RepositoryFactory::getRepository($params); $credentials = new \PHPCR\SimpleCredentials($user, $pass); @@ -149,13 +150,13 @@ mysql driver of midgard to connect to the database. Midgard can also use sqlite, with the following parameters:: - $params = array( + $params = [ 'midgard2.configuration.db.type' => 'SQLite', 'midgard2.configuration.db.name' => 'odm', 'midgard2.configuration.db.dir' => '/tmp', 'midgard2.configuration.blobdir' => '/tmp/blobs' 'midgard2.configuration.db.init' => true, - ); + ]; Configuration ============= @@ -198,39 +199,20 @@ Prepare the mapping driver In order to make PHPCR-ODM understand your documents, you need to provide mappings. -You can choose between the drivers for annotations, xml and yml configuration files. +You can choose between the drivers for attributes, xml and yml configuration files. Add the respective code right after the autoloading. See later in this chapter for more options with the mapping drivers. -Annotation Mapping Driver +Attributes Mapping Driver ^^^^^^^^^^^^^^^^^^^^^^^^^ -With the annotation driver, you can annotate the fields in your document +With the attributes driver, you can add attributes to your document classes with the mapping metadata:: - use Doctrine\Common\Annotations\AnnotationRegistry; - use Doctrine\Common\Annotations\AnnotationReader; - use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver; + use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver; - AnnotationRegistry::registerLoader(array($autoload, 'loadClass')); - - $reader = new AnnotationReader(); - $driver = new AnnotationDriver($reader, array('/path/to/your/document/classes')); - -.. note:: - - Since PHPCR-ODM 1.1, the annotations are autoloaded like any other class. - - With version 1.0, you needed to register the annotation file:: - - use Doctrine\Common\Annotations\AnnotationRegistry; - - AnnotationRegistry::registerLoader(function($class) use ($autoload) { - $autoload->loadClass($class); - return class_exists($class, false); - }); - AnnotationRegistry::registerFile(__DIR__.'/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php'); + $driver = new AttributeDriver(['/path/to/your/document/classes']); XML Mapping Driver ^^^^^^^^^^^^^^^^^^ @@ -240,7 +222,7 @@ documents and PHPCR:: use Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver; - $driver = new XmlDriver(array('/path/to/your/xml-mapping/files')); + $driver = new XmlDriver(['/path/to/your/xml-mapping/files']); YML Mapping Driver ^^^^^^^^^^^^^^^^^^ @@ -249,7 +231,7 @@ Your project must require symfony/yaml in composer.json:: use Doctrine\ODM\PHPCR\Mapping\Driver\YamlDriver; - $driver = new YamlDriver(array('/path/to/your/yml-mapping/files')); + $driver = new YamlDriver(['/path/to/your/yml-mapping/files']); Quick Configuration Example @@ -265,15 +247,15 @@ A complete configuration could look like this:: /* --- see above for sample bootstrapping code of other repository implementations --- */ - $params = array( + $params = [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => $user, 'password' => $pass, 'dbname' => 'phpcr_odm_tutorial', - ); + ]; $dbConn = \Doctrine\DBAL\DriverManager::getConnection($params); - $parameters = array('jackalope.doctrine_dbal_connection' => $dbConn); + $parameters = ['jackalope.doctrine_dbal_connection' => $dbConn]; $repository = \Jackalope\RepositoryFactoryDoctrineDBAL::getRepository($parameters); $credentials = new \PHPCR\SimpleCredentials(null, null); @@ -283,12 +265,10 @@ A complete configuration could look like this:: $session = $repository->login($credentials, $workspace); /* prepare the doctrine configuration */ - use Doctrine\Common\Annotations\AnnotationReader; - use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver; + use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver; use Doctrine\ODM\PHPCR\DocumentManager; - $reader = new AnnotationReader(); - $driver = new AnnotationDriver($reader, array('/path/to/your/document/classes')); + $driver = new AttributeDriver(['/path/to/your/document/classes']); $config = new \Doctrine\ODM\PHPCR\Configuration(); $config->setMetadataDriverImpl($driver); @@ -349,20 +329,19 @@ classes. There are currently 4 implementations available: -- ``Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver`` +- ``Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver`` - ``Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver`` - ``Doctrine\ODM\PHPCR\Mapping\Driver\YamlDriver`` - ``Doctrine\ODM\PHPCR\Mapping\Driver\DriverChain`` -Throughout the most part of this manual the AnnotationDriver is +Throughout the most part of this manual the AttributeDriver is used in the examples. For information on the usage of the XmlDriver or YamlDriver please refer to the dedicated chapters ``XML Mapping`` and ``YAML Mapping``. -When you manually instantiate the annotation driver, you need to tell it the -path to the entities. All metadata drivers accept either a single directory as -a string or an array of directories. With this feature a single driver can -support multiple directories of Documents. +When you manually instantiate the attribute driver, you need to tell it the +path to the entities. All metadata drivers accept an array of directories. +With this feature a single driver can support multiple directories of Documents. Metadata Cache (***RECOMMENDED***) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -374,7 +353,7 @@ Metadata Cache (***RECOMMENDED***) Gets or sets the cache implementation to use for caching metadata information, that is, all the information you supply via -annotations, xml or yaml, so that they do not need to be parsed and +attributes, xml or yaml, so that they do not need to be parsed and loaded from scratch on every single request which is a waste of resources. The cache implementation must implement the ``Doctrine\Common\Cache\Cache`` interface. @@ -516,27 +495,6 @@ each time you change anything on your class or mapping: This command is only available since PHPCR-ODM 1.1. -Autoloading Proxies -~~~~~~~~~~~~~~~~~~~ - -When you deserialize proxy objects from the session or any other storage -it is necessary to have an autoloading mechanism in place for these classes. -For implementation reasons Proxy class names are not PSR-0 compliant. This -means that you have to register a special autoloader for these classes:: - - use Doctrine\ORM\Proxy\Autoloader; - - $proxyDir = '/path/to/proxies'; - $proxyNamespace = 'MyProxies'; - - Autoloader::register($proxyDir, $proxyNamespace); - -If you want to execute additional logic to intercept the proxy file not found -state you can pass a closure as the third argument. It will be called with -the arguments proxydir, namespace and className when the proxy file could not -be found. - - Multiple Metadata Sources ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/en/reference/introduction.rst b/docs/en/reference/introduction.rst index 77c453699..4fe8536a4 100644 --- a/docs/en/reference/introduction.rst +++ b/docs/en/reference/introduction.rst @@ -94,13 +94,13 @@ your project root directory:: throw new RuntimeException('Install dependencies with composer.'); } - $params = array( + $params = [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'dbname' => 'phpcr_odm_tutorial', - ); + ]; $workspace = 'default'; $user = 'admin'; @@ -109,7 +109,7 @@ your project root directory:: /* --- transport implementation specific code begin --- */ // for more options, see https://github.com/jackalope/jackalope-doctrine-dbal#bootstrapping $dbConn = \Doctrine\DBAL\DriverManager::getConnection($params); - $parameters = array('jackalope.doctrine_dbal_connection' => $dbConn); + $parameters = ['jackalope.doctrine_dbal_connection' => $dbConn]; $repository = \Jackalope\RepositoryFactoryDoctrineDBAL::getRepository($parameters); $credentials = new \PHPCR\SimpleCredentials(null, null); /* --- transport implementation specific code ends --- */ @@ -117,20 +117,15 @@ your project root directory:: $session = $repository->login($credentials, $workspace); /* prepare the doctrine configuration */ - use Doctrine\Common\Annotations\AnnotationRegistry; - use Doctrine\Common\Annotations\AnnotationReader; - use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver; + use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver; use Doctrine\ODM\PHPCR\Configuration; use Doctrine\ODM\PHPCR\DocumentManager; - AnnotationRegistry::registerLoader(array($autoload, 'loadClass')); - - $reader = new AnnotationReader(); - $driver = new AnnotationDriver($reader, array( + $driver = new AttributeDriver([ // this is a list of all folders containing document classes 'vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', 'src/Demo', - )); + ]); $config = new Configuration(); $config->setMetadataDriverImpl($driver); @@ -156,46 +151,32 @@ Building the model ------------------ Models are plain PHP classes. Note that you have several ways to define the mapping. -For easy readability, we use the annotation mapping with PHPCR namespace in this tutorial:: +For easy readability, we use the attribute mapping with PHPCR namespace in this tutorial:: // src/Demo/Document.php namespace Demo; - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class MyDocument { - /** - * @PHPCR\Id - */ + #[PHPCR\Id] private $id; - /** - * @PHPCR\ParentDocument - */ + #[PHPCR\ParentDocument] private $parent; - /** - * @PHPCR\Nodename - */ + #[PHPCR\Nodename] private $name; - /** - * @PHPCR\Children - */ + #[PHPCR\Children] private $children; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: 'string')] private $title; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: 'string')] private $content; public function getId() @@ -234,7 +215,7 @@ For easy readability, we use the annotation mapping with PHPCR namespace in this } If you are familiar with Doctrine ORM, this code should look pretty familiar to you. The -only important difference are the hierarchy related annotations ParentDocument, Name and Children. +only important difference are the hierarchy related mappings ``ParentDocument``, ``Name`` and ``Children``. In PHPCR, data is stored in trees. Every document has a parent and its own name. The id is built from this structure, resulting in path strings. The recommended way to generate the id is by assigning a name and a parent to the document. See the section on identifier @@ -315,7 +296,7 @@ This script will simply echo the data to the console:: require_once '../bootstrap.php'; - $doc = $documentManager->find(null, "/doc"); + $doc = $documentManager->find(null, '/doc'); echo 'Found '.$doc->getId() ."\n"; echo 'Title: '.$doc->getTitle()."\n"; @@ -329,15 +310,15 @@ Tree traversal PHPCR is a tree based store. Every document must have a parent, and can have children. We already used this when creating the document. -The ``@ParentDocument`` maps the parent of a document and is used -to determine the position in the tree, together with ``@Nodename``. +The ``ParentDocument`` maps the parent of a document and is used +to determine the position in the tree, together with ``Nodename``. -As the children of our sample document are mapped with ``@Children``, +As the children of our sample document are mapped with ``Children``, we can traverse them:: use Demo\MyDocument; - $doc = $documentManager->find(null, "/doc"); + $doc = $documentManager->find(null, '/doc'); foreach($doc->getChildren() as $child) { if ($child instanceof MyDocument) { @@ -371,12 +352,12 @@ Add references PHPCR-ODM supports arbitrary links between documents. The referring document does not need to know what class it links to. Use -``ReferenceOne`` resp. ``@ReferenceMany`` to map the link +``ReferenceOne`` resp. ``ReferenceMany`` to map the link to a document or a collection of links to documents. -You can also map the inverse relation. ``@Referrers`` needs the +You can also map the inverse relation. ``Referrers`` needs the referring class but can be used to add referencing documents. -``@MixedReferrers`` maps all documents referencing this document, +``MixedReferrers`` maps all documents referencing this document, but is readonly. Lets look at an example of document ``A`` referencing ``B``:: @@ -385,29 +366,21 @@ Lets look at an example of document ``A`` referencing ``B``:: namespace Demo; - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class A { - /** - * @PHPCR\ReferenceOne - */ + #[PHPCR\ReferenceOne] private $ref; ... } - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class B { - /** - * @PHPCR\Referrers(referringDocument="Demo\A", referencedBy="ref") - */ + #[PHPCR\Referrers(referringDocument: A::class, referencedBy: 'ref')] private $referrers; } diff --git a/docs/en/reference/multilang.rst b/docs/en/reference/multilang.rst index 754bdad5c..a2847eae4 100644 --- a/docs/en/reference/multilang.rst +++ b/docs/en/reference/multilang.rst @@ -32,9 +32,14 @@ soon as at least one field in that locale exists. Mapping ------- -To make a document translated, you need to define the ``translator`` attribute on the document -configuration, and you need to map the ``locale`` field. Then you can use the ``translated`` -attribute on all fields that should be different depending on the locale. +To make a document translated, you need to define the ``translator`` parameter +on the document mapping, and you need to map the ``locale`` field. Then you +can use the ``translated`` parameter on all fields that should be different +depending on the locale. + +PHPCR-ODM does not restrict what fields may be translatable - if you need e.g. +a date to be different depending on the language, you can simply specify the +``translated: true`` parameter. .. configuration-block:: @@ -42,33 +47,29 @@ attribute on all fields that should be different depending on the locale. use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; - /** - * @PHPCR\Document(translator="attribute") + #[PHPCR\Document(translator: 'attribute')] */ class MyPersistentClass { - /** - * The language this document currently is in - * @Locale - */ + #[PHPCR\Locale] private $locale; /** * Untranslated property - * @PHPCR\Field(type="date") */ + #[PHPCR\Field(type: 'date')] private $publishDate; /** * Translated property - * @PHPCR\Field(type="string", translated=true) */ + #[PHPCR\Field(type: 'string', translated: true)] private $topic; /** * Language specific image - * @PHPCR\Field(type="binary", translated=true) */ + #[PHPCR\Field(type: 'binary', translated: true)] private $image; } @@ -215,11 +216,11 @@ any translatable documents:: use Doctrine\ODM\PHPCR\DocumentManager; - $localePrefs = array( - 'en' => array('de', 'fr'), - 'fr' => array('de', 'en'), - 'it' => array('de', 'en'), - ); + $localePrefs = [ + 'en' => ['de', 'fr'], + 'fr' => ['de', 'en'], + 'it' => ['de', 'en'], + ]; $dm = new DocumentManager($session, $config); $dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en')); @@ -239,10 +240,10 @@ Full Example // bootstrap the DocumentManager as required (see above) - $localePrefs = array( - 'en' => array('fr'), - 'fr' => array('en'), - ); + $localePrefs = [ + 'en' => ['fr'], + 'fr' => ['en'], + ]; $dm = new DocumentManager($session, $config); $dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en')); diff --git a/docs/en/reference/phpcr-access.rst b/docs/en/reference/phpcr-access.rst index 9ec850df2..e1c16e7a5 100644 --- a/docs/en/reference/phpcr-access.rst +++ b/docs/en/reference/phpcr-access.rst @@ -31,16 +31,12 @@ This field is populated on find, and as soon as you register the document with t .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class MyPersistentClass { - /** - * @PHPCR\Node - */ + #[PHPCR\Node] private $node; } diff --git a/docs/en/reference/query-builder-reference.rst b/docs/en/reference/query-builder-reference.rst index aeb3faf88..fa5dfa7b5 100644 --- a/docs/en/reference/query-builder-reference.rst +++ b/docs/en/reference/query-builder-reference.rst @@ -818,7 +818,7 @@ This is the node which is returned when a query builder is asked for:: $dm = // get document manager $qb = $dm->createQueryBuilder(); - $qb->fromDocument('Blog\Post', 'p'); + $qb->fromDocument(BlogPost::class, 'p'); $qb->where()->eq()->field('p.title')->literal('My Post'); $docs = $qb->getQuery()->execute(); @@ -948,7 +948,7 @@ source as the left operand:: Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the ``uniqueNodeType`` property -must be set to ``true`` for the document (see :ref:`<_annref_document>`). Otherwise, the join +must be set to ``true`` for the document (see :ref:`<_attref_document>`). Otherwise, the join will behave as an inner join. **Adds**: :ref:`select ` (Select) @@ -973,7 +973,7 @@ source as the left operand:: Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the ``uniqueNodeType`` property -must be set to ``true`` for the document (see :ref:`<_annref_document>`). Otherwise, the join +must be set to ``true`` for the document (see :ref:`<_attref_document>`). Otherwise, the join will behave as an inner join. **Adds**: :ref:`select ` (Select) @@ -998,7 +998,7 @@ source as the left operand:: Note that for outer joins to work correctly, documents being joined to must be mapped with a node type that is unique to the repository workspace, and the ``uniqueNodeType`` property -must be set to ``true`` for the document (see :ref:`<_annref_document>`). Otherwise, the join +must be set to ``true`` for the document (see :ref:`<_attref_document>`). Otherwise, the join will behave as an inner join. **Adds**: :ref:`select ` (Select) @@ -1320,5 +1320,3 @@ Factory node for appending additional "wheres" with an OR **Child Cardinality**: * **1..1** :ref:`constraint ` - - diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 389870927..8834e162c 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -10,7 +10,7 @@ An example query:: $qb = $documentManager->createQueryBuilder(); - $qb->from()->document('Blog\User', 'u'); + $qb->from()->document(User::class, 'u'); $qb->where()->eq()->field('u.name')->literal('dtl'); $query = $qb->getQuery(); @@ -35,7 +35,7 @@ Alternatively the above query can be written more fluently by the using $qb = $documentManager->createQueryBuilder(); $qb->from() - ->document('Blog\User') + ->document(User::class) ->end() ->where() ->eq() @@ -163,7 +163,7 @@ Aliases and fields The term "alias" refers to the string that is assigned to a document source, either a ``SourceFrom`` or a ``SourceJoin``:: - $qb->from('Blog\Post', 'post'); + $qb->from(Post::class, 'post'); In the example above, "post" is the alias. The alias is subsequently used whenever the source is referenced. The following example show some instances @@ -201,7 +201,7 @@ You can also instantiate a ``QueryBuilder`` from a ``DocumentRepsitory`` instance, doing so will automatically select only those records which are associated with the ``DocumentRepository``:: - $postsRepository = $dm->getRepository('Blog\Post'); + $postsRepository = $dm->getRepository(Post::class); $qb = $postsRepository->createQueryBuilder('p'); $posts = $qb->getQuery()->execute(); @@ -254,8 +254,7 @@ From Single Source .. code-block:: php - // select documents of class Foo\Bar. - $qb->from()->document('Blog\Post', 'p'); + $qb->from()->document(Post::class, 'p'); The above example will setup the query builder to select documents only of class ``Blog\Post`` using the *alias name* "p". The alias name is the alias used @@ -274,8 +273,8 @@ The following will retrieve a collection of ``Blog\Post`` documents for active u // select documents from a join $qb->from('p')->joinInner() - ->left()->document('Blog\Post', 'p')->end() - ->right()->document('Blog\User', 'u')->end() + ->left()->document(Post::class, 'p')->end() + ->right()->document(User::class', 'u')->end() ->condition()->equi('p.username', 'u.username'); $qb->where() @@ -297,9 +296,12 @@ Joining with an Association The following is another example which joins on an *association*. The ``CmsUser`` class is associated with a single address:: - $qb->fromDocument('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + use Doctrine\Tests\Models\CMS\CmsAddress; + use Doctrine\Tests\Models\CMS\CmsUser; + + $qb->fromDocument(CmsUser::class, 'u'); ->addJoinInner() - ->right()->document('Doctrine\Tests\Models\CMS\CmsAddress', 'a')->end() + ->right()->document(CmsAddress::class, 'a')->end() ->condition()->equi('u.address', 'a.uuid'); ->where()->eq()->field('a.city')->literal('Lyon'); $users = $qb->getQuery()->execute(); @@ -319,7 +321,7 @@ node, this is currently only useful when :ref:`hydrating to PHPCR nodes `. The default (object) hydration will *always* hydrate all fields regardless of what you specify:: - $qb->from('Demo\User', 'u'); + $qb->from(User::class, 'u'); $qb->select() ->field('u.firstname') ->field('u.lastname'); @@ -355,7 +357,7 @@ Specifying selection criteria You can specify selection criteria using the ``where`` factory node:: // setup our document source with alias "u" - $qb->from('Blog\User', 'u'); + $qb->from(User::class, 'u'); // where name is "daniel" $qb->where() @@ -434,7 +436,7 @@ Querying translated documents If your documents contain :doc:`translated fields `, the query builder automatically handles them both for ``where`` and ``orderBy`` -when using the annotation or child translation strategy. +when using the attribute or child translation strategy. It will use the "current" locale according to the LocaleChooser. If you want to query in a different locale, you can also specify the locale explicitly:: @@ -443,7 +445,7 @@ to query in a different locale, you can also specify the locale explicitly:: $qb ->setLocale('fr') ->from() - ->document('Demo\Document', 'd') + ->document(Document::class, 'd') ->end() ->where()->fieldIsset('d.title')->end() ->orderBy() diff --git a/docs/en/reference/query.rst b/docs/en/reference/query.rst index ba35b1f11..a73091a89 100644 --- a/docs/en/reference/query.rst +++ b/docs/en/reference/query.rst @@ -84,7 +84,7 @@ to specify an array of parameters as the first argument:: // is equivalenet to $query = // get new query - $docs = $query->execute(array(), Query::HYDRATE_DOCUMENT); + $docs = $query->execute([], Query::HYDRATE_DOCUMENT); .. note:: @@ -131,4 +131,3 @@ should be retrieved:: $query->setOffset(50); $query->setMaxResults(150); $res = $query->getResult(); // will return a maximum of 100 results from result index 50 - diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 26ffb7053..b014e5b93 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -70,62 +70,6 @@ This command needs to be run once on a new repository to prepare it for use with Failing to do so will throw you errors when you try to store a document that uses a node type different from nt:unstructured, like a file or folder. -.. - TODO: would be nice to provide this as well - - Convert Mapping Information - --------------------------- - - Convert mapping information between supported formats. - - This is an **execute one-time** command. It should not be necessary for - you to call this method multiple times, especially when using the ``--from-database`` - flag. - - Converting an existing database schema into mapping files only solves about 70-80% - of the necessary mapping information. Additionally the detection from an existing - database cannot detect inverse associations, inheritance types, - entities with foreign keys as primary keys and many of the - semantical operations on associations such as cascade. - - .. note:: - - There is no need to convert YAML or XML mapping files to annotations - every time you make changes. All mapping drivers are first class citizens - in Doctrine 2 and can be used as runtime mapping for the ORM. See the - docs on XML and YAML Mapping for an example how to register this metadata - drivers as primary mapping source. - - To convert some mapping information between the various supported - formats you can use the ``ClassMetadataExporter`` to get exporter - instances for the different formats:: - - $cme = new \Doctrine\ORM\Tools\Export\ClassMetadataExporter(); - - Once you have a instance you can use it to get an exporter. For - example, the yml exporter:: - - $exporter = $cme->getExporter('yml', '/path/to/export/yml'); - - Now you can export some ``ClassMetadata`` instances:: - - $classes = array( - $em->getClassMetadata('Entities\User'), - $em->getClassMetadata('Entities\Profile') - ); - $exporter->setMetadata($classes); - $exporter->export(); - - This functionality is also available from the command line to - convert your loaded mapping information to another format. The - ``orm:convert-mapping`` command accepts two arguments, the type to - convert to and the path to generate it: - - .. code-block:: bash - - $ php doctrine orm:convert-mapping xml /path/to/mapping-path-converted-to-xml - - Adding your own commands ------------------------ diff --git a/docs/en/reference/versioning.rst b/docs/en/reference/versioning.rst index 4063fc753..37e28b717 100644 --- a/docs/en/reference/versioning.rst +++ b/docs/en/reference/versioning.rst @@ -74,21 +74,15 @@ Due to implementation limitations, the Locale field is `required` on all transla .. code-block:: php - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document(versionable="full") - */ + #[PHPCR\Document(versionable: 'full')] class MyPersistentClass { - /** - * @PHPCR\VersionName - */ + #[PHPCR\VersionName] private $versionName; - /** - * @PHPCR\VersionCreated - */ + #[PHPCR\VersionCreated] private $versionCreated; } @@ -117,8 +111,8 @@ Be aware that these two are different things: You get this document with the findVersionByName method. It is read-only. The document class you use needs not be the same. You can define a *version* document that is the same as your base document, but all fields are read - only and you use the VersionName and VersionCreated annotations on it. It - also does not need the versionable document attribute. (You do not create + only and you use the VersionName and VersionCreated mappings on it. The document + mapping also does not need the versionable document parameter. (You do not create versions of old versions, you only create versions of the main document.) You can track some information about old versions in PHPCR-ODM. Both are only diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 7e3dccbc2..f7191275e 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -99,31 +99,21 @@ want. Take the following example of a single ``Article`` document fetched from newly opened DocumentManager:: - use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; + use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; - /** - * @PHPCR\Document - */ + #[PHPCR\Document] class Article { - /** - * @PHPCR\Id - */ + #[PHPCR\Id] private $id; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: 'string')] private $headline; - /** - * @PHPCR\ReferenceOne - */ + #[PHPCR\ReferenceOne] private $author; - /** - * @PHPCR\Referrers(referrerDocument="Comment", referencedBy="article") - */ + #[PHPCR\Referrers(referrerDocument: Comment::class, referencedBy: 'article')] private $comments; public function __construct { @@ -254,7 +244,7 @@ as follows: * If X is a pre-existing managed document, it is ignored by the persist operation. However, the persist operation is cascaded to documents referenced by X if the relationships from X to these - other documents are mapped with ``cascade=PERSIST`` or ``cascade=ALL`` (see + other documents are mapped with ``cascade: 'PERSIST'`` or ``cascade: 'ALL'`` (see "Transitive Persistence"); * If X is a removed document, it becomes managed; * If X is a detached document, an exception will be thrown on @@ -292,11 +282,11 @@ as follows: * If X is a new document, it is ignored by the remove operation. However, the remove operation is cascaded to documents referenced by X, if the relationship from X to these other documents is mapped - with ``cascade=REMOVE`` or ``cascade=ALL`` (see "Transitive Persistence"); + with ``cascade: 'REMOVE'`` or ``cascade: 'ALL'`` (see "Transitive Persistence"); * If X is a managed document, the remove operation causes it to become removed. The remove operation is cascaded to documents referenced by X, if the relationships from X to these other - documents is mapped with ``cascade=REMOVE`` or ``cascade=ALL`` (see + documents is mapped with ``cascade: 'REMOVE'`` or ``cascade: 'ALL'`` (see "Transitive Persistence"); * If X is a detached document, an ``InvalidArgumentException`` will be thrown; @@ -313,7 +303,7 @@ the document explicitly removed. By default, references and referring documents are not deleted. You can enable this by configuring cascading removal on the association mapping. If an association -is marked as ``CASCADE=REMOVE``, PHPCR-ODM will follow this association. If +is marked as ``cascade: 'REMOVE'``, PHPCR-ODM will follow this association. If its a Single association it will pass this document to ``DocumentManager::remove()``. If the association is a collection, Doctrine will loop over all its elements and pass them to``DocumentManager::remove()``. @@ -349,14 +339,14 @@ as follows: * If X is a managed document, the detach operation causes it to become detached. The detach operation is cascaded to documents referenced by X, if the relationships from X to these other - documents is mapped with ``cascade=DETACH`` or ``cascade=ALL`` (see + documents is mapped with ``cascade: 'DETACH'`` or ``cascade: 'ALL'`` (see "Transitive Persistence"). Documents which previously referenced X will continue to reference X; * If X is a new or detached document, it is ignored by the detach operation; * If X is a removed document, the detach operation is cascaded to documents referenced by X, if the relationships from X to these - other documents is mapped with ``cascade=DETACH`` or ``cascade=ALL`` (see + other documents is mapped with ``cascade: 'DETACH'`` or ``cascade: 'ALL'`` (see "Transitive Persistence"). Documents which previously referenced X will continue to reference X. @@ -409,7 +399,7 @@ as follows: For all such Y referenced by X, X' is set to reference Y'. (Note that if X is managed then X is the same object as X'.); * If X is a document merged to X', with a reference to another - document Y, where ``cascade=MERGE`` or ``cascade=ALL`` is not specified, then + document Y, where ``cascade: 'MERGE'`` or ``cascade: 'ALL'`` is not specified, then navigation of the same association from X' yields a reference to a managed object Y' with the same persistent identity as Y. @@ -619,7 +609,7 @@ identifier (PHPCR path) using the example:: /** @var $em DocumentManager */ - $user = $em->find('MyProject\Domain\User', $id); + $user = $em->find(User::class, $id); The return value is either the found document instance or null if no instance could be found with the given identifier. @@ -644,25 +634,25 @@ methods on a repository as follows:: /** @var $dm DocumentManager */ // All users that are 20 years old - $users = $dm->getRepository('MyProject\Domain\User')->findBy(array('age' => 20)); + $users = $dm->getRepository(User::Class)->findBy(['age' => 20]); // All users that are 20 years old and have a surname of 'Miller' - $users = $dm->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller')); + $users = $dm->getRepository(User::Class)->findBy(['age' => 20, 'surname' => 'Miller']); // A single user by its nickname - $user = $dm->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); + $user = $dm->getRepository(User::Class)->findOneBy(['nickname' => 'romanb']); .. warning:: Note that due to the nature of PHPCR, the primary identifier is no field. - You can thus not use ``findBy(array('id' => '/my/path'))`` but should + You can thus not use ``findBy(['id' => '/my/path'])`` but should pass the ID into the ``find`` method. There is also findMany if you need to fetch several documents. You can also query by references through the repository:: - $number = $dm->find('MyProject\Domain\Phonenumber', '/path/to/phone/number'); - $user = $dm->getRepository('MyProject\Domain\User')->findOneBy(array('phone' => $number->getUuid())); + $number = $dm->find(PhoneNumber::class, '/path/to/phone/number'); + $user = $dm->getRepository(User::Class)->findOneBy(['phone' => $number->getUuid()]); Be careful that this only works by passing the uuid of the associated document, not yet by passing the associated document itself. @@ -671,8 +661,8 @@ The ``DocumentRepository::findBy()`` method additionally accepts orderings, limit and offset as second to fourth parameters:: $tenUsers = $dm - ->getRepository('MyProject\Domain\User') - ->findBy(array('age' => 20), array('name' => 'ASC'), 10, 0); + ->getRepository(User::Class) + ->findBy(['age' => 20], ['name' => 'ASC'], 10, 0); .. note:: @@ -685,10 +675,10 @@ calls through its use of ``__call``. Thus, the following two examples are equivalent:: // A single user by its nickname - $user = $dm->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); + $user = $dm->getRepository(User::Class)->findOneBy(['nickname' => 'romanb']); // A single user by its nickname (__call magic) - $user = $dm->getRepository('MyProject\Domain\User')->findOneByNickname('romanb'); + $user = $dm->getRepository(User::Class)->findOneByNickname('romanb'); By Lazy Loading @@ -738,9 +728,7 @@ in a central location:: use Doctrine\ODM\PHPCR\DocumentRepository; - /** - * @PHPCR\Document(repositoryClass="MyDomain\Model\UserRepository") - */ + #[PHPCR\Document(repositoryClass: UserRepository::class)] class User { @@ -760,4 +748,4 @@ You can access your repository now by calling:: /** @var $dm DocumentManager */ - $admins = $dm->getRepository('MyDomain\Model\User')->getAllAdminUsers(); + $admins = $dm->getRepository(User::class)->getAllAdminUsers(); diff --git a/docs/en/reference/xml-mapping.rst b/docs/en/reference/xml-mapping.rst index cb161321a..7c4b4e774 100644 --- a/docs/en/reference/xml-mapping.rst +++ b/docs/en/reference/xml-mapping.rst @@ -2,9 +2,9 @@ XML Mapping =========== This chapter gives a brief overview of the XML mapping by example. In general, -the attributes correspond to their annotation counterparts with the difference that -the attribute names are slugified as opposed to being camelCase -(``referring-document`` instead of ``referringDocument``). See :doc:`annotations-mapping`. +the attributes correspond to their attribute counterparts with the difference that +the parameter names are slugified as opposed to being camelCase +(``referring-document`` instead of ``referringDocument``). See :doc:`attributes-mapping`. The following example implements all of the possible XML mapping elements: diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Children.php b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Children.php index 050abd0f1..3462a17b9 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Children.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Children.php @@ -28,7 +28,7 @@ class Children { /** - * @var array + * @var array|null */ public $filter; diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Reference.php b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Reference.php index f34b40946..4e110b09a 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Reference.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/Reference.php @@ -25,16 +25,16 @@ class Reference { /** - * The PHPCR property name to use - * * @var string */ - public $property; + public $targetDocument; /** + * The PHPCR property name to use + * * @var string */ - public $targetDocument; + public $property; /** * @var string diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Child.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Child.php index c6f2e877e..6f01ca7e8 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Child.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Child.php @@ -4,8 +4,16 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Child as BaseChild; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Child extends BaseChild +final class Child extends BaseChild implements MappingAttribute { + public function __construct( + string $nodeName = null, + array $cascade = [], + ) { + $this->nodeName = $nodeName; + $this->cascade = $cascade; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Children.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Children.php index 5800b4502..8ff32c14e 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Children.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Children.php @@ -2,8 +2,22 @@ namespace Doctrine\ODM\PHPCR\Mapping\Attributes; +use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Children as BaseChildren; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; -final class Children extends BaseChildren +#[Attribute(Attribute::TARGET_PROPERTY)] +final class Children extends BaseChildren implements MappingAttribute { + public function __construct( + array|string $filter = null, + int $fetchDepth = -1, + bool $ignoreUntranslated = true, + array $cascade = [], + ) { + $this->filter = $filter ? (array) $filter : null; + $this->fetchDepth = $fetchDepth; + $this->ignoreUntranslated = $ignoreUntranslated; + $this->cascade = $cascade; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Depth.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Depth.php index 9d7a5f738..3e09f984e 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Depth.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Depth.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Depth as BaseDepth; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Depth extends BaseDepth +final class Depth extends BaseDepth implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Document.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Document.php index fbb261f2d..c900a04f7 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Document.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Document.php @@ -4,8 +4,32 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Document as BaseDocument; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_CLASS)] -final class Document extends BaseDocument +class Document extends BaseDocument implements MappingAttribute { + public function __construct( + string $nodeType = null, + string $repositoryClass = null, + string $translator = null, + array $mixins = null, + bool $inheritMixins = true, + string $versionable = null, + bool $referenceable = false, + bool $uniqueNodeType = false, + array $childClasses = [], + bool $isLeaf = false, + ) { + $this->nodeType = $nodeType; + $this->repositoryClass = $repositoryClass; + $this->translator = $translator; + $this->mixins = $mixins; + $this->inheritMixins = $inheritMixins; + $this->versionable = $versionable; + $this->referenceable = $referenceable; + $this->uniqueNodeType = $uniqueNodeType; + $this->childClasses = $childClasses; + $this->isLeaf = $isLeaf; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Field.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Field.php index 9f097ee81..a450b8158 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Field.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Field.php @@ -4,8 +4,25 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Field as BaseField; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Field extends BaseField +class Field extends BaseField implements MappingAttribute { + public function __construct( + string $property = null, + string $type = 'undefined', + bool $multivalue = false, + string $assoc = null, + bool $nullable = false, + bool $translated = false, + ) + { + $this->property = $property; + $this->type = $type; + $this->multivalue = $multivalue; + $this->assoc = $assoc; + $this->nullable = $nullable; + $this->translated = $translated; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Id.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Id.php index 95d6cc044..c412e0e94 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Id.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Id.php @@ -4,8 +4,18 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Id as BaseId; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Id extends BaseId +final class Id extends BaseId implements MappingAttribute { + public function __construct( + bool $id = true, + string $type = 'string', + string $strategy = null, + ) { + $this->id = $id; + $this->type = $type; + $this->strategy = $strategy; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Locale.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Locale.php index 2452d5c1e..36e950959 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Locale.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Locale.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Locale as BaseLocale; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Locale extends BaseLocale +final class Locale extends BaseLocale implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MappedSuperclass.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MappedSuperclass.php index ad5635422..f70deea50 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MappedSuperclass.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MappedSuperclass.php @@ -3,9 +3,8 @@ namespace Doctrine\ODM\PHPCR\Mapping\Attributes; use Attribute; -use Doctrine\ODM\PHPCR\Mapping\Annotations\MappedSuperclass as BaseMappedSuperclass; #[Attribute(Attribute::TARGET_CLASS)] -final class MappedSuperclass extends BaseMappedSuperclass +final class MappedSuperclass extends Document { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MixedReferrers.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MixedReferrers.php index 6800c376d..62c43e0e6 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MixedReferrers.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/MixedReferrers.php @@ -4,8 +4,13 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\MixedReferrers as BaseMixedReferrers; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class MixedReferrers extends BaseMixedReferrers +final class MixedReferrers extends BaseMixedReferrers implements MappingAttribute { + public function __construct(string $referenceType = null) + { + $this->referenceType = $referenceType; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Node.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Node.php index 4ac12f01a..55a86366c 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Node.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Node.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Node as BaseNode; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Node extends BaseNode +final class Node extends BaseNode implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Nodename.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Nodename.php index 0f5240af1..b3d0845e6 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Nodename.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Nodename.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Nodename as BaseNodename; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Nodename extends BaseNodename +final class Nodename extends BaseNodename implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ParentDocument.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ParentDocument.php index caeb8d0ce..8b60a5e68 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ParentDocument.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ParentDocument.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\ParentDocument as BaseParentDocument; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class ParentDocument extends BaseParentDocument +final class ParentDocument extends BaseParentDocument implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostLoad.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostLoad.php index c29dbee6b..311818f34 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostLoad.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostLoad.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PostLoad as BasePostLoad; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PostLoad extends BasePostLoad +final class PostLoad extends BasePostLoad implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostPersist.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostPersist.php index a32a966d1..aad5e81bc 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostPersist.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostPersist.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PostPersist as BasePostPersist; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PostPersist extends BasePostPersist +final class PostPersist extends BasePostPersist implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostRemove.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostRemove.php index cb5561aa1..d4314a3c1 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostRemove.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostRemove.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PostRemove as BasePostRemove; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PostRemove extends BasePostRemove +final class PostRemove extends BasePostRemove implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostUpdate.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostUpdate.php index 2fe376b37..c99e4feef 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostUpdate.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PostUpdate.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PostUpdate as BasePostUpdate; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PostUpdate extends BasePostUpdate +final class PostUpdate extends BasePostUpdate implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PrePersist.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PrePersist.php index 15695d47b..64a31e2c5 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PrePersist.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PrePersist.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PrePersist as BasePrePersist; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PrePersist extends BasePrePersist +final class PrePersist extends BasePrePersist implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreRemove.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreRemove.php index dd4611ee9..596543561 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreRemove.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreRemove.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PreRemove as BasePreRemove; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PreRemove extends BasePreRemove +final class PreRemove extends BasePreRemove implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreUpdate.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreUpdate.php index 0f94321fa..0bacc4678 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreUpdate.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/PreUpdate.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\PreUpdate as BasePreUpdate; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_METHOD)] -final class PreUpdate extends BasePreUpdate +final class PreUpdate extends BasePreUpdate implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Reference.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Reference.php new file mode 100644 index 000000000..64fd52a56 --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Reference.php @@ -0,0 +1,24 @@ +property = $property; + $this->targetDocument = $targetDocument; + $this->strategy = $strategy; + $this->cascade = $cascade; + } +} diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceMany.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceMany.php index 5b3dcd6e6..b10c87202 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceMany.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceMany.php @@ -3,9 +3,8 @@ namespace Doctrine\ODM\PHPCR\Mapping\Attributes; use Attribute; -use Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceMany as BaseReferenceMany; #[Attribute(Attribute::TARGET_PROPERTY)] -final class ReferenceMany extends BaseReferenceMany +final class ReferenceMany extends Reference { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceOne.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceOne.php index ec62ead4a..1ee210760 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceOne.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/ReferenceOne.php @@ -3,9 +3,8 @@ namespace Doctrine\ODM\PHPCR\Mapping\Attributes; use Attribute; -use Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceOne as BaseReferenceOne; #[Attribute(Attribute::TARGET_PROPERTY)] -final class ReferenceOne extends BaseReferenceOne +final class ReferenceOne extends Reference { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Referrers.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Referrers.php index e9f3909c9..dd7a0c1ea 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Referrers.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Referrers.php @@ -4,8 +4,21 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\Referrers as BaseReferrers; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Referrers extends BaseReferrers +final class Referrers extends BaseReferrers implements MappingAttribute { + /** + * @param string[] $cascade + */ + public function __construct( + string $referencedBy, + string $referringDocument, + array $cascade = [] + ) { + $this->referencedBy = $referencedBy; + $this->referringDocument = $referringDocument; + $this->cascade = $cascade; + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Uuid.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Uuid.php index 6ed6f5cd3..36e0d7abd 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Uuid.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Uuid.php @@ -3,9 +3,18 @@ namespace Doctrine\ODM\PHPCR\Mapping\Attributes; use Attribute; -use Doctrine\ODM\PHPCR\Mapping\Annotations\Uuid as BaseUuid; #[Attribute(Attribute::TARGET_PROPERTY)] -final class Uuid extends BaseUuid +final class Uuid extends Field { + public function __construct( + string $property = 'jcr:uuid', + string $type = 'string', + bool $multivalue = false, + string $assoc = null, + bool $nullable = false, + bool $translated = false, + ) { + parent::__construct($property, $type, $multivalue, $assoc, $nullable, $translated); + } } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionCreated.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionCreated.php index 8d3e6ba12..7e46e2dbb 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionCreated.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionCreated.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\VersionCreated as BaseVersionCreated; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class VersionCreated extends BaseVersionCreated +final class VersionCreated extends BaseVersionCreated implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionName.php b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionName.php index d997f2165..73e1000a2 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionName.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Attributes/VersionName.php @@ -4,8 +4,9 @@ use Attribute; use Doctrine\ODM\PHPCR\Mapping\Annotations\VersionName as BaseVersionName; +use Doctrine\ODM\PHPCR\Mapping\MappingAttribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class VersionName extends BaseVersionName +final class VersionName extends BaseVersionName implements MappingAttribute { } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php index 7db1c37c6..c82488426 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php @@ -614,7 +614,7 @@ public function setIdentifier($identifier) /** * Registers a custom repository class for the document class. * - * @param string $repositoryClassName the class name of the custom repository + * @param class-string $repositoryClassName the class name of the custom repository */ public function setCustomRepositoryClassName($repositoryClassName) { diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php index 374d5ff9c..0d482accc 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php @@ -25,6 +25,9 @@ use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\ODM\PHPCR\Mapping\Annotations\Document; +use Doctrine\ODM\PHPCR\Mapping\Annotations\MappedSuperclass; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata as PhpcrClassMetadata; /** * The AnnotationDriver reads the mapping metadata from docblock annotations. @@ -47,16 +50,17 @@ class AnnotationDriver extends AbstractAnnotationDriver implements MappingDriver * Document annotation classes, ordered by precedence. */ protected $entityAnnotationClasses = [ - 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document' => 0, - 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass' => 1, + Document::class => 0, + MappedSuperclass::class => 1, ]; /** * {@inheritdoc} + * + * @param PhpcrClassMetadata $metadata */ public function loadMetadataForClass($className, ClassMetadata $metadata) { - /** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */ $reflClass = $metadata->getReflectionClass(); $documentAnnots = []; @@ -184,7 +188,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } foreach ($reflClass->getMethods() as $method) { - if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) { + if ($method->isPublic() && $method->getDeclaringClass()->getName() === $metadata->name) { foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof ODM\PrePersist) { $metadata->addLifecycleCallback($method->getName(), Event::prePersist); diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php new file mode 100644 index 000000000..587e925fc --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php @@ -0,0 +1,248 @@ +. + */ + +namespace Doctrine\ODM\PHPCR\Mapping\Driver; + +use Doctrine\ODM\PHPCR\Event; +use Doctrine\ODM\PHPCR\Mapping\Attributes as ODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes\Document; +use Doctrine\ODM\PHPCR\Mapping\Attributes\MappedSuperclass; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use Doctrine\ODM\PHPCR\Mapping\MappingException; +use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata; +use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; +use ReflectionClass; + +/** + * Read mapping metadata from PHP attributes. + * + * @license http://www.opensource.org/licenses/MIT-license.php MIT license + * + * @see www.doctrine-project.org + * @since 1.8 + * + * @author David Buchmann + */ +class AttributeDriver implements MappingDriver +{ + use ColocatedMappingDriver; + + /** + * Document attribute classes, ordered by precedence. + */ + private const DOCUMENT_ATTRIBUTE_CLASSES = [ + Document::class => 0, + MappedSuperclass::class => 1, + ]; + + private AttributeReader $reader; + + /** + * @param array $paths + */ + public function __construct(array $paths) + { + $this->reader = new AttributeReader(); + $this->addPaths($paths); + } + + public function isTransient($className) + { + $classAttributes = $this->reader->getClassAttributes(new ReflectionClass($className)); + + foreach ($classAttributes as $a) { + if (array_key_exists($a::class, self::DOCUMENT_ATTRIBUTE_CLASSES)) { + return false; + } + } + + return true; + } + + public function loadMetadataForClass($className, PersistenceClassMetadata $metadata): void + { + \assert($metadata instanceof ClassMetadata); + $reflectionClass = $metadata->getReflectionClass(); + $classAttributes = $this->reader->getClassAttributes($reflectionClass); + + // Evaluate document attribute + if (array_key_exists(ODM\Document::class, $classAttributes)) { + $documentAttribute = $classAttributes[ODM\Document::class]; + \assert($documentAttribute instanceof ODM\Document); + } elseif (isset($classAttributes[ODM\MappedSuperclass::class])) { + $documentAttribute = $classAttributes[ODM\MappedSuperclass::class]; + \assert($documentAttribute instanceof ODM\MappedSuperclass); + $metadata->isMappedSuperclass = true; + } else { + throw MappingException::classIsNotAValidDocument($className); + } + + if (null !== $documentAttribute->referenceable) { + $metadata->setReferenceable($documentAttribute->referenceable); + } + + if (null !== $documentAttribute->versionable) { + $metadata->setVersioned($documentAttribute->versionable); + } + + if (null !== $documentAttribute->uniqueNodeType) { + $metadata->setUniqueNodeType($documentAttribute->uniqueNodeType); + } + + if (null !== $documentAttribute->mixins) { + $metadata->setMixins($documentAttribute->mixins); + } + + if (null !== $documentAttribute->inheritMixins) { + $metadata->setInheritMixins($documentAttribute->inheritMixins); + } + + if (null !== $documentAttribute->nodeType) { + $metadata->setNodeType($documentAttribute->nodeType); + } + + if (null !== $documentAttribute->repositoryClass) { + $metadata->setCustomRepositoryClassName($documentAttribute->repositoryClass); + } + + if (null !== $documentAttribute->translator) { + $metadata->setTranslator($documentAttribute->translator); + } + + if ([] !== $documentAttribute->childClasses) { + $metadata->setChildClasses($documentAttribute->childClasses); + } + + $metadata->setIsLeaf($documentAttribute->isLeaf); + + foreach ($reflectionClass->getProperties() as $property) { + if ($metadata->isInheritedField($property->name) + && $metadata->name !== $property->getDeclaringClass()->getName() + ) { + continue; + } + + $mapping = []; + $mapping['fieldName'] = $property->getName(); + + foreach ($this->reader->getPropertyAttributes($property) as $fieldAttribute) { + if ($fieldAttribute instanceof ODM\Field) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapField($mapping); + } elseif ($fieldAttribute instanceof ODM\Id) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapId($mapping); + } elseif ($fieldAttribute instanceof ODM\Node) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapNode($mapping); + } elseif ($fieldAttribute instanceof ODM\Nodename) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapNodename($mapping); + } elseif ($fieldAttribute instanceof ODM\ParentDocument) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapParentDocument($mapping); + } elseif ($fieldAttribute instanceof ODM\Child) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapChild($mapping); + } elseif ($fieldAttribute instanceof ODM\Children) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapChildren($mapping); + } elseif ($fieldAttribute instanceof ODM\ReferenceOne) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapManyToOne($mapping); + } elseif ($fieldAttribute instanceof ODM\ReferenceMany) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapManyToMany($mapping); + } elseif ($fieldAttribute instanceof ODM\Referrers) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $mapping['cascade'] = $this->getCascadeMode($fieldAttribute->cascade); + $metadata->mapReferrers($mapping); + } elseif ($fieldAttribute instanceof ODM\MixedReferrers) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapMixedReferrers($mapping); + } elseif ($fieldAttribute instanceof ODM\Locale) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapLocale($mapping); + } elseif ($fieldAttribute instanceof ODM\Depth) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapDepth($mapping); + } elseif ($fieldAttribute instanceof ODM\VersionName) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapVersionName($mapping); + } elseif ($fieldAttribute instanceof ODM\VersionCreated) { + $mapping = array_merge($mapping, (array) $fieldAttribute); + $metadata->mapVersionCreated($mapping); + } + } + } + + foreach ($reflectionClass->getMethods() as $method) { + if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) { + foreach ($this->reader->getMethodAttributes($method) as $methodAttribute) { + if ($methodAttribute instanceof ODM\PrePersist) { + $metadata->addLifecycleCallback($method->getName(), Event::prePersist); + } elseif ($methodAttribute instanceof ODM\PostPersist) { + $metadata->addLifecycleCallback($method->getName(), Event::postPersist); + } elseif ($methodAttribute instanceof ODM\PreUpdate) { + $metadata->addLifecycleCallback($method->getName(), Event::preUpdate); + } elseif ($methodAttribute instanceof ODM\PostUpdate) { + $metadata->addLifecycleCallback($method->getName(), Event::postUpdate); + } elseif ($methodAttribute instanceof ODM\PreRemove) { + $metadata->addLifecycleCallback($method->getName(), Event::preRemove); + } elseif ($methodAttribute instanceof ODM\PostRemove) { + $metadata->addLifecycleCallback($method->getName(), Event::postRemove); + } elseif ($methodAttribute instanceof ODM\PostLoad) { + $metadata->addLifecycleCallback($method->getName(), Event::postLoad); + } + } + } + } + + $metadata->validateClassMapping(); + } + + /** + * Gathers a list of cascade options found in the given cascade element. + * + * @param array $cascadeList + * + * @return int a bitmask of cascade options + */ + private function getCascadeMode(array $cascadeList) + { + $cascade = 0; + foreach ($cascadeList as $cascadeMode) { + $constantName = 'Doctrine\ODM\PHPCR\Mapping\ClassMetadata::CASCADE_'.strtoupper($cascadeMode); + if (!defined($constantName)) { + throw new MappingException("Cascade mode '$cascadeMode' not supported."); + } + $cascade |= constant($constantName); + } + + return $cascade; + } +} + +interface_exists(PersistenceClassMetadata::class); diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeReader.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeReader.php new file mode 100644 index 000000000..29acec81a --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeReader.php @@ -0,0 +1,79 @@ + + * + * @template T of MappingAttribute + */ + public function getClassAttributes(ReflectionClass $class): array + { + return $this->convertToAttributeInstances($class->getAttributes()); + } + + /** + * @return class-string-map + * + * @template T of MappingAttribute + */ + public function getMethodAttributes(ReflectionMethod $method): array + { + return $this->convertToAttributeInstances($method->getAttributes()); + } + + /** + * @return class-string-map + * + * @template T of MappingAttribute + */ + public function getPropertyAttributes(ReflectionProperty $property): array + { + return $this->convertToAttributeInstances($property->getAttributes()); + } + + /** + * @param array $attributes + * + * @return class-string-map + * + * @template T of MappingAttribute + */ + private function convertToAttributeInstances(array $attributes): array + { + $instances = []; + + foreach ($attributes as $attribute) { + $attributeName = $attribute->getName(); + assert(is_string($attributeName)); + // Make sure we only get Doctrine Attributes + if (! is_subclass_of($attributeName, MappingAttribute::class)) { + continue; + } + + $instance = $attribute->newInstance(); + assert($instance instanceof MappingAttribute); + + $instances[$attributeName] = $instance; + } + + return $instances; + } +} diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/MappingAttribute.php b/lib/Doctrine/ODM/PHPCR/Mapping/MappingAttribute.php new file mode 100644 index 000000000..5f4cc33cb --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Mapping/MappingAttribute.php @@ -0,0 +1,8 @@ +loadDriver(); + $attributeDriver->addPaths([__DIR__.'/Model']); + + return $attributeDriver; + } + + /** + * Overwriting private parent properties isn't supported with annotations. + * + * @doesNotPerformAssertions + */ + public function testParentWithPrivatePropertyMapping(): void + { + } +} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesAndLeafObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesAndLeafObject.php index 5748a1e89..6ecd3f0c0 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesAndLeafObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesAndLeafObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties @@ -11,8 +12,10 @@ * "stdClass", * }, isLeaf=true) */ +#[PHPCR\Document(childClasses: [\stdClass::class], isLeaf: true)] class ChildClassesAndLeafObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesObject.php index 76cb7637c..5068fae34 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildClassesObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties @@ -11,8 +12,10 @@ * "stdClass", * }, isLeaf=false) */ +#[PHPCR\Document(childClasses: [\stdClass::class], isLeaf: false)] class ChildClassesObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildMappingObject.php index 60752267b..76b86cd41 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildMappingObject.php @@ -3,20 +3,25 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class ChildMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Child(nodeName="first") */ + #[PHPCR\Child(nodeName: 'first')] public $child1; /** @PHPCRODM\Child(nodeName="second") */ + #[PHPCR\Child(nodeName: 'second')] public $child2; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildrenMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildrenMappingObject.php index db6f61d84..0da86de0a 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildrenMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ChildrenMappingObject.php @@ -3,20 +3,25 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class ChildrenMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Children() */ + #[PHPCR\Children] public $all; /** @PHPCRODM\Children(filter="*some*", fetchDepth=2, cascade={"persist", "remove"}) */ + #[PHPCR\Children(filter: '*some*', fetchDepth: 2, cascade: ['persist', 'remove'])] public $some; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildMappingObject.php index 6b036d27c..21aa1c838 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildMappingObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that represents a child class for the purposes @@ -10,6 +11,7 @@ * * @PHPCRODM\Document() */ +#[PHPCR\Document] class ClassInheritanceChildMappingObject extends ClassInheritanceParentMappingObject { } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildOverridesMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildOverridesMappingObject.php index 5db5722a5..c5062ea21 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildOverridesMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceChildOverridesMappingObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that represents a parent class for the purposes @@ -17,6 +18,14 @@ * versionable="full" * ) */ +#[PHPCR\Document( + nodeType: 'nt:test-override', + mixins: ['mix:baz'], + inheritMixins: false, + translator: 'bar', + repositoryClass: BarfooRepository::class, + versionable: 'full', +)] class ClassInheritanceChildOverridesMappingObject extends ClassInheritanceParentMappingObject { } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceParentMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceParentMappingObject.php index 04c25de48..f624844f6 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceParentMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ClassInheritanceParentMappingObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that represents a parent class for the purposes @@ -17,8 +18,16 @@ * versionable="simple" * ) */ +#[PHPCR\Document( + nodeType: 'nt:test', + repositoryClass: DocumentRepository::class, + translator: 'foo', + mixins: ['mix:foo', 'mix:bar'], + referenceable: true, +)] class ClassInheritanceParentMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DefaultMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DefaultMappingObject.php index 8852e8678..bb4d5e96e 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DefaultMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DefaultMappingObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class with no explicitly set properties for testing default values. * * @PHPCRODM\Document */ +#[PHPCR\Document] class DefaultMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DepthMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DepthMappingObject.php index 111fca085..b9acd0883 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DepthMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/DepthMappingObject.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains a mapped parent document via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class DepthMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Depth */ + #[PHPCR\Depth] public $depth; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/FieldMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/FieldMappingObject.php index f40ca9772..09084e0c9 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/FieldMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/FieldMappingObject.php @@ -3,50 +3,65 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped fields via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class FieldMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Field(type="string") */ + #[PHPCR\Field(type: 'string')] public $string; /** @PHPCRODM\Field(type="binary") */ + #[PHPCR\Field(type: 'binary')] public $binary; /** @PHPCRODM\Field(type="long") */ + #[PHPCR\Field(type: 'long')] public $long; /** @PHPCRODM\Field(type="long") */ + #[PHPCR\Field(type: 'long')] public $int; /** @PHPCRODM\Field(type="decimal") */ + #[PHPCR\Field(type: 'decimal')] public $decimal; /** @PHPCRODM\Field(type="double") */ + #[PHPCR\Field(type: 'double')] public $double; /** @PHPCRODM\Field(type="double") */ + #[PHPCR\Field(type: 'double')] public $float; /** @PHPCRODM\Field(type="date") */ + #[PHPCR\Field(type: 'date')] public $date; /** @PHPCRODM\Field(type="boolean") */ + #[PHPCR\Field(type: 'boolean')] public $boolean; /** @PHPCRODM\Field(type="name") */ + #[PHPCR\Field(type: 'name')] public $name; /** @PHPCRODM\Field(type="path") */ + #[PHPCR\Field(type: 'path')] public $path; /** @PHPCRODM\Field(type="uri") */ + #[PHPCR\Field(type: 'uri')] public $uri; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/InheritedMixinMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/InheritedMixinMappingObject.php index bb20f4eab..b1d09f54a 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/InheritedMixinMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/InheritedMixinMappingObject.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document(mixins={"mix:title"}) */ +#[PHPCR\Document(mixins: ['mix:title'])] class InheritedMixinMappingObject extends MixinMappingObject { /** @PHPCRODM\Field(type="string", property="jcr:title") */ + #[PHPCR\Field(type: 'string', property: 'jcr:title')] public $title; /** @PHPCRODM\Field(type="string", property="jcr:description") */ + #[PHPCR\Field(type: 'string', property: 'jcr:description')] public $description; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/IsLeafObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/IsLeafObject.php index b2d1a1bbc..2c6f0a345 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/IsLeafObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/IsLeafObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document(isLeaf=true) */ +#[PHPCR\Document(isLeaf: true)] class IsLeafObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/LifecycleCallbackMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/LifecycleCallbackMappingObject.php index c95112e80..ef14b6681 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/LifecycleCallbackMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/LifecycleCallbackMappingObject.php @@ -3,48 +3,58 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses Lifecycle Callbacks * * @PHPCRODM\Document */ +#[PHPCR\Document] class LifecycleCallbackMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\PreRemove */ + #[PHPCR\PreRemove] public function preRemoveFunc() { } /** @PHPCRODM\PostRemove */ + #[PHPCR\PostRemove] public function postRemoveFunc() { } /** @PHPCRODM\PrePersist */ + #[PHPCR\PrePersist] public function prePersistFunc() { } /** @PHPCRODM\PostPersist */ + #[PHPCR\PostPersist] public function postPersistFunc() { } /** @PHPCRODM\PreUpdate */ + #[PHPCR\PreUpdate] public function preUpdateFunc() { } /** @PHPCRODM\PostUpdate */ + #[PHPCR\PostUpdate] public function postUpdateFunc() { } /** @PHPCRODM\PostLoad */ + #[PHPCR\PostLoad] public function postLoadFunc() { } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MappedSuperclassMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MappedSuperclassMappingObject.php index 5502a0a36..813d28f4c 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MappedSuperclassMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MappedSuperclassMappingObject.php @@ -3,14 +3,24 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\MappedSuperclass(nodeType="phpcr:test", repositoryClass="Doctrine\Tests\ODM\PHPCR\Mapping\Model\DocumentRepository", translator="children", mixins={"mix:one", "mix:two"}, versionable="simple", referenceable=true) */ +#[PHPCR\MappedSuperclass( + nodeType: 'phpcr:test', + repositoryClass: DocumentRepository::class, + translator: 'children', + mixins: ['mix:one', 'mix:two'], + versionable: 'simple', + referenceable: true, +)] class MappedSuperclassMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MixinMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MixinMappingObject.php index 9d3b6a069..d7ea787ab 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MixinMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/MixinMappingObject.php @@ -3,23 +3,29 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document(mixins={"mix:lastModified"}) */ +#[PHPCR\Document(mixins: ['mix:lastModified'])] class MixinMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Node */ + #[PHPCR\Node] public $node; /** @PHPCRODM\Field(type="date", property="jcr:lastModified") */ + #[PHPCR\Field(type: 'date', property: 'jcr:lastModified')] public $lastModified; /** @PHPCRODM\Field(type="string", property="jcr:lastModifiedBy") */ + #[PHPCR\Field(type: 'string', property: 'jcr:lastModifiedBy')] public $lastModifiedBy; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeMappingObject.php index 755e2ac72..6a66e6f7c 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeMappingObject.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\Document */ +#[PHPCR\Document] class NodeMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Node */ + #[PHPCR\Node] public $node; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeTypeMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeTypeMappingObject.php index 1c5c2ebee..0ee41e477 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeTypeMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodeTypeMappingObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\Document(nodeType="nt:test") */ +#[PHPCR\Document(nodeType: 'nt:test')] class NodeTypeMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodenameMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodenameMappingObject.php index f20975836..d94e667b0 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodenameMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/NodenameMappingObject.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped fields via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class NodenameMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Nodename */ + #[PHPCR\Nodename] public $namefield; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ParentDocumentMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ParentDocumentMappingObject.php index 97751419b..1b27bdac3 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ParentDocumentMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ParentDocumentMappingObject.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains a mapped parent document via properties * * @PHPCRODM\Document */ +#[PHPCR\Document] class ParentDocumentMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\ParentDocument */ + #[PHPCR\ParentDocument] public $parent; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceManyMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceManyMappingObject.php index 5a2b7d0c5..d1e3ea989 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceManyMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceManyMappingObject.php @@ -3,20 +3,25 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that references many other documents * * @PHPCRODM\Document */ +#[PHPCR\Document] class ReferenceManyMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\ReferenceMany(targetDocument="myDocument", strategy="weak") */ + #[PHPCR\ReferenceMany(targetDocument: 'myDocument', strategy: 'weak')] public $referenceManyWeak; /** @PHPCRODM\ReferenceMany(targetDocument="myDocument", strategy="hard") */ + #[PHPCR\ReferenceMany(targetDocument: 'myDocument', strategy: 'hard')] public $referenceManyHard; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceOneMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceOneMappingObject.php index d6086ce61..2f40fc9de 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceOneMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceOneMappingObject.php @@ -3,20 +3,25 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that references one other document * * @PHPCRODM\Document */ +#[PHPCR\Document] class ReferenceOneMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\ReferenceOne(targetDocument="myDocument", strategy="weak") */ + #[PHPCR\ReferenceOne(targetDocument: 'myDocument', strategy: 'weak')] public $referenceOneWeak; /** @PHPCRODM\ReferenceOne(targetDocument="myDocument", strategy="hard") */ + #[PHPCR\ReferenceOne(targetDocument: 'myDocument', strategy: 'hard')] public $referenceOneHard; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildMappingObject.php index 32ae8e9b5..79691c266 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildMappingObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * Object which extends a referenceable object and so should also @@ -10,8 +11,10 @@ * * @PHPCRODM\Document() */ +#[PHPCR\Document] class ReferenceableChildMappingObject extends ReferenceableMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildReferenceableFalseMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildReferenceableFalseMappingObject.php index 6e5217962..421a14729 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildReferenceableFalseMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableChildReferenceableFalseMappingObject.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * An object that extends a referenceable object but sets @@ -10,6 +11,7 @@ * * @PHPCRODM\Document(referenceable=false) */ +#[PHPCR\Document(referenceable: false)] class ReferenceableChildReferenceableFalseMappingObject extends ReferenceableMappingObject { } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableMappingObject.php index 9737cf4f5..2129c64f2 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferenceableMappingObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\Document(referenceable=true) */ +#[PHPCR\Document(referenceable: true)] class ReferenceableMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferrersMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferrersMappingObject.php index c4a5a585d..6a70e70fe 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferrersMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReferrersMappingObject.php @@ -3,34 +3,41 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses referrers * * @PHPCRODM\Document(referenceable=true) */ +#[PHPCR\Document(referenceable: true)] class ReferrersMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** * @PHPCRODM\MixedReferrers */ + #[PHPCR\MixedReferrers] public $allReferrers; /** * @PHPCRODM\Referrers(referencedBy="referenceManyWeak", referringDocument="ReferenceManyMappingObject") */ + #[PHPCR\Referrers(referencedBy: 'referenceManyWeak', referringDocument: ReferenceManyMappingObject::class)] public $filteredReferrers; /** * @PHPCRODM\MixedReferrers(referenceType="hard") */ + #[PHPCR\MixedReferrers(referenceType: 'hard')] public $hardReferrers; /** * @PHPCRODM\MixedReferrers(referenceType="weak") */ + #[PHPCR\MixedReferrers(referenceType: 'weak')] public $weakReferrers; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReplaceMixinMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReplaceMixinMappingObject.php index 74d60248b..680e2f936 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReplaceMixinMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/ReplaceMixinMappingObject.php @@ -3,23 +3,29 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that contains mapped children via properties * * @PHPCRODM\Document(mixins={"mix:lastModified"}, inheritMixins=false) */ +#[PHPCR\Document(mixins: ['mix:lastModified'], inheritMixins: false)] class ReplaceMixinMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Node */ + #[PHPCR\Node] public $node; /** @PHPCRODM\Field(type="date", property="jcr:lastModified") */ + #[PHPCR\Field(type: 'date', property: 'jcr:lastModified')] public $lastModified; /** @PHPCRODM\Field(type="string", property="jcr:lastModifiedBy") */ + #[PHPCR\Field(type: 'string', property: 'jcr:lastModifiedBy')] public $lastModifiedBy; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/RepositoryMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/RepositoryMappingObject.php index cea4730f8..624a8640b 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/RepositoryMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/RepositoryMappingObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\Document(repositoryClass="Doctrine\Tests\ODM\PHPCR\Mapping\Model\DocumentRepository") */ +#[PHPCR\Document(repositoryClass: DocumentRepository::class)] class RepositoryMappingObject { /** @PHPCRODM\Id(strategy="repository") */ + #[PHPCR\Id(strategy: 'repository')] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringExtendedMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringExtendedMappingObject.php index 1b39618b5..e94037246 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringExtendedMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringExtendedMappingObject.php @@ -3,12 +3,14 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that extends a class which contains string properties * * @PHPCRODM\Document(translator="attribute") */ +#[PHPCR\Document(translator: 'attribute')] class StringExtendedMappingObject extends StringMappingObject { /** @@ -16,8 +18,10 @@ class StringExtendedMappingObject extends StringMappingObject * * @PHPCRODM\Locale */ + #[PHPCR\Locale] private $doclocale; /** @PHPCRODM\Field(type="string", translated=true) */ + #[PHPCR\Field(type: 'string', translated: true)] public $stringAssoc; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringMappingObject.php index 8b1c26ce6..0214cfea2 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/StringMappingObject.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; /** @@ -9,11 +10,14 @@ * * @PHPCRODM\Document */ +#[PHPCR\Document] class StringMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\Field(type="string", assoc="") */ + #[PHPCR\Field(type: 'string', assoc: '')] public $stringAssoc; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObject.php index e5f3afc6d..0b26a28f3 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObject.php @@ -3,12 +3,14 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses translator and translatable * * @PHPCRODM\Document(translator="attribute") */ +#[PHPCR\Document(translator: 'attribute')] class TranslatorMappingObject { /** @@ -16,6 +18,7 @@ class TranslatorMappingObject * * @PHPCRODM\Id */ + #[PHPCR\Id] private $id; /** @@ -23,6 +26,7 @@ class TranslatorMappingObject * * @PHPCRODM\Locale */ + #[PHPCR\Locale] private $doclocale; /** @@ -30,6 +34,7 @@ class TranslatorMappingObject * * @PHPCRODM\Field(type="date") */ + #[PHPCR\Field(type: 'date')] private $publishDate; /** @@ -37,6 +42,7 @@ class TranslatorMappingObject * * @PHPCRODM\Field(type="string", translated=true) */ + #[PHPCR\Field(type: 'string', translated: true)] private $topic; /** @@ -44,5 +50,6 @@ class TranslatorMappingObject * * @PHPCRODM\Field(type="binary", translated=true) */ + #[PHPCR\Field(type: 'binary', translated: true)] private $image; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObjectNoStrategy.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObjectNoStrategy.php index 41116f57e..8cb81649b 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObjectNoStrategy.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/TranslatorMappingObjectNoStrategy.php @@ -3,19 +3,20 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * An invalid class with translated fields but no translator * * @PHPCRODM\Document() */ +#[PHPCR\Document] class TranslatorMappingObjectNoStrategy { /** - * The path - * * @PHPCRODM\Id */ + #[PHPCR\Id] private $id; /** @@ -23,6 +24,7 @@ class TranslatorMappingObjectNoStrategy * * @PHPCRODM\Locale */ + #[PHPCR\Locale] private $doclocale; /** @@ -30,6 +32,7 @@ class TranslatorMappingObjectNoStrategy * * @PHPCRODM\Field(type="date") */ + #[PHPCR\Field(type: 'date')] private $publishDate; /** @@ -37,6 +40,7 @@ class TranslatorMappingObjectNoStrategy * * @PHPCRODM\Field(type="string", translated=true) */ + #[PHPCR\Field(type: 'string', translated: true)] private $topic; /** @@ -44,5 +48,6 @@ class TranslatorMappingObjectNoStrategy * * @PHPCRODM\Field(type="binary", translated=true) */ + #[PHPCR\Field(type: 'binary', translated: true)] private $image; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UniqueNodeTypeMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UniqueNodeTypeMappingObject.php index 6a9cebb31..e04c532f0 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UniqueNodeTypeMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UniqueNodeTypeMappingObject.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that has a unique node type among other mapped documents. * * @PHPCRODM\Document(uniqueNodeType=true) */ +#[PHPCR\Document(uniqueNodeType: true)] class UniqueNodeTypeMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObject.php index 4313aa678..6e371c3ba 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObject.php @@ -3,15 +3,19 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * @PHPCRODM\Document(referenceable=true) */ +#[PHPCR\Document(referenceable: true)] class UuidMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; - /** @PHPCRODM\Uuid()*/ + /** @PHPCRODM\Uuid */ + #[PHPCR\Uuid] public $uuid; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObjectNotReferenceable.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObjectNotReferenceable.php index 349d2c8db..6419b2e29 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObjectNotReferenceable.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/UuidMappingObjectNotReferenceable.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * An invalid document that has the uuid mapped but is not referenceable. * * @PHPCRODM\Document(referenceable=false) */ +#[PHPCR\Document(referenceable: false)] class UuidMappingObjectNotReferenceable { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; - /** @PHPCRODM\Uuid() */ + /** @PHPCRODM\Uuid */ + #[PHPCR\Uuid] public $uuid; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/VersionableMappingObject.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/VersionableMappingObject.php index da55da9a5..5c8aea4aa 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/VersionableMappingObject.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/Model/VersionableMappingObject.php @@ -3,20 +3,25 @@ namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model; use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; /** * A class that uses the repository strategy to generate IDs * * @PHPCRODM\Document(versionable="simple") */ +#[PHPCR\Document(versionable: 'simple')] class VersionableMappingObject { /** @PHPCRODM\Id */ + #[PHPCR\Id] public $id; /** @PHPCRODM\VersionName */ + #[PHPCR\VersionName] private $versionName; /** @PHPCRODM\VersionCreated */ + #[PHPCR\VersionCreated] private $versionCreated; }