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: $this->commentTable($blueprint);
34:
35: $this->fluentComments($blueprint);
36:
37: $this->commentColumns($blueprint);
38: }
39:
40: 41: 42: 43: 44: 45:
46: private function commentTable(OracleBlueprint $blueprint)
47: {
48: $table = $this->wrapValue($blueprint->getTable());
49:
50: if ($blueprint->comment != null) {
51: $this->connection->statement("comment on table {$table} is '{$blueprint->comment}'");
52: }
53: }
54:
55: 56: 57: 58: 59: 60:
61: protected function wrapValue($value)
62: {
63: return $this->isReserved($value) ? parent::wrapValue($value) : $value;
64: }
65:
66: 67: 68: 69: 70: 71:
72: private function fluentComments(OracleBlueprint $blueprint)
73: {
74: foreach ($blueprint->getColumns() as $column) {
75: if (isset($column['comment'])) {
76: $this->commentColumn($blueprint->getTable(), $column['name'], $column['comment']);
77: }
78: }
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: private function commentColumn($table, $column, $comment)
89: {
90: $table = $this->wrapValue($table);
91:
92: $column = $this->wrapValue($column);
93:
94: $this->connection->statement("comment on column {$table}.{$column} is '{$comment}'");
95: }
96:
97: 98: 99: 100: 101: 102:
103: private function commentColumns(OracleBlueprint $blueprint)
104: {
105: foreach ($blueprint->commentColumns as $column => $comment) {
106: $this->commentColumn($blueprint->getTable(), $column, $comment);
107: }
108: }
109: }
110: