-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change to sqlserver driver registration
- Loading branch information
1 parent
c07c42d
commit 4fe6977
Showing
3 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |