Skip to content

Commit

Permalink
CycleDynamicFactory now uses Injector from container
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Nov 13, 2020
1 parent 767dc8d commit d5dda92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion config/common.php
Expand Up @@ -11,6 +11,7 @@
use Spiral\Core\FactoryInterface as SpiralFactoryInterface;
use Spiral\Database\DatabaseManager;
use Spiral\Database\DatabaseProviderInterface;
use Yiisoft\Injector\Injector;
use Yiisoft\Yii\Cycle\Exception\SchemaWasNotProvidedException;
use Yiisoft\Yii\Cycle\Factory\CycleDynamicFactory;
use Yiisoft\Yii\Cycle\Factory\DbalFactory;
Expand All @@ -32,7 +33,9 @@
// Cycle ORM
ORMInterface::class => new OrmFactory($params['yiisoft/yii-cycle']['orm-promise-factory']),
// Spiral Core Factory
SpiralFactoryInterface::class => static fn (ContainerInterface $container) => new CycleDynamicFactory($container),
SpiralFactoryInterface::class => static function (ContainerInterface $container) {
return new CycleDynamicFactory($container->get(Injector::class));
},
// Factory for Cycle ORM
CycleFactoryInterface::class => static function (ContainerInterface $container) {
return new Factory(
Expand Down
5 changes: 2 additions & 3 deletions src/Factory/CycleDynamicFactory.php
Expand Up @@ -4,16 +4,15 @@

namespace Yiisoft\Yii\Cycle\Factory;

use Psr\Container\ContainerInterface;
use Spiral\Core\FactoryInterface;
use Yiisoft\Injector\Injector;

final class CycleDynamicFactory implements FactoryInterface
{
private Injector $injector;
public function __construct(ContainerInterface $container)
public function __construct(Injector $injector)
{
$this->injector = new Injector($container);
$this->injector = $injector;
}

public function make(string $alias, array $parameters = [])
Expand Down
3 changes: 2 additions & 1 deletion tests/Factory/DbalFactory/BaseDbalFactoryTest.php
Expand Up @@ -9,6 +9,7 @@
use Psr\Log\NullLogger;
use Spiral\Core\FactoryInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Injector\Injector;
use Yiisoft\Test\Support\Container\Exception\NotFoundException;
use Yiisoft\Test\Support\Container\SimpleContainer;
use Yiisoft\Yii\Cycle\Factory\CycleDynamicFactory;
Expand All @@ -30,7 +31,7 @@ protected function setUp(): void
],
function (string $id) {
if ($id === FactoryInterface::class) {
return new CycleDynamicFactory($this->container);
return new CycleDynamicFactory(new Injector($this->container));
}
throw new NotFoundException($id);
}
Expand Down

0 comments on commit d5dda92

Please sign in to comment.