|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: thalesmartins |
|
5
|
|
|
* Date: 11/12/2018 |
|
6
|
|
|
* Time: 18:14 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Saci\Console\Infrastructure\Domain\Services; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Saci\Console\Domain\Events\ModuleWasCreated; |
|
13
|
|
|
use Saci\Console\Infrastructure\Domain\Services\PhpClass\Mapping; |
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
15
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
16
|
|
|
|
|
17
|
|
|
class ClassMappingMakerSubscriber implements \Saci\Console\Domain\Services\ClassMappingMakerSubscriber, EventSubscriberInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Returns an array of event names this subscriber wants to listen to. |
|
22
|
|
|
* |
|
23
|
|
|
* The array keys are event names and the value can be: |
|
24
|
|
|
* |
|
25
|
|
|
* * The method name to call (priority defaults to 0) |
|
26
|
|
|
* * An array composed of the method name to call and the priority |
|
27
|
|
|
* * An array of arrays composed of the method names to call and respective |
|
28
|
|
|
* priorities, or 0 if unset |
|
29
|
|
|
* |
|
30
|
|
|
* For instance: |
|
31
|
|
|
* |
|
32
|
|
|
* * array('eventName' => 'methodName') |
|
33
|
|
|
* * array('eventName' => array('methodName', $priority)) |
|
34
|
|
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))) |
|
35
|
|
|
* |
|
36
|
|
|
* @return array The event names to listen to |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function getSubscribedEvents() |
|
39
|
|
|
{ |
|
40
|
|
|
return [ModuleWasCreated::NAME => 'create']; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function create(ModuleWasCreated $created) |
|
44
|
|
|
{ |
|
45
|
|
|
$classMaker = new ClassMaker($created->getModule()); |
|
46
|
|
|
$generateable = $classMaker->generate(new Mapping()); |
|
47
|
|
|
$stringClass = GeneratorClassFactory::create()->generate($generateable); |
|
48
|
|
|
|
|
49
|
|
|
$stringClass = "<?php\n" . $stringClass; |
|
50
|
|
|
|
|
51
|
|
|
(new Filesystem())->dumpFile($created->getModule()->getPathModule() . DIRECTORY_SEPARATOR . 'Mapping.php', $stringClass); |
|
52
|
|
|
|
|
53
|
|
|
return true; |
|
54
|
|
|
} |
|
55
|
|
|
} |