Skip to content

Commit d154052

Browse files
committed
docs: add another example
1 parent 4a29526 commit d154052

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

user_guide_src/source/concepts/factories.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ Configurations
150150
To set default component options, create a new Config files at **app/Config/Factory.php**
151151
that supplies options as an array property that matches the name of the component.
152152

153+
Example: Filters Factories
154+
--------------------------
155+
153156
For example, if you want to create **Filters** by Factories, the component name wll be ``filters``.
154157
And if you want to ensure that each filter is an instance of a class which implements CodeIgniter's ``FilterInterface``,
155158
your **app/Config/Factory.php** file might look like this:
@@ -162,6 +165,22 @@ and the returned instance will surely be a CodeIgniter's filter.
162165
This would prevent conflict of an third-party module which happened to have an
163166
unrelated ``Filters`` path in its namespace.
164167

168+
Example: Library Factories
169+
--------------------------
170+
171+
If you want to load your library classes in the **app/Libraries** directory with
172+
``Factories::library('SomeLib')``, the path `Libraries` is different from the
173+
default path `Library`.
174+
175+
In this case, your **app/Config/Factory.php** file will look like this:
176+
177+
.. literalinclude:: factories/011.php
178+
179+
Now you can load your libraries with the ``Factories::library()`` method:
180+
181+
.. literalinclude:: factories/012.php
182+
:lines: 2-
183+
165184
setOptions Method
166185
=================
167186

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Config;
4+
5+
use CodeIgniter\Config\Factory as BaseFactory;
6+
7+
class Factory extends BaseFactory
8+
{
9+
public $library = [
10+
'path' => 'Libraries',
11+
];
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use CodeIgniter\Config\Factories;
4+
5+
$someLib = Factories::library('SomeLib');

0 commit comments

Comments
 (0)