@@ -7,10 +7,10 @@ Factories
77 :depth: 2
88
99Introduction
10- ============
10+ ************
1111
1212What are Factories?
13- -------------------
13+ ===================
1414
1515Like :doc: `./services `, **Factories ** are an extension of autoloading that helps keep your code
1616concise yet optimal, without having to pass around object instances between classes.
@@ -25,7 +25,7 @@ to work on or transmit common data. The framework itself uses Factories internal
2525make sure the correct configuration is loaded when using the ``Config `` class.
2626
2727Differences from Services
28- -------------------------
28+ =========================
2929
3030Factories require a concrete class name to instantiate and do not have code to create instances.
3131
@@ -37,7 +37,7 @@ that needs other services or class instances. When you get a service, Services r
3737not a class name, so the returned instance can be changed without changing the client code.
3838
3939Example
40- -------
40+ =======
4141
4242Take a look at **Models ** as an example. You can access the Factory specific to Models
4343by using the magic static method of the Factories class, ``Factories::models() ``.
@@ -69,26 +69,26 @@ you get back the instance as before:
6969.. literalinclude :: factories/003.php
7070
7171Convenience Functions
72- =====================
72+ *********************
7373
7474Two shortcut functions for Factories have been provided. These functions are always available.
7575
7676config()
77- --------
77+ ========
7878
7979The first is ``config() `` which returns a new instance of a Config class. The only required parameter is the class name:
8080
8181.. literalinclude :: factories/008.php
8282
8383model()
84- --------
84+ =======
8585
8686The second function, ``model() `` returns a new instance of a Model class. The only required parameter is the class name:
8787
8888.. literalinclude :: factories/009.php
8989
9090Factory Parameters
91- ==================
91+ ******************
9292
9393``Factories `` takes as a second parameter an array of option values (described below).
9494These directives will override the default options configured for each component.
@@ -106,7 +106,7 @@ class instance that uses the alternate database connection.
106106.. _factories-options :
107107
108108Factories Options
109- ==================
109+ *****************
110110
111111The default behavior might not work for every component. For example, say your component
112112name and its path do not align, or you need to limit instances to a certain type of class.
@@ -127,7 +127,7 @@ preferApp boolean Whether a class with the same basename in the App name
127127========== ============== ============================================================ ===================================================
128128
129129Factories Behavior
130- ==================
130+ ******************
131131
132132Options can be applied in one of three ways (listed in ascending priority):
133133
@@ -136,7 +136,7 @@ Options can be applied in one of three ways (listed in ascending priority):
136136* Passing options directly at call time with a parameter.
137137
138138Configurations
139- --------------
139+ ==============
140140
141141To set default component options, create a new Config files at **app/Config/Factory.php **
142142that supplies options as an array property that matches the name of the component.
@@ -154,7 +154,7 @@ This would prevent conflict of an third-party module which happened to have an
154154unrelated ``Filters `` path in its namespace.
155155
156156setOptions Method
157- -----------------
157+ =================
158158
159159The ``Factories `` class has a static method to allow runtime option configuration: simply
160160supply the desired array of options using the ``setOptions() `` method and they will be
@@ -163,7 +163,7 @@ merged with the default values and stored for the next call:
163163.. literalinclude :: factories/006.php
164164
165165Parameter Options
166- -----------------
166+ =================
167167
168168``Factories ``'s magic static call takes as a second parameter an array of option values.
169169These directives will override the stored options configured for each component and can be
@@ -175,4 +175,4 @@ a component. By adding a second parameter to the magic static call, you can cont
175175that single call will return a new or shared instance:
176176
177177.. literalinclude :: factories/007.php
178- :lines: 2-
178+ :lines: 2-
0 commit comments