Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Phaseolies/Console/Commands/MakeAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected function listExistingAuthFiles(): void
$this->line("<fg=yellow>{$category}:</>");
foreach ($paths as $path) {
if (file_exists($path)) {
$this->line('- ' . str_replace(base_path(), '', $path));
$this->line('- ' . $this->relativePath($path));
}
}
$this->newLine();
Expand Down
11 changes: 4 additions & 7 deletions src/Phaseolies/Console/Commands/MakeAuthorizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ class MakeAuthorizerCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$model = $this->option('model') ?? $this->option('m');

$parts = explode('/', $name);
$className = array_pop($parts);

$namespace = 'App\\Authorizers' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Authorizers/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Authorizers', $name);

if (file_exists($filePath)) {
$this->displayError('Authorizer already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -52,7 +49,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Authorizer created successfully');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();

return Command::SUCCESS;
Expand Down
10 changes: 4 additions & 6 deletions src/Phaseolies/Console/Commands/MakeConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ class MakeConsoleCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$namespace = 'App\\Schedule\\Commands' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Schedule/Commands/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Schedule/Commands', $name);

if (file_exists($filePath)) {
$this->displayError('Command already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -49,7 +47,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Command created successfully');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>📌 Command Name:</> <fg=white>doppar:' . $this->convertToKebabCase($className) . '</>');

Expand Down
25 changes: 16 additions & 9 deletions src/Phaseolies/Console/Commands/MakeControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function handle(): int

if (file_exists($filePath)) {
$this->displayError('Controller already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand Down Expand Up @@ -176,7 +176,10 @@ protected function extractSubNamespace(string $namespace): string
*/
protected function parseFlags(): array
{
$name = str()->suffixAppend($this->argument('name'), 'Controller');
$name = str()->suffixAppend(
$this->normalizeGeneratedName((string) $this->argument('name')),
'Controller'
);
$routeName = strtolower(str()->removeSuffix($name, 'Controller'));
$isInvokable = $this->option('invokable');
$isResource = $this->option('bundle');
Expand All @@ -193,14 +196,14 @@ protected function parseFlags(): array
*/
protected function resolveNamespacesAndPaths(string $name, bool $isApi): array
{
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName($name);
$baseNamespace = 'App\\Http\\Controllers' . ($isApi ? '\\API' : '');
$namespace = $baseNamespace . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');

$filePath = base_path('app/Http/Controllers/' .
($isApi ? 'API/' : '') .
str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath(
'app/Http/Controllers' . ($isApi ? '/API' : ''),
$name
);

return [$namespace, $filePath, $className];
}
Expand Down Expand Up @@ -230,7 +233,11 @@ protected function generateLayout(string $namespace, string $className, string $
{
$layoutStub = $this->getLayoutStub('complete.stub');
$layoutContent = $this->replacePlaceholders($layoutStub, $namespace, $className, $routeName);
$layoutDir = base_path('resources/views/' . $routeName);
$layoutDir = base_path(str_replace(
['/', '\\'],
DIRECTORY_SEPARATOR,
'resources/views/' . $this->normalizeGeneratedName($routeName)
));
$this->createDirIfMissing($layoutDir);
$layoutPath = $layoutDir . '/default.odo.php';
$this->writeFile($layoutPath, $layoutContent);
Expand All @@ -242,7 +249,7 @@ protected function generateLayout(string $namespace, string $className, string $
*/
protected function outputFilePath(string $label, string $path): void
{
$this->line('<fg=yellow>' . $label . ':</> <fg=white>' . str_replace(base_path('/'), '', $path) . '</>');
$this->line('<fg=yellow>' . $label . ':</> <fg=white>' . $this->relativePath($path) . '</>');
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/Phaseolies/Console/Commands/MakeHookCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ class MakeHookCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$namespace = 'App\\Hooks' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Hooks/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Hooks', $name);

// Check if hook already exists
if (file_exists($filePath)) {
$this->displayError('Hook already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -52,7 +50,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Hook created successfully');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>📌 Hook Class:</> <fg=white>' . $className . '</>');

Expand Down Expand Up @@ -88,4 +86,4 @@ public function handle(Model \$model): void

EOT;
}
}
}
10 changes: 4 additions & 6 deletions src/Phaseolies/Console/Commands/MakeMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ class MakeMailCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));

// Ensure class name ends with Mail
if (!str_ends_with($className, 'Mail')) {
$className .= 'Mail';
}

$namespace = 'App\\Mail' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Mail/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Mail', $name);

// Check if Mailable already exists
if (file_exists($filePath)) {
$this->displayError('Mailable already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -58,7 +56,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Mailable created successfully');
$this->line('<fg=yellow>📧 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📧 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>✉️ Class:</> <fg=white>' . $className . '</>');

Expand Down
12 changes: 5 additions & 7 deletions src/Phaseolies/Console/Commands/MakeMiddlewareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ class MakeMiddlewareCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$namespace = 'App\\Http\\Middleware' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Http/Middleware/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Http/Middleware', $name);

// Check if middleware already exists
if (file_exists($filePath)) {
$this->displayError('Middleware already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -52,7 +50,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Middleware created successfully');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>🔒 Class:</> <fg=white>' . $className . '</>');

Expand Down Expand Up @@ -92,4 +90,4 @@ public function __invoke(Request \$request, Closure \$next): Response

EOT;
}
}
}
14 changes: 6 additions & 8 deletions src/Phaseolies/Console/Commands/MakeModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ public function __construct(MigrationCreator $creator)
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$withMigration = $this->option('m');
$parts = explode('/', $name);
$className = array_pop($parts);
$namespace = 'App\\Models' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Models/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Models', $name);

// Check if model already exists
if (file_exists($filePath)) {
$this->displayError('Model already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -73,7 +71,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Model created successfully');
$this->line('<fg=yellow>📦 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📦 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>📌 Class:</> <fg=white>' . $className . '</>');

Expand All @@ -86,7 +84,7 @@ public function handle(): int
$this->newLine();
$this->line('<bg=blue;options=bold> MIGRATION </> Created migration:');
$this->newLine();
$this->line('<fg=white>' . str_replace(base_path('/'), '', $migrationFile) . '</>');
$this->line('<fg=white>' . $this->relativePath($migrationFile) . '</>');
}

return Command::SUCCESS;
Expand Down Expand Up @@ -133,4 +131,4 @@ protected function getMigrationPath(): string
{
return base_path('database/migrations');
}
}
}
17 changes: 9 additions & 8 deletions src/Phaseolies/Console/Commands/MakeProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class MakeProviderCommand extends Command
*/
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$namespace = 'App\\Providers';
$filePath = base_path('app/Providers/' . $name . '.php');
return $this->executeWithTiming(function () {
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$namespace = 'App\\Providers' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = $this->generatedFilePath('app/Providers', $name);

// Check if provider already exists
if (file_exists($filePath)) {
$this->displayError('Provider already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -46,13 +46,13 @@ public function handle(): int
}

// Generate and save provider class
$content = $this->generateProviderContent($namespace, $name);
$content = $this->generateProviderContent($namespace, $className);
file_put_contents($filePath, $content);

$this->displaySuccess('Provider created successfully');
$this->line('<fg=yellow>📦 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📦 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>📌 Class:</> <fg=white>' . $name . '</>');
$this->line('<fg=yellow>📌 Class:</> <fg=white>' . $className . '</>');

return Command::SUCCESS;
});
Expand All @@ -69,6 +69,7 @@ protected function generateProviderContent(string $namespace, string $className)
namespace {$namespace};

use Phaseolies\Providers\ServiceProvider;
// use Phaseolies\Providers\GhostableProvider;

class {$className} extends ServiceProvider
{
Expand Down
10 changes: 4 additions & 6 deletions src/Phaseolies/Console/Commands/MakeRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ class MakeRequestCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function() {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));

// Ensure class name ends with Request
if (!str_ends_with($className, 'Request')) {
$className .= 'Request';
}

$namespace = 'App\\Http\\Validations' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Http/Validations/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Http/Validations', $name);

// Check if request already exists
if (file_exists($filePath)) {
$this->displayError('Request already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -58,7 +56,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Request created successfully');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>📁 File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>📌 Class:</> <fg=white>' . $className . '</>');

Expand Down
10 changes: 4 additions & 6 deletions src/Phaseolies/Console/Commands/MakeRuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ class MakeRuleCommand extends Command
public function handle(): int
{
return $this->executeWithTiming(function () {
$name = $this->argument('name');
$parts = explode('/', $name);
$className = array_pop($parts);
[$name, $parts, $className] = $this->splitGeneratedName((string) $this->argument('name'));
$namespace = 'App\\Http\\Validations\\Rules' . (count($parts) > 0 ? '\\' . implode('\\', $parts) : '');
$filePath = base_path('app/Http/Validations/Rules/' . str_replace('/', DIRECTORY_SEPARATOR, $name) . '.php');
$filePath = $this->generatedFilePath('app/Http/Validations/Rules', $name);

// Check if rule already exists
if (file_exists($filePath)) {
$this->displayError('Rule already exists at:');
$this->line('<fg=white>' . str_replace(base_path(), '', $filePath) . '</>');
$this->line('<fg=white>' . $this->relativePath($filePath) . '</>');
return Command::FAILURE;
}

Expand All @@ -52,7 +50,7 @@ public function handle(): int
file_put_contents($filePath, $content);

$this->displaySuccess('Rule created successfully');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . str_replace(base_path('/'), '', $filePath) . '</>');
$this->line('<fg=yellow>🛡️ File:</> <fg=white>' . $this->relativePath($filePath) . '</>');
$this->newLine();
$this->line('<fg=yellow>🔒 Class:</> <fg=white>' . $className . '</>');

Expand Down
Loading
Loading