|
11 | 11 |
|
12 | 12 | namespace Lucid\Console\Generators;
|
13 | 13 |
|
14 |
| -use Exception; |
15 | 14 | use Lucid\Console\Str;
|
16 | 15 | use Lucid\Console\Components\Feature;
|
17 | 16 |
|
18 | 17 | /**
|
19 | 18 | * @author Abed Halawi <[email protected]>
|
20 | 19 | */
|
21 |
| - class FeatureGenerator extends Generator |
22 |
| - { |
23 |
| - public function generate($feature, $service, array $jobs = []) |
24 |
| - { |
25 |
| - $feature = Str::feature($feature); |
26 |
| - $service = Str::service($service); |
| 20 | +class FeatureGenerator extends Generator |
| 21 | +{ |
| 22 | + public function generate($feature, $service, array $jobs = []) |
| 23 | + { |
| 24 | + $feature = Str::feature($feature); |
| 25 | + $service = Str::service($service); |
27 | 26 |
|
28 |
| - $path = $this->findFeaturePath($service, $feature); |
| 27 | + $path = $this->findFeaturePath($service, $feature); |
29 | 28 |
|
30 |
| - if ($this->exists($path)) { |
31 |
| - $this->error('Feature already exists!'); |
| 29 | + if ($this->exists($path)) { |
| 30 | + $this->error('Feature already exists!'); |
32 | 31 |
|
33 |
| - return false; |
34 |
| - } |
| 32 | + return false; |
| 33 | + } |
35 | 34 |
|
36 |
| - $namespace = $this->findFeatureNamespace($service); |
| 35 | + $namespace = $this->findFeatureNamespace($service); |
37 | 36 |
|
38 |
| - $content = file_get_contents($this->getStub()); |
| 37 | + $content = file_get_contents($this->getStub()); |
39 | 38 |
|
| 39 | + $useJobs = ''; // stores the `use` statements of the jobs |
| 40 | + $runJobs = ''; // stores the `$this->run` statements of the jobs |
40 | 41 |
|
41 |
| - $useJobs = ''; // stores the `use` statements of the jobs |
42 |
| - $runJobs = ''; // stores the `$this->run` statements of the jobs |
43 |
| - |
44 |
| - foreach ($jobs as $index => $job) { |
| 42 | + foreach ($jobs as $index => $job) { |
45 | 43 | $useJobs .= 'use '.$job['namespace'].'\\'.$job['className'].";\n";
|
46 |
| - $runJobs .= "\t\t".'$this->run('.$job['className']."::class);"; |
| 44 | + $runJobs .= "\t\t".'$this->run('.$job['className'].'::class);'; |
47 | 45 |
|
48 | 46 | // only add carriage returns when it's not the last job
|
49 |
| - if($index != count($jobs) - 1) { |
| 47 | + if ($index != count($jobs) - 1) { |
50 | 48 | $runJobs .= "\n\n";
|
51 | 49 | }
|
52 |
| - } |
| 50 | + } |
53 | 51 |
|
54 |
| - $content = str_replace( |
55 |
| - ['{{feature}}', '{{namespace}}', '{{foundation_namespace}}', '{{use_jobs}}', '{{run_jobs}}'], |
56 |
| - [$feature, $namespace, $this->findFoundationNamespace(), $useJobs, $runJobs], |
57 |
| - $content |
58 |
| - ); |
| 52 | + $content = str_replace( |
| 53 | + ['{{feature}}', '{{namespace}}', '{{foundation_namespace}}', '{{use_jobs}}', '{{run_jobs}}'], |
| 54 | + [$feature, $namespace, $this->findFoundationNamespace(), $useJobs, $runJobs], |
| 55 | + $content |
| 56 | + ); |
59 | 57 |
|
60 |
| - $this->createFile($path, $content); |
| 58 | + $this->createFile($path, $content); |
61 | 59 |
|
62 |
| - return new Feature( |
| 60 | + return new Feature( |
63 | 61 | $feature,
|
64 | 62 | basename($path),
|
65 | 63 | $path,
|
66 | 64 | $this->relativeFromReal($path),
|
67 | 65 | $this->findService($service),
|
68 | 66 | $content
|
69 | 67 | );
|
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * Get the stub file for the generator. |
74 |
| - * |
75 |
| - * @return string |
76 |
| - */ |
77 |
| - protected function getStub() |
78 |
| - { |
79 |
| - return __DIR__.'/stubs/feature.stub'; |
80 |
| - } |
81 |
| - } |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get the stub file for the generator. |
| 72 | + * |
| 73 | + * @return string |
| 74 | + */ |
| 75 | + protected function getStub() |
| 76 | + { |
| 77 | + return __DIR__.'/stubs/feature.stub'; |
| 78 | + } |
| 79 | +} |
0 commit comments