-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathControllerGenerator.php
78 lines (66 loc) · 1.57 KB
/
ControllerGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Pingpong\Generators;
use Pingpong\Generators\Scaffolders\ControllerScaffolder;
class ControllerGenerator extends Generator
{
/**
* Get stub name.
*
* @var string
*/
protected $stub = 'controller/plain';
/**
* Configure some data.
*/
public function setUp()
{
if ($this->resource) {
$this->stub = 'controller/resource';
} elseif ($this->scaffold) {
$this->stub = 'controller/scaffold';
$this->scaffolder = new ControllerScaffolder($this->getClass(), $this->getPrefix());
}
}
/**
* Get prefix class.
*
* @return string
*/
public function getPrefix()
{
$paths = explode('/', $this->getName());
array_pop($paths);
return strtolower(implode('\\', $paths));
}
/**
* Get base path of destination file.
*
* @return string
*/
public function getBasePath()
{
return app_path().'/Http/Controllers';
}
/**
* Get root namespace.
*
* @return string
*/
public function getRootNamespace()
{
return $this->getAppNamespace().'Http\\Controllers\\';
}
/**
* Get template replacements.
*
* @return array
*/
public function getReplacements()
{
$replacements = array_merge(parent::getReplacements(), ['root_namespace' => $this->getAppNamespace()]);
if ($this->scaffold) {
return array_merge($replacements, $this->scaffolder->toArray());
}
return $replacements;
}
}