@@ 9-86 (lines=78) @@ | ||
6 | use Consigliere\Components\Traits\ComponentCommandTrait; |
|
7 | use Symfony\Component\Console\Input\InputArgument; |
|
8 | ||
9 | class GenerateMailCommand extends Command |
|
10 | { |
|
11 | use ComponentCommandTrait; |
|
12 | ||
13 | /** |
|
14 | * The console command name. |
|
15 | * |
|
16 | * @var string |
|
17 | */ |
|
18 | protected $name = 'component:make-mail'; |
|
19 | ||
20 | /** |
|
21 | * The console command description. |
|
22 | * |
|
23 | * @var string |
|
24 | */ |
|
25 | protected $description = 'Generate a new Mailable Class for the specified component'; |
|
26 | ||
27 | protected $argumentName = 'name'; |
|
28 | ||
29 | /** |
|
30 | * Get the console command arguments. |
|
31 | * |
|
32 | * @return array |
|
33 | */ |
|
34 | protected function getArguments() |
|
35 | { |
|
36 | return [ |
|
37 | ['name', InputArgument::REQUIRED, 'The name of the mailable.'], |
|
38 | ['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
39 | ]; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * Get template contents. |
|
44 | * |
|
45 | * @return string |
|
46 | */ |
|
47 | protected function getTemplateContents() |
|
48 | { |
|
49 | $component = $this->laravel['components']->findOrFail($this->getComponentName()); |
|
50 | ||
51 | return (new Stub('/mail.stub', [ |
|
52 | 'NAMESPACE' => $this->getClassNamespace($component), |
|
53 | 'CLASS' => $this->getClass(), |
|
54 | ]))->render(); |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * Get the destination file path. |
|
59 | * |
|
60 | * @return string |
|
61 | */ |
|
62 | protected function getDestinationFilePath() |
|
63 | { |
|
64 | $path = $this->laravel['components']->getComponentPath($this->getComponentName()); |
|
65 | ||
66 | $mailPath = $this->laravel['components']->config('paths.generator.emails', 'Emails'); |
|
67 | ||
68 | return $path . $mailPath . '/' . $this->getFileName() . '.php'; |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * @return string |
|
73 | */ |
|
74 | private function getFileName() |
|
75 | { |
|
76 | return studly_case($this->argument('name')); |
|
77 | } |
|
78 | ||
79 | /** |
|
80 | * @return string |
|
81 | */ |
|
82 | public function getDefaultNamespace() |
|
83 | { |
|
84 | return $this->laravel['components']->config('paths.generator.emails', 'Emails'); |
|
85 | } |
|
86 | } |
|
87 |
@@ 9-79 (lines=71) @@ | ||
6 | use Consigliere\Components\Traits\ComponentCommandTrait; |
|
7 | use Symfony\Component\Console\Input\InputArgument; |
|
8 | ||
9 | final class GenerateNotificationCommand extends Command |
|
10 | { |
|
11 | use ComponentCommandTrait; |
|
12 | ||
13 | /** |
|
14 | * The console command name. |
|
15 | * |
|
16 | * @var string |
|
17 | */ |
|
18 | protected $name = 'component:make-notification'; |
|
19 | ||
20 | protected $argumentName = 'name'; |
|
21 | ||
22 | /** |
|
23 | * Get template contents. |
|
24 | * |
|
25 | * @return string |
|
26 | */ |
|
27 | protected function getTemplateContents() |
|
28 | { |
|
29 | $component = $this->laravel['components']->findOrFail($this->getComponentName()); |
|
30 | ||
31 | return (new Stub('/notification.stub', [ |
|
32 | 'NAMESPACE' => $this->getClassNamespace($component), |
|
33 | 'CLASS' => $this->getClass(), |
|
34 | ]))->render(); |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Get the destination file path. |
|
39 | * |
|
40 | * @return string |
|
41 | */ |
|
42 | protected function getDestinationFilePath() |
|
43 | { |
|
44 | $path = $this->laravel['components']->getComponentPath($this->getComponentName()); |
|
45 | ||
46 | $mailPath = $this->laravel['components']->config('paths.generator.notifications', 'Notifications'); |
|
47 | ||
48 | return $path . $mailPath . '/' . $this->getFileName() . '.php'; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * Get the console command arguments. |
|
53 | * |
|
54 | * @return array |
|
55 | */ |
|
56 | protected function getArguments() |
|
57 | { |
|
58 | return [ |
|
59 | ['name', InputArgument::REQUIRED, 'The name of the notification class.'], |
|
60 | ['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
61 | ]; |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * @return string |
|
66 | */ |
|
67 | private function getFileName() |
|
68 | { |
|
69 | return studly_case($this->argument('name')); |
|
70 | } |
|
71 | ||
72 | /** |
|
73 | * @return string |
|
74 | */ |
|
75 | public function getDefaultNamespace() |
|
76 | { |
|
77 | return $this->laravel['components']->config('paths.generator.notifications', 'Notifications'); |
|
78 | } |
|
79 | } |
|
80 |