Skip to content

Commit 4cef8e7

Browse files
committed
Initial 3.0 Component
0 parents  commit 4cef8e7

22 files changed

+751
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/tests export-ignore
2+
/.github export-ignore
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Close Pull Request
2+
3+
permissions: write-all
4+
5+
on:
6+
pull_request_target:
7+
types: [ opened ]
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: superbrothers/close-pull-request@v3
14+
with:
15+
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! "

.github/workflows/release.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
push:
3+
tags:
4+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
5+
6+
name: Release
7+
permissions: write-all
8+
9+
jobs:
10+
release:
11+
name: Release
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Create Release
17+
id: create_release
18+
uses: actions/create-release@v1
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
with:
22+
tag_name: ${{ github.ref }}
23+
release_name: Release ${{ github.ref }}
24+
draft: false
25+
prerelease: false

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
composer.lock
2+
.idea
3+
vendor
4+
*.cache
5+
runtime

Application.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud;
14+
15+
use Hyperf\Collection\Collection;
16+
use Mine\GeneratorCrud\Entity\TableEntity;
17+
use Mine\GeneratorCrud\Event\GeneratorStaringEvent;
18+
use Psr\EventDispatcher\EventDispatcherInterface;
19+
20+
final class Application implements GeneratorInterface
21+
{
22+
public function __construct(
23+
private readonly Config $config,
24+
private readonly EventDispatcherInterface $dispatcher
25+
) {}
26+
27+
public function generate(TableEntity $table, array $config = [], array $extra = []): array
28+
{
29+
$context = new Context(Collection::make($config), Collection::empty(), Collection::make($extra), $table, Collection::empty());
30+
$this->dispatch(new GeneratorStaringEvent($context));
31+
foreach ($this->config->getProcessors() as $processor) {
32+
$context->getProcessors()->push($processor);
33+
$context->getEntities()->push($processor->process($context));
34+
}
35+
return $context->getEntities()->all();
36+
}
37+
38+
private function dispatch(object $event): void
39+
{
40+
$this->dispatcher->dispatch($event);
41+
}
42+
}

Config.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud;
14+
15+
use Hyperf\Contract\ConfigInterface;
16+
use Mine\GeneratorCrud\Processor\ProcessorInterface;
17+
use Psr\Container\ContainerExceptionInterface;
18+
use Psr\Container\ContainerInterface;
19+
use Psr\Container\NotFoundExceptionInterface;
20+
21+
final class Config
22+
{
23+
public function __construct(
24+
private readonly ConfigInterface $config,
25+
private readonly ContainerInterface $container
26+
) {}
27+
28+
public function getConfig(): ConfigInterface
29+
{
30+
return $this->config;
31+
}
32+
33+
public function isEnable(): bool
34+
{
35+
return (bool) $this->config->get('generator.enable', false);
36+
}
37+
38+
/**
39+
* @return iterable<ProcessorInterface>
40+
* @throws ContainerExceptionInterface
41+
* @throws NotFoundExceptionInterface
42+
*/
43+
public function getProcessors(): iterable
44+
{
45+
foreach ($this->config->get('generator.processors', []) as $processor) {
46+
yield $this->container->get($processor);
47+
}
48+
}
49+
}

Context.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud;
14+
15+
use Hyperf\Collection\Collection;
16+
use Mine\GeneratorCrud\Entity\TableEntity;
17+
18+
final class Context
19+
{
20+
public function __construct(
21+
private Collection $config,
22+
private Collection $processors,
23+
private Collection $extra,
24+
private TableEntity $table,
25+
private Collection $entities
26+
) {}
27+
28+
public function getConfig(): Collection
29+
{
30+
return $this->config;
31+
}
32+
33+
public function getTable(): TableEntity
34+
{
35+
return $this->table;
36+
}
37+
38+
public function getExtra(): Collection
39+
{
40+
return $this->extra;
41+
}
42+
43+
public function getProcessors(): Collection
44+
{
45+
return $this->processors;
46+
}
47+
48+
public function getEntities(): Collection
49+
{
50+
return $this->entities;
51+
}
52+
}

Entity/ColumnEntity.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud\Entity;
14+
15+
use Mine\GeneratorCrud\Enums\TableColumnType;
16+
17+
final class ColumnEntity
18+
{
19+
public function __construct(
20+
private string $columnName,
21+
private TableColumnType $columnType,
22+
private string $columnComment,
23+
private bool $isNullable,
24+
private bool $isPrimary,
25+
private bool $isUnique,
26+
private bool $isAutoIncrement,
27+
) {}
28+
29+
public function getColumnName(): string
30+
{
31+
return $this->columnName;
32+
}
33+
34+
public function setColumnName(string $columnName): void
35+
{
36+
$this->columnName = $columnName;
37+
}
38+
39+
public function getColumnType(): TableColumnType
40+
{
41+
return $this->columnType;
42+
}
43+
44+
public function setColumnType(TableColumnType $columnType): void
45+
{
46+
$this->columnType = $columnType;
47+
}
48+
49+
public function getColumnComment(): string
50+
{
51+
return $this->columnComment;
52+
}
53+
54+
public function setColumnComment(string $columnComment): void
55+
{
56+
$this->columnComment = $columnComment;
57+
}
58+
59+
public function isNullable(): bool
60+
{
61+
return $this->isNullable;
62+
}
63+
64+
public function setIsNullable(bool $isNullable): void
65+
{
66+
$this->isNullable = $isNullable;
67+
}
68+
69+
public function isPrimary(): bool
70+
{
71+
return $this->isPrimary;
72+
}
73+
74+
public function setIsPrimary(bool $isPrimary): void
75+
{
76+
$this->isPrimary = $isPrimary;
77+
}
78+
79+
public function isUnique(): bool
80+
{
81+
return $this->isUnique;
82+
}
83+
84+
public function setIsUnique(bool $isUnique): void
85+
{
86+
$this->isUnique = $isUnique;
87+
}
88+
89+
public function isAutoIncrement(): bool
90+
{
91+
return $this->isAutoIncrement;
92+
}
93+
94+
public function setIsAutoIncrement(bool $isAutoIncrement): void
95+
{
96+
$this->isAutoIncrement = $isAutoIncrement;
97+
}
98+
}

Entity/GeneratorEntity.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud\Entity;
14+
15+
final class GeneratorEntity
16+
{
17+
public function __construct(
18+
private readonly string $template,
19+
) {}
20+
21+
public function getTemplate(): string
22+
{
23+
return $this->template;
24+
}
25+
}

Entity/TableEntity.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\GeneratorCrud\Entity;
14+
15+
final class TableEntity
16+
{
17+
public function __construct(
18+
private string $tableName,
19+
private string $tableComment,
20+
private array $columns,
21+
) {}
22+
23+
public function getTableName(): string
24+
{
25+
return $this->tableName;
26+
}
27+
28+
public function setTableName(string $tableName): void
29+
{
30+
$this->tableName = $tableName;
31+
}
32+
33+
public function getTableComment(): string
34+
{
35+
return $this->tableComment;
36+
}
37+
38+
public function setTableComment(string $tableComment): void
39+
{
40+
$this->tableComment = $tableComment;
41+
}
42+
43+
/**
44+
* @return ColumnEntity[]
45+
*/
46+
public function getColumns(): array
47+
{
48+
return $this->columns;
49+
}
50+
51+
/**
52+
* @param ColumnEntity[] $columns
53+
*/
54+
public function setColumns(array $columns): void
55+
{
56+
$this->columns = $columns;
57+
}
58+
}

0 commit comments

Comments
 (0)