Skip to content

Commit a13c53d

Browse files
committed
docs: update existing description
1 parent 340a930 commit a13c53d

1 file changed

Lines changed: 32 additions & 16 deletions

File tree

user_guide_src/source/concepts/factories.rst

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ by using the magic static method of the Factories class, ``Factories::models()``
5454

5555
The static method name is called *component*.
5656

57-
By default, Factories first searches in the ``App`` namespace for the path corresponding to the magic static method name.
57+
.. _factories-passing-classname-without-namespace:
58+
59+
Passing Classname without Namespace
60+
-----------------------------------
61+
62+
If you pass a classname without a namespace, Factories first searches in the
63+
``App`` namespace for the path corresponding to the magic static method name.
5864
``Factories::models()`` searches the **app/Models** directory.
5965

66+
Passing Short Classname
67+
^^^^^^^^^^^^^^^^^^^^^^^
68+
6069
In the following code, if you have ``App\Models\UserModel``, the instance will be returned:
6170

6271
.. literalinclude:: factories/001.php
@@ -68,31 +77,35 @@ you get back the instance as before:
6877

6978
.. literalinclude:: factories/003.php
7079

71-
preferApp option
72-
----------------
80+
Passing Short Classname with Sub-directories
81+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7382

74-
You could also request a specific class:
83+
If you want to load a class in sub directories, you use the ``/`` as a separator.
84+
The following code loads **app/Libraries/Sub/SubLib.php** if it exists:
7585

76-
.. literalinclude:: factories/002.php
86+
.. literalinclude:: factories/013.php
7787
:lines: 2-
7888

79-
If you have only ``Blog\Models\UserModel``, the instance will be returned.
80-
But if you have both ``App\Models\UserModel`` and ``Blog\Models\UserModel``,
81-
the instance of ``App\Models\UserModel`` will be returned.
89+
Passing Full Qualified Classname
90+
--------------------------------
8291

83-
If you want to get ``Blog\Models\UserModel``, you need to disable the option ``preferApp``:
92+
You could also request a full qualified classname:
8493

85-
.. literalinclude:: factories/010.php
94+
.. literalinclude:: factories/002.php
8695
:lines: 2-
8796

88-
Loading a Class in Sub-directories
89-
==================================
97+
It returns the instance of ``Blog\Models\UserModel`` if it exists.
9098

91-
If you want to load a class in sub directories, you use the ``/`` as a separator.
92-
The following code loads **app/Libraries/Sub/SubLib.php**:
99+
.. note:: Prior to v4.4.0, when you requested a full qualified classname,
100+
if you had only ``Blog\Models\UserModel``, the instance would be returned.
101+
But if you had both ``App\Models\UserModel`` and ``Blog\Models\UserModel``,
102+
the instance of ``App\Models\UserModel`` would be returned.
93103

94-
.. literalinclude:: factories/013.php
95-
:lines: 2-
104+
If you wanted to get ``Blog\Models\UserModel``, you needed to disable the
105+
option ``preferApp``:
106+
107+
.. literalinclude:: factories/010.php
108+
:lines: 2-
96109

97110
Convenience Functions
98111
*********************
@@ -154,6 +167,9 @@ preferApp boolean Whether a class with the same basename in the App name
154167
overrides other explicit class requests.
155168
========== ============== ============================================================ ===================================================
156169

170+
.. note:: Since v4.4.0, ``preferApp`` works only when you request
171+
:ref:`a classname without a namespace <factories-passing-classname-without-namespace>`.
172+
157173
Factories Behavior
158174
******************
159175

0 commit comments

Comments
 (0)