1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Illuminate\Database\Connection; |
7
|
|
|
use Illuminate\Database\Schema\Builder; |
8
|
|
|
|
9
|
|
|
class OracleBuilder extends Builder |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \Yajra\Oci8\Schema\OracleAutoIncrementHelper |
13
|
|
|
*/ |
14
|
|
|
public $helper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param Connection $connection |
18
|
|
|
*/ |
19
|
|
|
public function __construct(Connection $connection) |
20
|
|
|
{ |
21
|
|
|
$this->connection = $connection; |
22
|
|
|
$this->grammar = $connection->getSchemaGrammar(); |
23
|
|
|
$this->helper = new OracleAutoIncrementHelper($connection); |
24
|
|
|
$this->comment = new Comment($connection); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new table on the schema. |
29
|
|
|
* |
30
|
|
|
* @param string $table |
31
|
|
|
* @param Closure $callback |
32
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
33
|
|
|
*/ |
34
|
|
|
public function create($table, Closure $callback) |
35
|
|
|
{ |
36
|
|
|
$blueprint = $this->createBlueprint($table); |
37
|
|
|
|
38
|
|
|
$blueprint->create(); |
39
|
|
|
|
40
|
|
|
$callback($blueprint); |
41
|
|
|
|
42
|
|
|
$this->build($blueprint); |
43
|
|
|
|
44
|
|
|
$this->comment->setComments($blueprint); |
45
|
|
|
|
46
|
|
|
$this->helper->createAutoIncrementObjects($blueprint, $table); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Changes an existing table on the schema. |
51
|
|
|
* |
52
|
|
|
* @param string $table |
53
|
|
|
* @param Closure $callback |
54
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
55
|
|
|
*/ |
56
|
|
|
public function table($table, Closure $callback) |
57
|
|
|
{ |
58
|
|
|
$blueprint = $this->createBlueprint($table); |
59
|
|
|
|
60
|
|
|
$callback($blueprint); |
61
|
|
|
|
62
|
|
|
$this->build($blueprint); |
63
|
|
|
|
64
|
|
|
$this->comment->setComments($blueprint); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Create a new command set with a Closure. |
69
|
|
|
* |
70
|
|
|
* @param string $table |
71
|
|
|
* @param Closure $callback |
72
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
73
|
|
|
*/ |
74
|
|
|
protected function createBlueprint($table, Closure $callback = null) |
75
|
|
|
{ |
76
|
|
|
$blueprint = new OracleBlueprint($table, $callback); |
77
|
|
|
$blueprint->setTablePrefix($this->connection->getTablePrefix()); |
78
|
|
|
|
79
|
|
|
return $blueprint; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Drop a table from the schema. |
84
|
|
|
* |
85
|
|
|
* @param string $table |
86
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
87
|
|
|
*/ |
88
|
|
|
public function drop($table) |
89
|
|
|
{ |
90
|
|
|
$this->helper->dropAutoIncrementObjects($table); |
91
|
|
|
parent::drop($table); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Indicate that the table should be dropped if it exists. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Support\Fluent |
98
|
|
|
*/ |
99
|
|
|
public function dropIfExists($table) |
100
|
|
|
{ |
101
|
|
|
$this->helper->dropAutoIncrementObjects($table); |
102
|
|
|
parent::dropIfExists($table); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: