-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4081 from morozov/issues/4069
Simplify Driver::connect() signature
- Loading branch information
Showing
30 changed files
with
410 additions
and
265 deletions.
There are no files selected for viewing
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
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
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
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
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli\Exception; | ||
|
||
use Doctrine\DBAL\Driver\Mysqli\MysqliException; | ||
use mysqli; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @psalm-immutable | ||
*/ | ||
final class InvalidCharset extends MysqliException | ||
{ | ||
public static function fromCharset(mysqli $connection, string $charset): self | ||
{ | ||
return new self( | ||
sprintf('Failed to set charset "%s": %s', $charset, $connection->error), | ||
$connection->sqlstate, | ||
$connection->errno | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli\Exception; | ||
|
||
use Doctrine\DBAL\Driver\Mysqli\MysqliException; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @psalm-immutable | ||
*/ | ||
final class InvalidOption extends MysqliException | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public static function fromOption(int $option, $value): self | ||
{ | ||
return new self( | ||
sprintf('Failed to set option %d with value "%s"', $option, $value) | ||
); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli; | ||
|
||
use mysqli; | ||
|
||
interface Initializer | ||
{ | ||
/** | ||
* @throws MysqliException | ||
*/ | ||
public function initialize(mysqli $connection): void; | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
|
||
use Doctrine\DBAL\Driver\Mysqli\Exception\InvalidCharset; | ||
use Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
use mysqli; | ||
|
||
final class Charset implements Initializer | ||
{ | ||
/** @var string */ | ||
private $charset; | ||
|
||
public function __construct(string $charset) | ||
{ | ||
$this->charset = $charset; | ||
} | ||
|
||
public function initialize(mysqli $connection): void | ||
{ | ||
if ($connection->set_charset($this->charset)) { | ||
return; | ||
} | ||
|
||
throw InvalidCharset::fromCharset($connection, $this->charset); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
|
||
use Doctrine\DBAL\Driver\Mysqli\Exception\InvalidOption; | ||
use Doctrine\DBAL\Driver\Mysqli\Initializer; | ||
use mysqli; | ||
|
||
use function mysqli_options; | ||
|
||
final class Options implements Initializer | ||
{ | ||
/** @var array<int,mixed> */ | ||
private $options; | ||
|
||
/** | ||
* @param array<int,mixed> $options | ||
*/ | ||
public function __construct(array $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
public function initialize(mysqli $connection): void | ||
{ | ||
foreach ($this->options as $option => $value) { | ||
if (! mysqli_options($connection, $option, $value)) { | ||
throw InvalidOption::fromOption($option, $value); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.