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
73 changes: 73 additions & 0 deletions src/Scaffold/Console/CreateSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php namespace Winter\Storm\Scaffold\Console;

use Winter\Storm\Scaffold\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class CreateSettings extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'create:settings {plugin} {settings=Settings}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new settings model.';

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

/**
* A mapping of stubs to generated files.
*
* @var array
*/
protected $stubs = [
'settings/model.stub' => 'models/{{studly_name}}.php',
'settings/fields.stub' => 'models/{{lower_name}}/fields.yaml'
];

/**
* Prepare variables for stubs.
*
* return @array
*/
protected function prepareVars()
{
$pluginCode = $this->argument('plugin');

$parts = explode('.', $pluginCode);
$plugin = array_pop($parts);
$author = array_pop($parts);
$settings = $this->argument('settings') ?? 'Settings';

return [
'name' => $settings,
'author' => $author,
'plugin' => $plugin
];
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['plugin', InputArgument::REQUIRED, 'The name of the plugin. Eg: Winter.Blog'],
['settings', InputArgument::OPTIONAL, 'The name of the settings model. Eg: Settings'],
];
}
}
7 changes: 7 additions & 0 deletions src/Scaffold/Console/settings/fields.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ===================================
# Form Field Definitions
# ===================================

fields:
settings_option:
label: This is a sample settings field used by {{author}}.{{plugin}}
31 changes: 31 additions & 0 deletions src/Scaffold/Console/settings/model.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php namespace {{studly_author}}\{{studly_plugin}}\Models;

use Model;

/**
* {{name}} Model
*/
class {{studly_name}} extends Model
{
use \Winter\Storm\Database\Traits\Validation;

/**
* @var array Behaviors implemented by this model.
*/
public $implement = ['System.Behaviors.SettingsModel'];

/**
* @var string Unique code
*/
public $settingsCode = '{{lower_author}}_{{lower_plugin}}_{{lower_name}}';

/**
* @var mixed Settings form field definitions
*/
public $settingsFields = 'fields.yaml';

/**
* @var array Validation rules
*/
public $rules = [];
}
4 changes: 4 additions & 0 deletions src/Scaffold/ScaffoldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\ServiceProvider;
use Winter\Storm\Scaffold\Console\CreateModel;
use Winter\Storm\Scaffold\Console\CreateSettings;
use Winter\Storm\Scaffold\Console\CreateTheme;
use Winter\Storm\Scaffold\Console\CreatePlugin;
use Winter\Storm\Scaffold\Console\CreateCommand;
Expand All @@ -22,6 +23,7 @@ class ScaffoldServiceProvider extends ServiceProvider implements DeferrableProvi
'command.create.theme' => CreateTheme::class,
'command.create.plugin' => CreatePlugin::class,
'command.create.model' => CreateModel::class,
'command.create.settings' => CreateSettings::class,
'command.create.controller' => CreateController::class,
'command.create.component' => CreateComponent::class,
'command.create.formwidget' => CreateFormWidget::class,
Expand All @@ -42,6 +44,7 @@ public function register()
'command.create.theme',
'command.create.plugin',
'command.create.model',
'command.create.settings',
'command.create.controller',
'command.create.component',
'command.create.formwidget',
Expand All @@ -63,6 +66,7 @@ public function provides()
'command.create.theme',
'command.create.plugin',
'command.create.model',
'command.create.settings',
'command.create.controller',
'command.create.component',
'command.create.formwidget',
Expand Down