Skip to content
Permalink
Browse files

formatting

  • Loading branch information...
taylorotwell committed Apr 17, 2019
1 parent 666cda4 commit 91a6afe1f9f8d18283f3ee9a72b636a121f06da5
@@ -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);
}
}
@@ -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');
}
}
@@ -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');

0 comments on commit 91a6afe

Please sign in to comment.
You can’t perform that action at this time.