@@ -299,6 +299,7 @@ private function generateFactory(array $tableList) : void
299
299
300
300
namespace {$ daoNamespace }\\Generated;
301
301
302
+ use Psr\Container\ContainerInterface;
302
303
" ;
303
304
foreach ($ tableList as $ table ) {
304
305
$ tableName = $ table ->getName ();
@@ -313,6 +314,14 @@ private function generateFactory(array $tableList) : void
313
314
*/
314
315
class $ daoFactoryClassName
315
316
{
317
+ private \$container;
318
+
319
+ public function __construct(ContainerInterface \$container)
320
+ {
321
+ \$this->container = \$container;
322
+ }
323
+
324
+
316
325
" ;
317
326
318
327
foreach ($ tableList as $ table ) {
@@ -321,7 +330,7 @@ class $daoFactoryClassName
321
330
$ daoInstanceName = self ::toVariableName ($ daoClassName );
322
331
323
332
$ str .= ' /**
324
- * @var ' .$ daoClassName .'
333
+ * @var ' .$ daoClassName .'|null
325
334
*/
326
335
private $ ' .$ daoInstanceName .';
327
336
@@ -332,11 +341,15 @@ class $daoFactoryClassName
332
341
*/
333
342
public function get ' .$ daoClassName .'() : ' .$ daoClassName .'
334
343
{
344
+ if (!$this-> ' .$ daoInstanceName .') {
345
+ $this-> ' .$ daoInstanceName .' = $this->container->get( ' .$ daoClassName .'::class);
346
+ }
347
+
335
348
return $this-> ' .$ daoInstanceName .';
336
349
}
337
350
338
351
/**
339
- * Sets the instance of the ' .$ daoClassName .' class that will be returned by the factory getter.
352
+ * Override the instance of the ' .$ daoClassName .' class that will be returned by the factory getter.
340
353
*
341
354
* @param ' .$ daoClassName .' $ ' .$ daoInstanceName .'
342
355
*/
0 commit comments