Skip to content

Commit 4d95cde

Browse files
author
arp
committed
edited the daoFactory generation code to lazyload from the container
1 parent 6c1bc9f commit 4d95cde

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Utils/TDBMDaoGenerator.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ private function generateFactory(array $tableList) : void
313313
*/
314314
class $daoFactoryClassName
315315
{
316+
private \$container;
317+
318+
public function __construct(ContainerInterface \$container)
319+
{
320+
\$this->container = \$container;
321+
}
322+
323+
316324
";
317325

318326
foreach ($tableList as $table) {
@@ -332,11 +340,15 @@ class $daoFactoryClassName
332340
*/
333341
public function get'.$daoClassName.'() : '.$daoClassName.'
334342
{
343+
if (!$this->'.$daoInstanceName.') {
344+
$this->'.$daoInstanceName.' = $this->container->get('.$daoClassName.'::class);
345+
}
346+
335347
return $this->'.$daoInstanceName.';
336348
}
337349
338350
/**
339-
* Sets the instance of the '.$daoClassName.' class that will be returned by the factory getter.
351+
* Override the instance of the '.$daoClassName.' class that will be returned by the factory getter.
340352
*
341353
* @param '.$daoClassName.' $'.$daoInstanceName.'
342354
*/

0 commit comments

Comments
 (0)