Skip to content

Commit

Permalink
Initial 3.0 Component
Browse files Browse the repository at this point in the history
  • Loading branch information
zds-s committed Oct 7, 2024
0 parents commit 4cef8e7
Show file tree
Hide file tree
Showing 22 changed files with 751 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests export-ignore
/.github export-ignore
15 changes: 15 additions & 0 deletions .github/workflows/close-pull-request.yml
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! "
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.lock
.idea
vendor
*.cache
runtime
42 changes: 42 additions & 0 deletions Application.php
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);
}
}
49 changes: 49 additions & 0 deletions Config.php
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);
}
}
}
52 changes: 52 additions & 0 deletions Context.php
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;
}
}
98 changes: 98 additions & 0 deletions Entity/ColumnEntity.php
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;
}
}
25 changes: 25 additions & 0 deletions Entity/GeneratorEntity.php
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;
}
}
58 changes: 58 additions & 0 deletions Entity/TableEntity.php
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;
}
}
Loading

0 comments on commit 4cef8e7

Please sign in to comment.