-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
42 lines (36 loc) · 1.3 KB
/
Application.php
File metadata and controls
42 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
/**
* This file is part of MineAdmin.
*
* @link https://www.mineadmin.com
* @document https://doc.mineadmin.com
* @contact root@imoi.cn
* @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);
}
}