-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathMysqlConnection.php
59 lines (52 loc) · 1.73 KB
/
MysqlConnection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Grimzy\LaravelMysqlSpatial;
use Doctrine\DBAL\Types\Type as DoctrineType;
use Grimzy\LaravelMysqlSpatial\Schema\Builder;
use Grimzy\LaravelMysqlSpatial\Schema\Grammars\MySqlGrammar;
use Illuminate\Database\MySqlConnection as IlluminateMySqlConnection;
class MysqlConnection extends IlluminateMySqlConnection
{
public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
{
parent::__construct($pdo, $database, $tablePrefix, $config);
if (class_exists(DoctrineType::class)) {
// Prevent geometry type fields from throwing a 'type not found' error when changing them
$geometries = [
'geometry',
'point',
'linestring',
'polygon',
'multipoint',
'multilinestring',
'multipolygon',
'geometrycollection',
'geomcollection',
];
$dbPlatform = $this->getDoctrineSchemaManager()->getDatabasePlatform();
foreach ($geometries as $type) {
$dbPlatform->registerDoctrineTypeMapping($type, 'string');
}
}
}
/**
* Get the default schema grammar instance.
*
* @return \Illuminate\Database\Grammar
*/
protected function getDefaultSchemaGrammar()
{
return $this->withTablePrefix(new MySqlGrammar());
}
/**
* Get a schema builder instance for the connection.
*
* @return \Illuminate\Database\Schema\MySqlBuilder
*/
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}
return new Builder($this);
}
}