-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4cef8e7
Showing
22 changed files
with
751 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/tests export-ignore | ||
/.github export-ignore |
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,15 @@ | ||
name: Close Pull Request | ||
|
||
permissions: write-all | ||
|
||
on: | ||
pull_request_target: | ||
types: [ opened ] | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: superbrothers/close-pull-request@v3 | ||
with: | ||
comment: "Hi, this is a READ-ONLY repository, please submit your PR on the https://github.com/mineadmin/components repository.<br><br> This Pull Request will close automatically.<br><br> Thanks! " |
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,25 @@ | ||
on: | ||
push: | ||
tags: | ||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
||
name: Release | ||
permissions: write-all | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false |
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,5 @@ | ||
composer.lock | ||
.idea | ||
vendor | ||
*.cache | ||
runtime |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud; | ||
|
||
use Hyperf\Collection\Collection; | ||
use Mine\GeneratorCrud\Entity\TableEntity; | ||
use Mine\GeneratorCrud\Event\GeneratorStaringEvent; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
|
||
final class Application implements GeneratorInterface | ||
{ | ||
public function __construct( | ||
private readonly Config $config, | ||
private readonly EventDispatcherInterface $dispatcher | ||
) {} | ||
|
||
public function generate(TableEntity $table, array $config = [], array $extra = []): array | ||
{ | ||
$context = new Context(Collection::make($config), Collection::empty(), Collection::make($extra), $table, Collection::empty()); | ||
$this->dispatch(new GeneratorStaringEvent($context)); | ||
foreach ($this->config->getProcessors() as $processor) { | ||
$context->getProcessors()->push($processor); | ||
$context->getEntities()->push($processor->process($context)); | ||
} | ||
return $context->getEntities()->all(); | ||
} | ||
|
||
private function dispatch(object $event): void | ||
{ | ||
$this->dispatcher->dispatch($event); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud; | ||
|
||
use Hyperf\Contract\ConfigInterface; | ||
use Mine\GeneratorCrud\Processor\ProcessorInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
|
||
final class Config | ||
{ | ||
public function __construct( | ||
private readonly ConfigInterface $config, | ||
private readonly ContainerInterface $container | ||
) {} | ||
|
||
public function getConfig(): ConfigInterface | ||
{ | ||
return $this->config; | ||
} | ||
|
||
public function isEnable(): bool | ||
{ | ||
return (bool) $this->config->get('generator.enable', false); | ||
} | ||
|
||
/** | ||
* @return iterable<ProcessorInterface> | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function getProcessors(): iterable | ||
{ | ||
foreach ($this->config->get('generator.processors', []) as $processor) { | ||
yield $this->container->get($processor); | ||
} | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud; | ||
|
||
use Hyperf\Collection\Collection; | ||
use Mine\GeneratorCrud\Entity\TableEntity; | ||
|
||
final class Context | ||
{ | ||
public function __construct( | ||
private Collection $config, | ||
private Collection $processors, | ||
private Collection $extra, | ||
private TableEntity $table, | ||
private Collection $entities | ||
) {} | ||
|
||
public function getConfig(): Collection | ||
{ | ||
return $this->config; | ||
} | ||
|
||
public function getTable(): TableEntity | ||
{ | ||
return $this->table; | ||
} | ||
|
||
public function getExtra(): Collection | ||
{ | ||
return $this->extra; | ||
} | ||
|
||
public function getProcessors(): Collection | ||
{ | ||
return $this->processors; | ||
} | ||
|
||
public function getEntities(): Collection | ||
{ | ||
return $this->entities; | ||
} | ||
} |
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,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud\Entity; | ||
|
||
use Mine\GeneratorCrud\Enums\TableColumnType; | ||
|
||
final class ColumnEntity | ||
{ | ||
public function __construct( | ||
private string $columnName, | ||
private TableColumnType $columnType, | ||
private string $columnComment, | ||
private bool $isNullable, | ||
private bool $isPrimary, | ||
private bool $isUnique, | ||
private bool $isAutoIncrement, | ||
) {} | ||
|
||
public function getColumnName(): string | ||
{ | ||
return $this->columnName; | ||
} | ||
|
||
public function setColumnName(string $columnName): void | ||
{ | ||
$this->columnName = $columnName; | ||
} | ||
|
||
public function getColumnType(): TableColumnType | ||
{ | ||
return $this->columnType; | ||
} | ||
|
||
public function setColumnType(TableColumnType $columnType): void | ||
{ | ||
$this->columnType = $columnType; | ||
} | ||
|
||
public function getColumnComment(): string | ||
{ | ||
return $this->columnComment; | ||
} | ||
|
||
public function setColumnComment(string $columnComment): void | ||
{ | ||
$this->columnComment = $columnComment; | ||
} | ||
|
||
public function isNullable(): bool | ||
{ | ||
return $this->isNullable; | ||
} | ||
|
||
public function setIsNullable(bool $isNullable): void | ||
{ | ||
$this->isNullable = $isNullable; | ||
} | ||
|
||
public function isPrimary(): bool | ||
{ | ||
return $this->isPrimary; | ||
} | ||
|
||
public function setIsPrimary(bool $isPrimary): void | ||
{ | ||
$this->isPrimary = $isPrimary; | ||
} | ||
|
||
public function isUnique(): bool | ||
{ | ||
return $this->isUnique; | ||
} | ||
|
||
public function setIsUnique(bool $isUnique): void | ||
{ | ||
$this->isUnique = $isUnique; | ||
} | ||
|
||
public function isAutoIncrement(): bool | ||
{ | ||
return $this->isAutoIncrement; | ||
} | ||
|
||
public function setIsAutoIncrement(bool $isAutoIncrement): void | ||
{ | ||
$this->isAutoIncrement = $isAutoIncrement; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud\Entity; | ||
|
||
final class GeneratorEntity | ||
{ | ||
public function __construct( | ||
private readonly string $template, | ||
) {} | ||
|
||
public function getTemplate(): string | ||
{ | ||
return $this->template; | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Mine\GeneratorCrud\Entity; | ||
|
||
final class TableEntity | ||
{ | ||
public function __construct( | ||
private string $tableName, | ||
private string $tableComment, | ||
private array $columns, | ||
) {} | ||
|
||
public function getTableName(): string | ||
{ | ||
return $this->tableName; | ||
} | ||
|
||
public function setTableName(string $tableName): void | ||
{ | ||
$this->tableName = $tableName; | ||
} | ||
|
||
public function getTableComment(): string | ||
{ | ||
return $this->tableComment; | ||
} | ||
|
||
public function setTableComment(string $tableComment): void | ||
{ | ||
$this->tableComment = $tableComment; | ||
} | ||
|
||
/** | ||
* @return ColumnEntity[] | ||
*/ | ||
public function getColumns(): array | ||
{ | ||
return $this->columns; | ||
} | ||
|
||
/** | ||
* @param ColumnEntity[] $columns | ||
*/ | ||
public function setColumns(array $columns): void | ||
{ | ||
$this->columns = $columns; | ||
} | ||
} |
Oops, something went wrong.