1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Maker; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\MakerBundle\ConsoleStyle; |
6
|
|
|
use Symfony\Bundle\MakerBundle\DependencyBuilder; |
7
|
|
|
use Symfony\Bundle\MakerBundle\Generator; |
8
|
|
|
use Symfony\Bundle\MakerBundle\InputConfiguration; |
9
|
|
|
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; |
10
|
|
|
use Symfony\Bundle\MakerBundle\MakerInterface; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class NotificationMaker extends AbstractMaker |
17
|
|
|
{ |
18
|
|
|
private $channels; |
19
|
|
|
private $channelTemplates = []; |
20
|
|
|
|
21
|
|
|
public function setEnabledChannels(array $channels) |
22
|
|
|
{ |
23
|
|
|
$this->channels = $channels; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function getCommandName(): string |
27
|
|
|
{ |
28
|
|
|
return 'make:notification'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public function configureCommand(Command $command, InputConfiguration $inputConf) |
33
|
|
|
{ |
34
|
|
|
$command |
35
|
|
|
->setDescription('Creates a new notification class') |
36
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'The name of the notification class (e.g. <fg=yellow>NewUserNotification</>)') |
37
|
|
|
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeNotification.txt')) |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
// Create The notification class |
44
|
|
|
// ask if create twig templates perhaps?? |
45
|
|
|
// Use the configured channels to determine which channels to include in the class, or... |
46
|
|
|
// ..ask user which of the enabled channels to use for the notification... |
47
|
|
|
|
48
|
|
|
// Broadcasts could be to a mailing list also |
49
|
|
|
// Broadcasts are for notifications to places that are not notifiables.. |
50
|
|
|
// eg mailing lists, mercure, push notifications etc etc |
51
|
|
|
|
52
|
|
|
$voterClassNameDetails = $generator->createClassNameDetails( |
53
|
|
|
$input->getArgument('name'), |
54
|
|
|
'Notification\\', |
55
|
|
|
'Notification' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$generator->generateClass( |
59
|
|
|
$voterClassNameDetails->getFullName(), |
60
|
|
|
__DIR__.'/../Resources/skeleton/notification/Notification.tpl.php', |
61
|
|
|
[] |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$generator->writeChanges(); |
65
|
|
|
|
66
|
|
|
$this->writeSuccessMessage($io); |
67
|
|
|
|
68
|
|
|
$io->text([ |
69
|
|
|
'Next: Open your notification and add your logic.' |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function configureDependencies(DependencyBuilder $dependencies) |
74
|
|
|
{ |
75
|
|
|
// $dependencies->addClassDependency( |
76
|
|
|
// Voter::class, |
77
|
|
|
// 'security' |
78
|
|
|
// ); |
79
|
|
|
} |
80
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.