|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Blast Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
|
7
|
|
|
* |
|
8
|
|
|
* This file is licenced under the GNU LGPL v3. |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Blast\Bundle\CoreBundle\Generator; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
16
|
|
|
use Sonata\AdminBundle\Generator\ControllerGenerator as BaseControllerGenerator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class ControllerGenerator. |
|
20
|
|
|
*/ |
|
21
|
|
|
class ControllerGenerator extends BaseControllerGenerator |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string|null |
|
25
|
|
|
*/ |
|
26
|
|
|
private $class; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string|null |
|
30
|
|
|
*/ |
|
31
|
|
|
private $file; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param array|string $skeletonDirectory |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct($skeletonDirectory) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->setSkeletonDirs($skeletonDirectory); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param BundleInterface $bundle |
|
43
|
|
|
* @param string $controllerClassBasename |
|
44
|
|
|
* |
|
45
|
|
|
* @throws \RuntimeException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function generate(BundleInterface $bundle, $controllerClassBasename) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->class = sprintf('%s\Controller\%s', $bundle->getNamespace(), $controllerClassBasename); |
|
50
|
|
|
$this->file = sprintf( |
|
51
|
|
|
'%s/Controller/%s.php', |
|
52
|
|
|
$bundle->getPath(), |
|
53
|
|
|
str_replace('\\', '/', $controllerClassBasename) |
|
54
|
|
|
); |
|
55
|
|
|
$parts = explode('\\', $this->class); |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
if (file_exists($this->file)) { |
|
|
|
|
|
|
58
|
|
|
throw new \RuntimeException(sprintf( |
|
59
|
|
|
'Unable to generate the admin controller class "%s". The file "%s" already exists.', |
|
60
|
|
|
$this->class, |
|
61
|
|
|
realpath($this->file) |
|
62
|
|
|
)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->renderFile('AdminController.php.twig', $this->file, array( |
|
66
|
|
|
'classBasename' => array_pop($parts), |
|
67
|
|
|
'namespace' => implode('\\', $parts), |
|
68
|
|
|
)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string|null |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getClass() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->class; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string|null |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getFile() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->file; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|