Skip to content

Commit

Permalink
Update MediaQueryModule constructor
Browse files Browse the repository at this point in the history
install AuraSqlModule separately
  • Loading branch information
koriym committed Feb 6, 2021
1 parent 55f824a commit 601a1a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
17 changes: 9 additions & 8 deletions README.ja.md
Expand Up @@ -42,14 +42,15 @@ interface TodoItemInterface
クエリーインターフェイスを指定して、モジュールをインストールします。

```php
protected function configure(): void
{
$mediaQueries = [
TodoAddInterface::class,
TodoItemInterface::class,
];
$this->install(new MediaQueryModule('sqlite::memory:', $sqlDir, $mediaQueries));
}
protected function configure(): void
{
$mediaQueries = [
UserAddInterface::class,
UserItemInterface::class
];
$this->install(new MediaQueryModule($this->sqlDir, $mediaQueries));
$this->install(new AuraSqlModule($this->dsn));
}
```

実装クラスを用意する必要はありません。生成され、インジェクトされます。
Expand Down
17 changes: 9 additions & 8 deletions README.md
Expand Up @@ -45,14 +45,15 @@ interface TodoItemInterface
Specify the query interface and install the module.

```php
protected function configure(): void
{
$mediaQueries = [
TodoAddInterface::class,
TodoItemInterface::class, TodoItemInterface::class,
];
$this->install(new MediaQueryModule('sqlite::memory:', $sqlDir, $mediaQueries));
}
protected function configure(): void
{
$mediaQueries = [
UserAddInterface::class,
UserItemInterface::class
];
$this->install(new MediaQueryModule($this->sqlDir, $mediaQueries));
$this->install(new AuraSqlModule($this->dsn));
}
```

You don't need to provide any implementation classes. It will be generated and injected.
Expand Down
3 changes: 2 additions & 1 deletion demo/run.php
Expand Up @@ -28,7 +28,8 @@ protected function configure()
UserAddInterface::class,
UserItemInterface::class
];
$this->install(new MediaQueryModule($this->dsn, $this->sqlDir, $mediaQueries));
$this->install(new MediaQueryModule($this->sqlDir, $mediaQueries));
$this->install(new AuraSqlModule($this->dsn));
}
});
/** @var ExtendedPdoInterface $pdo */
Expand Down
5 changes: 1 addition & 4 deletions src/MediaQueryModule.php
Expand Up @@ -17,22 +17,19 @@ class MediaQueryModule extends AbstractModule

/** @var array<class-string> */
private $mediaQueries;
private string $dsn;

/**
* @param array<class-string> $mediaQueries
*/
public function __construct(string $dsn, string $sqlDir, array $mediaQueries, ?AbstractModule $module = null)
public function __construct(string $sqlDir, array $mediaQueries, ?AbstractModule $module = null)
{
$this->mediaQueries = $mediaQueries;
$this->sqlDir = $sqlDir;
$this->dsn = $dsn;
parent::__construct($module);
}

protected function configure(): void
{
$this->install(new AuraSqlModule($this->dsn));
$this->bind(SqlQueryInterface::class)->to(SqlQuery::class);
$this->bind(MediaQueryLoggerInterface::class)->to(MediaQueryLogger::class)->in(Scope::SINGLETON);
$this->bindInterceptor(
Expand Down
3 changes: 2 additions & 1 deletion tests/MediaQueryModuleTest.php
Expand Up @@ -6,6 +6,7 @@

use Aura\Sql\ExtendedPdoInterface;
use PHPUnit\Framework\TestCase;
use Ray\AuraSqlModule\AuraSqlModule;
use Ray\AuraSqlModule\Pagerfanta\Page;
use Ray\Di\AbstractModule;
use Ray\Di\Injector;
Expand Down Expand Up @@ -34,7 +35,7 @@ protected function setUp(): void
TodoItemInterface::class,
TodoListInterface::class,
];
$module = new MediaQueryModule('sqlite::memory:', dirname(__DIR__) . '/tests/sql', $mediaQueries);
$module = new MediaQueryModule(dirname(__DIR__) . '/tests/sql', $mediaQueries, new AuraSqlModule('sqlite::memory:'));
$this->injector = new Injector($module);
$pdo = $this->injector->getInstance(ExtendedPdoInterface::class);
assert($pdo instanceof ExtendedPdoInterface);
Expand Down

0 comments on commit 601a1a4

Please sign in to comment.