|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use Sensio\Bundle\GeneratorBundle\Generator\Generator; |
|
6
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Generates a Notification inside a bundle. |
|
11
|
|
|
*/ |
|
12
|
|
|
class DatabaseNotificationGenerator extends Generator |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var Filesystem */ |
|
15
|
|
|
private $filesystem; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(Filesystem $filesystem) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->filesystem = $filesystem; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param BundleInterface $bundle |
|
24
|
|
|
* @param $entityName |
|
25
|
|
|
*/ |
|
26
|
|
|
public function generate(BundleInterface $bundle, $entityName) |
|
27
|
|
|
{ |
|
28
|
|
|
$bundleDir = $bundle->getPath(); |
|
29
|
|
|
$notificationDir = $bundleDir . '/Entity'; |
|
30
|
|
|
self::mkdir($notificationDir); |
|
31
|
|
|
|
|
32
|
|
|
$notificationFile = $notificationDir . '/' . $entityName . '.php'; |
|
33
|
|
|
|
|
34
|
|
|
// Check that each file does not already exist |
|
35
|
|
|
if ($this->filesystem->exists($notificationFile)) { |
|
36
|
|
|
throw new \RuntimeException(sprintf('"%s" already exists', $notificationFile)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$parameters = [ |
|
40
|
|
|
'namespace' => $bundle->getNamespace(), |
|
41
|
|
|
'class_name' => $entityName, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
// Set generator to look in correct directory for notifications template. |
|
45
|
|
|
$path = __DIR__ . '/../Resources/skeleton'; |
|
46
|
|
|
$this->setSkeletonDirs([$path]); |
|
47
|
|
|
|
|
48
|
|
|
// Template, destination, params |
|
49
|
|
|
$this->renderFile('notification/DatabaseNotification.php.twig', $notificationFile, $parameters); |
|
50
|
|
|
} |
|
51
|
|
|
} |