1: <?php
2:
3: namespace Mapbender\CoreBundle\Command;
4:
5: use Sensio\Bundle\GeneratorBundle\Generator\Generator;
6:
7: class TemplateGenerator extends Generator {
8: public function create($container, $bundle, $bundleDir, $bundleNamespace, $className, $type) {
9: $files = Array();
10:
11: $classNameLower = strtolower($className);
12:
13:
14: $filesystem = $container->get('filesystem');
15:
16: $files = array(
17: 'class' => sprintf('%s/Template/%s.php', $bundleDir, $className),
18: 'js' => sprintf('%s/Resources/public/mapbender.template.%s.js',
19: $bundleDir, $classNameLower),
20: 'css' => sprintf('%s/Resources/public/mapbender.template.%s.js',
21: $bundleDir, $classNameLower),
22: 'twig' => sprintf('%s/Resources/views/Template/%s.html.twig',
23: $bundleDir, $classNameLower));
24:
25: $exists = array();
26: foreach($files as $type => $file) {
27: if(file_exists($file)) {
28: $exists[] = $file;
29: }
30: }
31: if(count($exists) > 0) {
32: $msg = array();
33: $msg[] = 'The following file(s) exist and would be overwritten. '
34: .'Aborting.';
35: $msg = array_merge($msg, $exists);
36: throw new \RuntimeException($msg);
37: }
38:
39: foreach($files as $type => $file) {
40: $skeletonFile = pathinfo($file, PATHINFO_FILENAME);
41: $this->renderFile(__DIR__ . '/../Resources/skeleton/template',
42: $skeletonFile, array(
43: 'bundleNamespace' => $bundleNamespace,
44: 'className' => $className,
45: 'classNameLower' => $classNameLower,
46: 'bundle' => $bundle));
47: }
48:
49: return $files;
50: }
51: }
52: