Skip to content

Commit 4e4c404

Browse files
Change factory inheritance to composition
1 parent af66166 commit 4e4c404

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/ActiveRecordFactory.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
use Yiisoft\Factory\Exceptions\InvalidConfigException;
1010
use Yiisoft\Factory\Factory;
1111

12-
final class ActiveRecordFactory extends Factory
12+
final class ActiveRecordFactory
1313
{
14+
/**
15+
* @var Factory
16+
*/
17+
private Factory $factory;
18+
19+
public function __construct(Factory $factory)
20+
{
21+
$this->factory = $factory;
22+
}
23+
1424
/**
1525
* Allows you to create an active record instance through the factory.
1626
*
@@ -22,7 +32,7 @@ final class ActiveRecordFactory extends Factory
2232
*/
2333
public function createAR(string $arClass): ActiveRecordInterface
2434
{
25-
return $this->create(
35+
return $this->factory->create(
2636
[
2737
'__class' => $arClass,
2838
]
@@ -41,7 +51,7 @@ public function createAR(string $arClass): ActiveRecordInterface
4151
*/
4252
public function createQueryTo(string $arClass, string $queryClass = null): ActiveQueryInterface
4353
{
44-
return $this->create(
54+
return $this->factory->create(
4555
[
4656
'__class' => $queryClass ?? ActiveQuery::class,
4757
'__construct()' => [
@@ -63,7 +73,7 @@ public function createQueryTo(string $arClass, string $queryClass = null): Activ
6373
*/
6474
public function createRedisQueryTo(string $arClass, string $queryClass = null): ActiveQueryInterface
6575
{
66-
return $this->create(
76+
return $this->factory->create(
6777
[
6878
'__class' => $queryClass ?? RedisActiveQuery::class,
6979
'__construct()' => [
@@ -83,7 +93,7 @@ public function createRedisQueryTo(string $arClass, string $queryClass = null):
8393
*/
8494
public function withConnection(ConnectionInterface $connection): void
8595
{
86-
$this->set(ConnectionInterface::class, $connection);
96+
$this->factory->set(ConnectionInterface::class, $connection);
8797
}
8898

8999
/**
@@ -95,6 +105,6 @@ public function withConnection(ConnectionInterface $connection): void
95105
*/
96106
public function getConnection(): ConnectionInterface
97107
{
98-
return $this->create(ConnectionInterface::class);
108+
return $this->factory->create(ConnectionInterface::class);
99109
}
100110
}

tests/TestCase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
3030
use Yiisoft\EventDispatcher\Provider\Provider;
3131
use Yiisoft\Factory\Definitions\Reference;
32+
use Yiisoft\Factory\Factory;
3233
use Yiisoft\Log\Logger;
3334
use Yiisoft\Profiler\Profiler;
3435
use Yiisoft\Profiler\ProfilerInterface;
@@ -288,8 +289,8 @@ private function config(): array
288289
],
289290
],
290291

291-
ActiveRecordFactory::class => [
292-
'__class' => ActiveRecordFactory::class,
292+
Factory::class => [
293+
'__class' => Factory::class,
293294
'__construct()' => [
294295
null,
295296
[ConnectionInterface::class => Reference::to(SqliteConnection::class)],

0 commit comments

Comments
 (0)