From 801ab3219bec15c86ab7ba6318d111542467766d Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk Date: Tue, 15 Apr 2025 11:06:32 +0300 Subject: [PATCH 1/3] Describe custom metadata files regex with AttributeDriver::setFileRegex() --- docs/en/reference/advanced-configuration.rst | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 523e5575d3..1738d74806 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -415,6 +415,28 @@ 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. +Custom Metadata Files Regex +--------------------------- + +When using the ``AttributeDriver`` in combination with domain-oriented folder structures, +it's common to have domain-related classes like tests, fixtures, commands within the same +directory as entity classes. These should typically be excluded from metadata mapping. + +You can define a regular expression to filter which files the driver will consider as mapping sources: + +.. code-block:: php + + setFileRegex('/^(?!.*(Test|Fixture|Command)\.php$).*\.php$/'); + +Provided regular expression is going to be matched against each file name during mapping discovery. +In this example, files ending with ``Test.php``, ``Fixture.php``, or ``Command.php`` will be excluded. +This allows to ensure that only actual entity classes are taken into account when loading metadata, +preventing unrelated files from being included by the driver. + Multiple Metadata Sources ------------------------- From ba600701a1ecd3c66f93e6c2473b4a4b170a3d20 Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk <41589422+rela589n@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:34:43 +0300 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tweak descriptions Co-authored-by: Grégoire Paris --- docs/en/reference/advanced-configuration.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 1738d74806..82acbc5bfa 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -418,7 +418,7 @@ be found. Custom Metadata Files Regex --------------------------- -When using the ``AttributeDriver`` in combination with domain-oriented folder structures, +When using the ``AttributeDriver`` in combination with domain-oriented directory structures, it's common to have domain-related classes like tests, fixtures, commands within the same directory as entity classes. These should typically be excluded from metadata mapping. @@ -432,9 +432,9 @@ You can define a regular expression to filter which files the driver will consid $driver = new AttributeDriver([__DIR__ . '/src/Domain/User']); $driver->setFileRegex('/^(?!.*(Test|Fixture|Command)\.php$).*\.php$/'); -Provided regular expression is going to be matched against each file name during mapping discovery. +The provided regular expression is going to be matched against each file name during mapping discovery. In this example, files ending with ``Test.php``, ``Fixture.php``, or ``Command.php`` will be excluded. -This allows to ensure that only actual entity classes are taken into account when loading metadata, +This ensures that only actual entity classes are taken into account when loading metadata, preventing unrelated files from being included by the driver. Multiple Metadata Sources From d4fa78fc1129e59d599b31c45c15a5e05129063f Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk Date: Wed, 16 Apr 2025 13:58:16 +0300 Subject: [PATCH 3/3] Add custom directory structure example --- docs/en/reference/advanced-configuration.rst | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 82acbc5bfa..43e4b225b6 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -422,6 +422,24 @@ When using the ``AttributeDriver`` in combination with domain-oriented directory it's common to have domain-related classes like tests, fixtures, commands within the same directory as entity classes. These should typically be excluded from metadata mapping. +For example, a typical directory structure for User aggregate might look like this: + +.. code-block:: text + + User/ + ├── User.php + ├── UserFixture.php + ├── Email/ + │ ├── Email.php + │ └── EmailTest.php + ├── Password/ + │ ├── Password.php + │ └── PasswordTest.php + └── Actions/ + └── Register/ + ├── RegisterUserCommand.php + └── RegisterUserTest.php + You can define a regular expression to filter which files the driver will consider as mapping sources: .. code-block:: php @@ -433,7 +451,9 @@ You can define a regular expression to filter which files the driver will consid $driver->setFileRegex('/^(?!.*(Test|Fixture|Command)\.php$).*\.php$/'); The provided regular expression is going to be matched against each file name during mapping discovery. -In this example, files ending with ``Test.php``, ``Fixture.php``, or ``Command.php`` will be excluded. +In this example, files ending with ``Test.php``, ``Fixture.php``, or ``Command.php`` will be excluded, +while `User.php`, `Email.php`, and `Password.php` will be included. + This ensures that only actual entity classes are taken into account when loading metadata, preventing unrelated files from being included by the driver.