forked from doppar/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBundleCommand.php
More file actions
87 lines (70 loc) · 2.36 KB
/
BundleCommand.php
File metadata and controls
87 lines (70 loc) · 2.36 KB
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
79
80
81
82
83
84
85
86
87
<?php
namespace Phaseolies\Console\Commands\Presenter;
use Phaseolies\Console\Schedule\Command;
class BundleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:bundle {name}';
/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Create a new presenter bundle class';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
return $this->executeWithTiming(function () {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
$namespace = 'App\\Http\\Presenters' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Http/Presenters/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
if (file_exists($filePath)) {
$this->displayError('Bundle class already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
return Command::FAILURE;
}
$directoryPath = dirname($filePath);
if (!is_dir($directoryPath)) {
mkdir($directoryPath, 0755, true);
}
$content = $this->generatePresentersContent($namespace, $className);
file_put_contents($filePath, $content);
$this->displaySuccess("Bundle class created successfully");
$this->line('<fg=yellow>📁 File:</> <fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->newLine();
return Command::SUCCESS;
});
}
/**
* Generate controller content based on type.
*/
protected function generatePresentersContent(string $namespace, string $className): string
{
return $this->generateRegularPresentersContent($namespace, $className);
}
/**
* Generate standard controller content.
*/
protected function generateRegularPresentersContent(string $namespace, string $className): string
{
return <<<EOT
<?php
namespace {$namespace};
use Phaseolies\Support\Presenter\PresenterBundle;
class {$className} extends PresenterBundle
{
// No additional logic needed here
}
EOT;
}
}