Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 17, 2019
1 parent 666cda4 commit 91a6afe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
48 changes: 24 additions & 24 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
18 changes: 10 additions & 8 deletions src/Illuminate/Database/Schema/MySqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions tests/Integration/Database/SchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 91a6afe

Please sign in to comment.