-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from giagara/main
Fix error in PR #3 and refactoring
- Loading branch information
Showing
10 changed files
with
124 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...esolvers/SchemaRulesResolverInterface.php → ...ontracts/SchemaRulesResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace LaracraftTech\LaravelSchemaRules\Resolvers; | ||
|
||
use LaracraftTech\LaravelSchemaRules\Contracts\SchemaRulesResolverInterface; | ||
use stdClass; | ||
|
||
abstract class BaseSchemaRulesResolver implements SchemaRulesResolverInterface | ||
{ | ||
|
||
private string $table; | ||
private array $columns; | ||
|
||
public function __construct(string $table, array $columns = []) | ||
{ | ||
$this->table = $table; | ||
$this->columns = $columns; | ||
} | ||
|
||
public function generate(): array | ||
{ | ||
$tableColumns = $this->getColumnsDefinitionsFromTable(); | ||
|
||
$skip_columns = config('schema-rules.skip_columns'); | ||
|
||
$tableRules = []; | ||
foreach ($tableColumns as $column) { | ||
$field = $this->getField($column); | ||
|
||
// If specific columns where supplied only process those... | ||
if (! empty($this->columns()) && ! in_array($field, $this->columns())) { | ||
continue; | ||
} | ||
|
||
// If column should be skipped | ||
if (in_array($field, $skip_columns)) { | ||
continue; | ||
} | ||
|
||
// We do not need a rule for auto increments | ||
if ($this->isAutoIncrement($column)) { | ||
continue; | ||
} | ||
|
||
$tableRules[$field] = $this->generateColumnRules($column); | ||
} | ||
|
||
return $tableRules; | ||
} | ||
|
||
protected function table() | ||
{ | ||
return $this->table; | ||
} | ||
|
||
protected function columns() | ||
{ | ||
return $this->columns; | ||
} | ||
|
||
abstract protected function isAutoIncrement($column) : bool; | ||
|
||
abstract protected function getField($column) : string; | ||
|
||
abstract protected function getColumnsDefinitionsFromTable(); | ||
|
||
abstract protected function generateColumnRules(stdClass $column): array; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters