Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The MakeSettingsClass command speeds up the process #126

Closed
wants to merge 1 commit into from
Closed
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
The MakeSettingsClass command speeds up the process
  • Loading branch information
egyjs committed Mar 29, 2022
commit eac3ee28cdc92caca312ed044a79f4417e070ec3
61 changes: 61 additions & 0 deletions src/Console/MakeSettingsClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\GeneratorCommand;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline

class MakeSettingsClass extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:setting {name : Setting Class name} {--group= : The group name}';

/**
* The console command name.
*
* @var string
*/

protected $name = 'make:setting';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Settings Class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Setting Class';

protected function getStub()
{
return __DIR__.'/stubs/settingClass.stub'; // todo: add stubs to package!
egyjs marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline here

}

protected function buildClass($name): array|string
{
$class = parent::buildClass($name); // todo: uncomment after stubs added to package!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment here


if ($this->option('group')) {
$class = str_replace(['DummyView','{{ group }}'], $this->option('group'), $class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of DummyView here?

Could we dynamically deduce group from the name? Name probably always will be something like CreateBlogPostSettings if we take BlogPost from that we can make it snake case so it would look like blog_post. Off course we would keep the group command parameter to manually set the group.

}

return $class;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline

protected function getDefaultNamespace($rootNamespace): string
{
return $rootNamespace.'\Settings';
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline


}
21 changes: 21 additions & 0 deletions src/Console/stubs/settingClass.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace {{ namespace }};

use Spatie\LaravelSettings\Settings;

class {{ class }} extends Settings
{
/**
* The app name.
*
* @return string
*/
// protected $appName = 'Laravel Settings';
Comment on lines +9 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add this to an empty Settings class



public static function group(): string
{
return '{{ group }}';
}
}