|
7 | 7 | use Barryvdh\Reflection\DocBlock;
|
8 | 8 | use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
9 | 9 | use Barryvdh\Reflection\DocBlock\Tag;
|
10 |
| -use Exception; |
11 | 10 | use Illuminate\Console\Command;
|
12 | 11 | use Illuminate\Contracts\Container\BindingResolutionException;
|
13 | 12 | use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
@@ -51,7 +50,6 @@ public function __construct(Filesystem $files)
|
51 | 50 |
|
52 | 51 | /**
|
53 | 52 | * @throws BindingResolutionException
|
54 |
| - * @throws \Doctrine\DBAL\Exception |
55 | 53 | * @throws FileNotFoundException
|
56 | 54 | */
|
57 | 55 | public function handle(): void
|
@@ -101,88 +99,23 @@ protected function loadModel(string $model): Model
|
101 | 99 | return $this->laravel->make(config('apiresourcegenerator.models.namespace').'\\'.$model);
|
102 | 100 | }
|
103 | 101 |
|
104 |
| - /** |
105 |
| - * @throws \Doctrine\DBAL\Exception |
106 |
| - */ |
107 | 102 | protected function getPropertiesFromTable(Model $model): void
|
108 | 103 | {
|
109 |
| - /*$table = $model->getConnection()->getTablePrefix().$model->getTable(); |
110 |
| -
|
111 |
| - try { |
112 |
| - // Check if getDoctrineSchemaManager method exists to deal with Laravel 11 upgrade |
113 |
| - if (method_exists($model->getConnection(), 'getDoctrineSchemaManager')) { |
114 |
| - $schema = $model->getConnection()->getDoctrineSchemaManager(); |
115 |
| - } else { |
116 |
| - $schema = $model->getConnection()->getSchemaBuilder(); |
117 |
| - } |
118 |
| - } catch (Exception $exception) { |
119 |
| - $this->error($exception->getMessage()); |
120 |
| -
|
121 |
| - $class = get_class($model); |
122 |
| - $driver = $model->getConnection()->getDriverName(); |
123 |
| -
|
124 |
| - if (in_array($driver, ['mysql', 'pgsql', 'sqlite'])) { |
125 |
| - $this->error("Database driver ({$driver}) for {$class} model is not configured properly!"); |
126 |
| - } else { |
127 |
| - $this->warn("Database driver ({$driver}) for {$class} model is not supported."); |
128 |
| - } |
129 |
| -
|
130 |
| - return; |
131 |
| - } |
132 |
| -
|
133 |
| - $database = null; |
134 |
| -
|
135 |
| - if (Str::contains($table, '.')) { |
136 |
| - [$database, $table] = explode('.', $table); |
137 |
| - } |
138 |
| -
|
139 |
| - // Check if listTableColumns method exists to deal with Laravel 11 upgrade |
140 |
| - if (method_exists($schema, 'listTableColumns')) { |
141 |
| - $columns = $schema->listTableColumns($table, $database); |
142 |
| - } else { |
143 |
| - $columns = $schema->getColumns($table); |
144 |
| - } |
145 |
| -
|
146 |
| - if ( ! $columns) { |
147 |
| - return; |
148 |
| - } |
149 |
| -
|
150 |
| - $this->properties = []; |
151 |
| - $this->php_docs_properties = []; |
152 |
| -
|
153 |
| - foreach ($columns as $column) { |
154 |
| - // Check if $column is an array to deal with Laravel 11 upgrade |
155 |
| - if (is_array($column)) { |
156 |
| - $field = $column['name']; |
157 |
| - $type = $column['type']; |
158 |
| - } else { |
159 |
| - $field = $column->getName(); |
160 |
| - $type = $column->getType()->getName(); |
161 |
| - } |
162 |
| -
|
163 |
| - $field_type = match ($type) { |
164 |
| - 'string', 'text', 'date', 'time', 'guid', 'datetimetz', 'datetime', 'decimal' => 'string', |
165 |
| - 'integer', 'bigint', 'smallint' => 'integer', |
166 |
| - 'boolean' => 'boolean', |
167 |
| - 'float' => 'float', |
168 |
| - default => 'mixed', |
169 |
| - }; |
170 |
| -
|
171 |
| - $this->properties[$field] = $field; |
172 |
| - $this->php_docs_properties[$field] = $field_type.' '.$field; |
173 |
| - }*/ |
174 | 104 | $table = $model->getTable();
|
175 | 105 | $schema = $model->getConnection()->getSchemaBuilder();
|
176 | 106 | $columns = $schema->getColumns($table);
|
177 |
| - $driverName = $model->getConnection()->getDriverName(); |
178 | 107 |
|
179 | 108 |
|
180 | 109 | if (!$columns) {
|
181 | 110 | return;
|
182 | 111 | }
|
183 | 112 |
|
| 113 | + $this->properties = []; |
| 114 | + $this->php_docs_properties = []; |
| 115 | + |
184 | 116 | foreach ($columns as $column) {
|
185 | 117 | $name = $column['name'];
|
| 118 | + |
186 | 119 | if (in_array($name, $model->getDates())) {
|
187 | 120 | $type = 'string';
|
188 | 121 | } else {
|
@@ -282,14 +215,14 @@ protected function generatePHPDocs(): string
|
282 | 215 |
|
283 | 216 | $attr = 'property';
|
284 | 217 |
|
285 |
| - $tagLine = trim("@{$attr} {$type[0]} {$name}"); |
286 |
| - $tag = Tag::createInstance($tagLine, $phpdoc); |
| 218 | + $tag_line = trim("@{$attr} {$type[0]} {$name}"); |
| 219 | + $tag = Tag::createInstance($tag_line, $phpdoc); |
287 | 220 | $phpdoc->appendTag($tag);
|
288 | 221 | }
|
289 | 222 |
|
290 | 223 | $serializer = new DocBlockSerializer();
|
291 |
| - $docComment = $serializer->getDocComment($phpdoc); |
| 224 | + $doc_comment = $serializer->getDocComment($phpdoc); |
292 | 225 |
|
293 |
| - return "{$docComment}"; |
| 226 | + return "{$doc_comment}"; |
294 | 227 | }
|
295 | 228 | }
|
0 commit comments