From 69e00e59b945150a82c79aa244ff689222f23cab Mon Sep 17 00:00:00 2001 From: Korben Dallas Date: Sat, 2 Jan 2021 20:55:26 +0300 Subject: [PATCH] Auto register supportes types (#53) - tsrange - numeric --- src/PostgresConnection.php | 17 +++++++++++++++++ src/Schema/Types/NumericType.php | 23 +++++++++++++++++++++++ src/Schema/Types/TsRangeType.php | 23 +++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/Schema/Types/NumericType.php create mode 100644 src/Schema/Types/TsRangeType.php diff --git a/src/PostgresConnection.php b/src/PostgresConnection.php index 472e622..96ade14 100644 --- a/src/PostgresConnection.php +++ b/src/PostgresConnection.php @@ -15,6 +15,8 @@ use Umbrellio\Postgres\Schema\Builder; use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar; use Umbrellio\Postgres\Schema\Subscribers\SchemaAlterTableChangeColumnSubscriber; +use Umbrellio\Postgres\Schema\Types\NumericType; +use Umbrellio\Postgres\Schema\Types\TsRangeType; class PostgresConnection extends BasePostgresConnection { @@ -22,6 +24,11 @@ class PostgresConnection extends BasePostgresConnection private static $extensions = []; + private $initialTypes = [ + TsRangeType::TYPE_NAME => TsRangeType::class, + NumericType::TYPE_NAME => NumericType::class, + ]; + /** * @param AbstractExtension|string $extension * @throws ExtensionInvalidException @@ -52,6 +59,7 @@ public function useDefaultPostProcessor(): void parent::useDefaultPostProcessor(); $this->registerExtensions(); + $this->registerInitialTypes(); } public function getDoctrineConnection(): Connection @@ -109,6 +117,15 @@ protected function getDefaultSchemaGrammar() return $this->withTablePrefix(new PostgresGrammar()); } + private function registerInitialTypes(): void + { + foreach ($this->initialTypes as $type => $typeClass) { + $this + ->getSchemaBuilder() + ->registerCustomDoctrineType($typeClass, $type, $type); + } + } + /** * @codeCoverageIgnore */ diff --git a/src/Schema/Types/NumericType.php b/src/Schema/Types/NumericType.php new file mode 100644 index 0000000..ee5e9fc --- /dev/null +++ b/src/Schema/Types/NumericType.php @@ -0,0 +1,23 @@ +