1: <?php
2:
3: namespace Yajra\Oci8\Schema;
4:
5: use Illuminate\Database\Connection;
6: use Illuminate\Database\Schema\Grammars\Grammar;
7: use Yajra\Oci8\OracleReservedWords;
8:
9: class Comment extends Grammar
10: {
11: use OracleReservedWords;
12:
13: 14: 15:
16: protected $connection;
17:
18: 19: 20:
21: public function __construct(Connection $connection)
22: {
23: $this->connection = $connection;
24: }
25:
26: 27: 28: 29: 30:
31: public function setComments(OracleBlueprint $blueprint)
32: {
33:
34: $this->commentTable($blueprint);
35:
36:
37: $this->fluentComments($blueprint);
38:
39:
40: $this->commentColumns($blueprint);
41: }
42:
43: 44: 45: 46: 47:
48: private function commentTable(OracleBlueprint $blueprint)
49: {
50: $table = $this->wrapValue($blueprint->getTable());
51:
52: if ($blueprint->comment != null) {
53: $this->connection->statement("comment on table {$table} is '{$blueprint->comment}'");
54: }
55: }
56:
57: 58: 59: 60: 61:
62: private function fluentComments(OracleBlueprint $blueprint)
63: {
64: foreach ($blueprint->getColumns() as $column) {
65: if (isset($column['comment'])) {
66: $this->commentColumn($blueprint->getTable(), $column['name'], $column['comment']);
67: }
68: }
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: private function commentColumn($table, $column, $comment)
79: {
80: $table = $this->wrapValue($table);
81:
82: $column = $this->wrapValue($column);
83:
84: $this->connection->statement("comment on column {$table}.{$column} is '{$comment}'");
85: }
86:
87: 88: 89: 90: 91:
92: private function commentColumns(OracleBlueprint $blueprint)
93: {
94: foreach ($blueprint->commentColumns as $column => $comment) {
95: $this->commentColumn($blueprint->getTable(), $column, $comment);
96: }
97: }
98:
99: 100: 101: 102: 103: 104:
105: protected function wrapValue($value)
106: {
107: return $this->isReserved($value) ? parent::wrapValue($value) : $value;
108: }
109: }
110: