5 changed files with 165 additions and 127 deletions
-
135src/CrudMake.php
-
30src/Generators/FormViewGenerator.php
-
30src/Generators/IndexViewGenerator.php
-
64src/Generators/LangFileGenerator.php
-
33src/Generators/ModelFactoryGenerator.php
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Form View Generator Class |
|||
*/ |
|||
class FormViewGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$viewPath = $this->makeDirectory(resource_path('views/'.$this->modelNames['table_name'])); |
|||
|
|||
$this->generateFile($viewPath.'/forms.blade.php', $this->getContent()); |
|||
|
|||
$this->command->info($this->modelNames['model_name'].' form view file generated.'); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/view-forms.stub'); |
|||
return $this->replaceStubString($stub); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Index Views Generator Class |
|||
*/ |
|||
class IndexViewGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$viewPath = $this->makeDirectory(resource_path('views/'.$this->modelNames['table_name'])); |
|||
|
|||
$this->generateFile($viewPath.'/index.blade.php', $this->getContent()); |
|||
|
|||
$this->command->info($this->modelNames['model_name'].' index view file generated.'); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/view-index.stub'); |
|||
return $this->replaceStubString($stub); |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Lang File Generator Class |
|||
*/ |
|||
class LangFileGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$langPath = $this->makeDirectory(resource_path('lang/en')); |
|||
|
|||
$this->createAppLangFile($langPath); |
|||
$this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getContent()); |
|||
|
|||
$this->command->info($this->modelNames['lang_name'].' lang files generated.'); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/lang.stub'); |
|||
|
|||
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->modelNames['model_name']))); |
|||
|
|||
$properLangFileContent = str_replace( |
|||
$this->modelNames['model_name'], |
|||
$displayModelName, |
|||
$this->replaceStubString($stub) |
|||
); |
|||
|
|||
return $properLangFileContent; |
|||
} |
|||
|
|||
/** |
|||
* Generate lang/app.php file if it doesn't exists |
|||
* |
|||
* @param string $langPath Directory path of lang files |
|||
* @return void |
|||
*/ |
|||
private function createAppLangFile($langPath) |
|||
{ |
|||
if (! $this->files->exists($langPath.'/app.php')) { |
|||
$this->generateFile($langPath.'/app.php', $this->getAppLangFileContent()); |
|||
$this->command->info('lang/app.php generated.'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get lang/app.php file content |
|||
* |
|||
* @return string |
|||
*/ |
|||
private function getAppLangFileContent() |
|||
{ |
|||
return $this->files->get(__DIR__.'/../stubs/lang-app.stub'); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Model Factory Generator Class |
|||
*/ |
|||
class ModelFactoryGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$modelFactoryPath = $this->makeDirectory(database_path('factories')); |
|||
|
|||
$this->generateFile( |
|||
$modelFactoryPath.'/'.$this->modelNames['model_name'].'Factory.php', |
|||
$this->getContent() |
|||
); |
|||
|
|||
$this->command->info($this->modelNames['model_name'].' model factory generated.'); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/model-factory.stub'); |
|||
return $this->replaceStubString($stub); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue