1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: thalesmartins |
5
|
|
|
* Date: 11/12/2018 |
6
|
|
|
* Time: 18:34 |
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\ServiceProvider; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
15
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
16
|
|
|
|
17
|
|
|
class ClassServiceProviderMakerSubscriber implements \Saci\Console\Domain\Services\ClassServiceProviderMakerSubscriber, 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
|
1 |
|
public static function getSubscribedEvents() |
39
|
|
|
{ |
40
|
1 |
|
return [ModuleWasCreated::NAME => 'create']; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function create(ModuleWasCreated $created) |
44
|
|
|
{ |
45
|
1 |
|
$classMaker = new ClassMaker($created->getModule()); |
46
|
1 |
|
$generateable = $classMaker->generate(new ServiceProvider()); |
47
|
1 |
|
$stringClass = GeneratorClassFactory::create()->generate($generateable); |
48
|
|
|
|
49
|
1 |
|
$stringClass = "<?php\n" . $stringClass; |
50
|
|
|
|
51
|
1 |
|
(new Filesystem())->dumpFile($created->getModule()->getPathModule() . DIRECTORY_SEPARATOR . "{$created->getModule()->getName()}ServiceProvider.php", $stringClass); |
52
|
|
|
|
53
|
1 |
|
return true; |
54
|
|
|
} |
55
|
|
|
} |