diff --git a/src/Illuminate/Database/Schema/Builder.php b/src/Illuminate/Database/Schema/Builder.php index 86d09741da03..d80f375b7ac0 100755 --- a/src/Illuminate/Database/Schema/Builder.php +++ b/src/Illuminate/Database/Schema/Builder.php @@ -285,6 +285,30 @@ protected function createBlueprint($table, Closure $callback = null) return new Blueprint($table, $callback, $prefix); } + /** + * Register a custom Doctrine mapping type. + * + * @param string $class + * @param string $name + * @param string $type + * @return void + * + * @throws \Doctrine\DBAL\DBALException + */ + public function registerCustomDoctrineType($class, $name, $type) + { + if (Type::hasType($name)) { + return; + } + + Type::addType($name, $class); + + $this->connection + ->getDoctrineSchemaManager() + ->getDatabasePlatform() + ->registerDoctrineTypeMapping($type, $name); + } + /** * Get the database connection instance. * @@ -318,28 +342,4 @@ public function blueprintResolver(Closure $resolver) { $this->resolver = $resolver; } - - /** - * Register your own Doctrine mapping type. - * - * @param string $class - * @param string $name - * @param string $type - * @return void - * - * @throws \Doctrine\DBAL\DBALException - */ - public function registerCustomDBALType($class, $name, $type) - { - if (Type::hasType($name)) { - return; - } - - Type::addType($name, $class); - - $this->connection - ->getDoctrineSchemaManager() - ->getDatabasePlatform() - ->registerDoctrineTypeMapping($type, $name); - } } diff --git a/src/Illuminate/Database/Schema/MySqlBuilder.php b/src/Illuminate/Database/Schema/MySqlBuilder.php index 2d1290bab1d1..bdd64d680c8b 100755 --- a/src/Illuminate/Database/Schema/MySqlBuilder.php +++ b/src/Illuminate/Database/Schema/MySqlBuilder.php @@ -8,16 +8,18 @@ class MySqlBuilder extends Builder { /** - * MySqlBuilder constructor. + * Create a new builder instance. * * @param \Illuminate\Database\Connection $connection + * @return void + * * @throws \Doctrine\DBAL\DBALException */ public function __construct(Connection $connection) { parent::__construct($connection); - $this->registerCustomDBALTypes(); + $this->registerCustomDoctrineTypes(); } /** @@ -129,18 +131,18 @@ protected function getAllViews() } /** - * Register custom DBAL types for the MySQL builder. + * Register the custom Doctrine mapping types for the MySQL builder. * * @return void * * @throws \Doctrine\DBAL\DBALException */ - private function registerCustomDBALTypes() + protected function registerCustomDoctrineTypes() { - if (! $this->connection->isDoctrineAvailable()) { - return; + if ($this->connection->isDoctrineAvailable()) { + $this->registerCustomDoctrineType( + TinyInteger::class, TinyInteger::NAME, 'TINYINT' + ); } - - $this->registerCustomDBALType(TinyInteger::class, TinyInteger::NAME, 'TINYINT'); } } diff --git a/tests/Integration/Database/SchemaBuilderTest.php b/tests/Integration/Database/SchemaBuilderTest.php index df790b6d2e14..6eea5f94e9de 100644 --- a/tests/Integration/Database/SchemaBuilderTest.php +++ b/tests/Integration/Database/SchemaBuilderTest.php @@ -41,9 +41,9 @@ public function test_drop_all_views() $this->assertTrue(true); } - public function test_register_custom_DBAL_type() + public function test_register_custom_doctrine_type() { - Schema::registerCustomDBALType(TinyInteger::class, TinyInteger::NAME, 'TINYINT'); + Schema::registerCustomDoctrineType(TinyInteger::class, TinyInteger::NAME, 'TINYINT'); Schema::create('test', function (Blueprint $table) { $table->string('test_column');