Schema::connection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace jlourenco\support\Database;
2
3
use Illuminate\Support\Facades\Facade;
4
5
class Schema extends Facade
6
{
7
8
    /**
9
     * Get a schema builder instance for a connection.
10
     *
11
     * @param  string  $name
12
     * @return \Illuminate\Database\Schema\Builder
13
     */
14
    public static function connection($name)
15
    {
16
        $connection = static::$app['db']->connection($name);
17
        return static::useCustomGrammar($connection);
18
    }
19
20
    /**
21
     * Get a schema builder.
22
     *
23
     * @return \Illuminate\Database\Schema\Builder
24
     */
25
    protected static function getFacadeAccessor()
26
    {
27
        $connection = static::$app['db']->connection();
28
        return static::useCustomGrammar($connection);
29
    }
30
31
    /**
32
     * Boot system by calling our custom Grammar
33
     *
34
     * @param  object  $connection \Illuminate\Database\Connection
35
     * @return \Illuminate\Database\Schema\Builder
36
     */
37
    protected static function useCustomGrammar($connection)
38
    {
39
        // Only for MySqlGrammar
40
        if (get_class($connection) === 'Illuminate\Database\MySqlConnection') {
41
            $MySqlGrammar = $connection->withTablePrefix(new MySqlGrammar);
42
            $connection->setSchemaGrammar($MySqlGrammar);
43
        }
44
45
        $schema = $connection->getSchemaBuilder();
46
        $schema->blueprintResolver(function($table, $callback) {
47
            return new Blueprint($table, $callback);
48
        });
49
50
        return $schema;
51
    }
52
53
}