-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Migrate console commands to Lovata.Toolbox console
- Loading branch information
1 parent
c483a5a
commit 2581b1d
Showing
23 changed files
with
354 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use Lovata\Toolbox\Classes\Console\CommonCreateFile; | ||
|
||
class CommonConsole extends CommonCreateFile | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $arLogoLovata = [ | ||
'▒█▀▀█ █░░ █▀▀█ █▀▀▄ █▀▀ ▀▀█▀▀ █▀▀█ ▒█▀▀▄ █▀▀ █░░ ▒█▀▀▀ █▀▀ ▀▀█▀▀ █▀▀', | ||
'▒█▄▄█ █░░ █▄▄█ █░░█ █▀▀ ░░█░░ █▄▄█ ▒█░▒█ █▀▀ █░░ ▒█▀▀▀ ▀▀█ ░░█░░ █▀▀', | ||
'▒█░░░ ▀▀▀ ▀░░▀ ▀░░▀ ▀▀▀ ░░▀░░ ▀░░▀ ▒█▄▄▀ ▀▀▀ ▀▀▀ ▒█▄▄▄ ▀▀▀ ░░▀░░ ▀▀▀', | ||
]; | ||
|
||
protected function getModelCachedAttrs() | ||
{ | ||
$sExpansionAuthor = array_get($this->arData, 'replace.studly_expansion_author'); | ||
$sExpansionPlugin = array_get($this->arData, 'replace.studly_expansion_plugin'); | ||
$sModel = array_get($this->arData, 'replace.studly_model'); | ||
if (!$sExpansionAuthor || !$sExpansionPlugin || !$sModel) { | ||
return; | ||
} | ||
|
||
/** @var \Model|\Eloquent $obModel */ | ||
$obModel = app(join("\\", [$sExpansionAuthor, $sExpansionPlugin, 'Models', $sModel])); | ||
if ($obModel) { | ||
if (property_exists($obModel, 'cached')) { | ||
$arColumns = $obModel->cached; | ||
$sFileContent = \File::get(plugins_path('planetadeleste/apitoolbox/classes/parser/templates/cached_attributes.stub')); | ||
$sContent = \Twig::parse($sFileContent, ['attributes' => $arColumns]); | ||
array_set($this->arData, 'replace.cached', $sContent); | ||
$this->setEnableList($arColumns); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,26 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use October\Rain\Scaffold\GeneratorCommand; | ||
use October\Rain\Support\Str; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use PlanetaDelEste\ApiToolbox\Classes\Parser\Create\ControllerCreateFile; | ||
|
||
class CreateApiController extends GeneratorCommand | ||
class CreateApiController extends CommonConsole | ||
{ | ||
/** | ||
* @var string The console command name. | ||
*/ | ||
protected $name = 'apitoolbox:create:controller'; | ||
|
||
/** | ||
* @var string The console command description. | ||
*/ | ||
protected $description = 'Create a new Api controller class'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Api Controller'; | ||
|
||
/** | ||
* A mapping of stub to generated file. | ||
* | ||
* @var array | ||
*/ | ||
protected $stubs = [ | ||
'controllers/Controller.stub' => 'controllers/api/{{studly_name}}.php', | ||
]; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function prepareVars() | ||
{ | ||
$pluginCode = $this->argument('plugin'); | ||
|
||
$parts = explode('.', $pluginCode); | ||
$plugin = array_pop($parts); | ||
$author = array_pop($parts); | ||
|
||
$controller = $this->argument('controller'); | ||
|
||
/* | ||
* Determine the model name to use, | ||
* either supplied or singular from the controller name. | ||
*/ | ||
$model = $this->option('model'); | ||
if (!$model) { | ||
$model = Str::singular($controller); | ||
} | ||
|
||
return [ | ||
'name' => $controller, | ||
'model' => $model, | ||
'author' => $author, | ||
'plugin' => $plugin | ||
]; | ||
} | ||
|
||
/** | ||
* Get the console command arguments. | ||
* | ||
* @return array | ||
*/ | ||
protected function getArguments() | ||
{ | ||
return [ | ||
['plugin', InputArgument::REQUIRED, 'The name of the plugin to create. Eg: RainLab.Blog'], | ||
['controller', InputArgument::REQUIRED, 'The name of the controller to create. Eg: Posts'], | ||
]; | ||
} | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.controller'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource index collection.'; | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
* Execute the console command. | ||
*/ | ||
protected function getOptions() | ||
public function handle() | ||
{ | ||
return [ | ||
['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], | ||
['model', null, InputOption::VALUE_OPTIONAL, 'The name of the model. Eg: Post'], | ||
]; | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
$this->setController(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->createFile(ControllerCreateFile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use PlanetaDelEste\ApiToolbox\Classes\Parser\Create\ResourceIndexCreateFile; | ||
|
||
class CreateApiResourceIndex extends CommonConsole | ||
{ | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.resourceindex'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource index collection.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->createFile(ResourceIndexCreateFile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use PlanetaDelEste\ApiToolbox\Classes\Parser\Create\ResourceItemCreateFile; | ||
|
||
class CreateApiResourceItem extends CommonConsole | ||
{ | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.resourceitem'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource index collection.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
// $this->setFieldList(['external_id', self::CODE_VIEW_COUNT]); | ||
$this->getModelCachedAttrs(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->createFile(ResourceItemCreateFile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use PlanetaDelEste\ApiToolbox\Classes\Parser\Create\ResourceListCreateFile; | ||
|
||
class CreateApiResourceList extends CommonConsole | ||
{ | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.resourcelist'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource list collection.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->createFile(ResourceListCreateFile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use PlanetaDelEste\ApiToolbox\Classes\Parser\Create\ResourceShowCreateFile; | ||
|
||
class CreateApiResourceShow extends CommonConsole | ||
{ | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.resourceshow'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource show item.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
// $this->setFieldList(['external_id', self::CODE_VIEW_COUNT]); | ||
$this->getModelCachedAttrs(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->createFile(ResourceShowCreateFile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace PlanetaDelEste\ApiToolbox\Classes\Console; | ||
|
||
use Lovata\Toolbox\Classes\Parser\Create\ModelCreateFile; | ||
|
||
class CreateApiResources extends CommonConsole | ||
{ | ||
/** @var string The console command name. */ | ||
protected $name = 'toolbox:create.api.resources'; | ||
/** @var string The console command description. */ | ||
protected $description = 'Create a new api resource items.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
|
||
$this->setAuthor(true); | ||
$this->setPlugin(true); | ||
$this->setModel(); | ||
// $this->setFieldList(['external_id', self::CODE_VIEW_COUNT]); | ||
$this->getModelCachedAttrs(); | ||
$this->setAdditionList(self::CODE_COMMAND_PARENT); | ||
$this->callCommandList(); | ||
} | ||
|
||
protected function callCommandList() | ||
{ | ||
$this->call('toolbox:create.api.resourceitem', ['data' => $this->arData]); | ||
$this->call('toolbox:create.api.resourceshow', ['data' => $this->arData]); | ||
$this->call('toolbox:create.api.resourceindex', ['data' => $this->arData]); | ||
$this->call('toolbox:create.api.resourcelist', ['data' => $this->arData]); | ||
} | ||
} |
Oops, something went wrong.