File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,11 @@ protected function createObject(mixed $value): array
180180 if ($ value ) {
181181 Obj::init ($ obj , $ value );
182182 }
183+ } elseif (isset ($ value ['__creator ' ]) && is_callable ($ value ['__creator ' ])) {
184+ $ creator = $ value ['__creator ' ];
185+ // create object.
186+ $ obj = $ creator ($ this );
187+ $ opt = $ value ['__opt ' ] ?? [];
183188 }
184189 }
185190
@@ -194,17 +199,19 @@ protected function createObject(mixed $value): array
194199 /**
195200 * Register an service definition to the box.
196201 *
197- * **$definition**:
202+ * **For $definition**:
198203 *
199- * - Closure
204+ * - Closure(ObjectBox): object
200205 * - Object and has __invoke()
201206 * - string: an function name
202207 * - array: callable array [class, method]
203208 * - array: config array
204209 *
205210 * ```php
206211 * [
207- * 'class' => string,
212+ * 'class' => class-string,
213+ * // '__creator' => callable(ObjectBox): object, // can also use creator func.
214+ *
208215 * // option for create object.
209216 * '__opt' => [
210217 * 'callInit' => true,
You can’t perform that action at this time.
0 commit comments