Skip to content

Commit

Permalink
refactor: change to sqlserver driver registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chance-fyi committed Aug 28, 2024
1 parent c07c42d commit 4fe6977
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
37 changes: 0 additions & 37 deletions src/Aspect/SqlServerAspect.php

This file was deleted.

10 changes: 7 additions & 3 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace Chance\Hyperf\Database\Sqlsrv;

use Chance\Hyperf\Database\Sqlsrv\Aspect\SqlServerAspect;
use Chance\Hyperf\Database\Sqlsrv\Connectors\SqlServerConnector;
use Chance\Hyperf\Database\Sqlsrv\Listener\RegisterConnectionListener;

class ConfigProvider
{
Expand All @@ -18,8 +19,11 @@ public function __invoke(): array
],
],
],
'aspects' => [
SqlServerAspect::class,
'dependencies' => [
'db.connector.sqlsrv' => SqlServerConnector::class,
],
'listeners' => [
RegisterConnectionListener::class,
],
];
}
Expand Down
34 changes: 34 additions & 0 deletions src/Listener/RegisterConnectionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Chance\Hyperf\Database\Sqlsrv\Listener;

use Chance\Hyperf\Database\Sqlsrv\SqlServerConnection;
use Hyperf\Database\Connection;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
use Psr\Container\ContainerInterface;

class RegisterConnectionListener implements ListenerInterface
{
/**
* Create a new connection factory instance.
*/
public function __construct(protected ContainerInterface $container) {}

public function listen(): array
{
return [
BootApplication::class,
];
}

/**
* register sqlserver need Connector and Connection.
*/
public function process(object $event): void
{
Connection::resolverFor('sqlsrv', static function ($connection, $database, $prefix, $config) {
return new SqlServerConnection($connection, $database, $prefix, $config);
});
}
}

0 comments on commit 4fe6977

Please sign in to comment.