Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove $db property from constructor #368

Merged
merged 24 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f32d7ac
Remove `$tableName` property from constructor
Tigrov Jun 25, 2024
207a53c
Apply fixes from StyleCI
StyleCIBot Jun 25, 2024
2e04d0f
Add comments to trait [skip ci]
Tigrov Jun 25, 2024
825a647
Add parameter type
Tigrov Jun 27, 2024
338d484
Remove `$db` property from constructor
Tigrov Jun 27, 2024
130337a
Update tests
Tigrov Jun 27, 2024
85764f7
Add `ConnectionProvider::isset()` method
Tigrov Jun 27, 2024
0c17288
Remove `$db` from `ActiveQuery` constructor
Tigrov Jun 27, 2024
d1f11d7
Remove `ActiveRecordFactory`
Tigrov Jun 28, 2024
ede81de
Add middleware and update README
Tigrov Jun 28, 2024
0216f59
Merge branch 'refs/heads/remove-tableName-property' into remove-db-pr…
Tigrov Jun 28, 2024
bad1290
Apply fixes from StyleCI
StyleCIBot Jun 28, 2024
20da8ba
Fix psalm issues
Tigrov Jun 28, 2024
74b7f72
Merge remote-tracking branch 'origin/remove-db-property' into remove-…
Tigrov Jun 28, 2024
de5a50a
Remove `yiisoft/factory` from composer
Tigrov Jun 28, 2024
94794c0
Fix psalm issues
Tigrov Jun 28, 2024
11494ee
Apply suggestions from code review [skip ci]
Tigrov Jul 1, 2024
270dab4
Merge branch 'refs/heads/master' into remove-db-property
Tigrov Jul 1, 2024
0bcbcc6
Update after merge
Tigrov Jul 1, 2024
cadcd07
Apply fixes from StyleCI
StyleCIBot Jul 1, 2024
1796d71
Add soc about config for middleware
Tigrov Jul 1, 2024
8c88e55
Add `ConnectionProvider` tests
Tigrov Jul 2, 2024
e5ff769
Add suggestions to composer.json
Tigrov Jul 2, 2024
6afc4eb
Configure `composer-require-checker`
Tigrov Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add soc about config for middleware
Tigrov committed Jul 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1796d71ce0b1eba45a66ef809b8bc546fa0f62fc
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -143,6 +143,21 @@ Route::methods([Method::GET, Method::POST], '/user/register')
->name('user/register');
```

Or, if you use `yiisoft/config` and `yiisoft/middleware-dispatcher` packages, add the middleware to the configuration,
for example in `config/common/params.php` file:

```php
use Yiisoft\ActiveRecord\ConnectionProviderMiddleware;

return [
'middlewares' => [
ConnectionProviderMiddleware::class,
],
];
```

_For more information about how to configure middleware, follow [Middleware Documentation](https://github.com/yiisoft/docs/blob/master/guide/en/structure/middleware.md)_

Now you can use the Active Record in the action:

```php

Unchanged files with check annotations Beta

*
* @return ConnectionInterface[]
*/
public static function all(): array

Check warning on line 24 in src/ConnectionProvider.php

Codecov / codecov/patch

src/ConnectionProvider.php#L24

Added line #L24 was not covered by tests
{
return self::$connections;

Check warning on line 26 in src/ConnectionProvider.php

Codecov / codecov/patch

src/ConnectionProvider.php#L26

Added line #L26 was not covered by tests
}
/**
/**
* Checks if a connection with the given name exists.
*/
public static function has(string $name = self::DEFAULT): bool

Check warning on line 40 in src/ConnectionProvider.php

Codecov / codecov/patch

src/ConnectionProvider.php#L40

Added line #L40 was not covered by tests
{
return isset(self::$connections[$name]);

Check warning on line 42 in src/ConnectionProvider.php

Codecov / codecov/patch

src/ConnectionProvider.php#L42

Added line #L42 was not covered by tests
}
/**
class ConnectionProviderMiddleware implements MiddlewareInterface
{
public function __construct(private readonly ConnectionInterface $db)

Check warning on line 15 in src/ConnectionProviderMiddleware.php

Codecov / codecov/patch

src/ConnectionProviderMiddleware.php#L15

Added line #L15 was not covered by tests
{
}

Check warning on line 17 in src/ConnectionProviderMiddleware.php

Codecov / codecov/patch

src/ConnectionProviderMiddleware.php#L17

Added line #L17 was not covered by tests
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

Check warning on line 19 in src/ConnectionProviderMiddleware.php

Codecov / codecov/patch

src/ConnectionProviderMiddleware.php#L19

Added line #L19 was not covered by tests
{
ConnectionProvider::set($this->db);

Check warning on line 21 in src/ConnectionProviderMiddleware.php

Codecov / codecov/patch

src/ConnectionProviderMiddleware.php#L21

Added line #L21 was not covered by tests
return $handler->handle($request);

Check warning on line 23 in src/ConnectionProviderMiddleware.php

Codecov / codecov/patch

src/ConnectionProviderMiddleware.php#L23

Added line #L23 was not covered by tests
}
}