Skip to content

Commit 886fa87

Browse files
committed
docs: add about Factories::define()
1 parent a13c53d commit 886fa87

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

user_guide_src/source/concepts/factories.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,29 @@ The second function, :php:func:`model()` returns a new instance of a Model class
128128

129129
.. literalinclude:: factories/009.php
130130

131+
.. _factories-defining-classname-to-be-loaded:
132+
133+
Defining Classname to be Loaded
134+
*******************************
135+
136+
.. versionadded:: 4.4.0
137+
138+
You could define a classname to be loaded before loading the class with
139+
the ``Factories::define()`` method:
140+
141+
.. literalinclude:: factories/014.php
142+
:lines: 2-
143+
144+
The first parameter is a component. The second parameter is a class alias
145+
(the first parameter to Factories magic static method), and the third parameter
146+
is the true full qualified classname to be loaded.
147+
148+
After that, if you load ``Myth\Auth\Models\UserModel`` with Factories, the
149+
``App\Models\UserModel`` instance will be returned:
150+
151+
.. literalinclude:: factories/015.php
152+
:lines: 2-
153+
131154
Factory Parameters
132155
******************
133156

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
Factories::define('models', 'Myth\Auth\Models\UserModel', 'App\Models\UserModel');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$users = model('Myth\Auth\Models\UserModel');

0 commit comments

Comments
 (0)