-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thasso Araújo
committed
Jun 15, 2020
1 parent
0c13ecb
commit 8cae1fb
Showing
52 changed files
with
3,020 additions
and
3 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
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,130 @@ | ||
<?php | ||
|
||
namespace App\Console\Scaffold\Makes; | ||
|
||
class BaseMake | ||
{ | ||
protected function start() | ||
{ | ||
$name = $this->param['modelo'] . $this->arq . '.php'; | ||
$this->param['path'] = $this->tratarPathFile(); | ||
|
||
$path = substr(__DIR__, 0, -22) . "Http/" . $this->folder . "/" . $this->param['path'] . $name; | ||
|
||
if ($this->files->exists($path)) { | ||
return $this->scaffoldCommandObj->comment("x $name"); | ||
} | ||
|
||
$this->files->put($path, $this->compileControllerServicesStub()); | ||
$this->scaffoldCommandObj->comment("+ $name"); | ||
} | ||
|
||
protected function compileControllerServicesStub() | ||
{ | ||
$stub = $this->files->get(substr(__DIR__, 0, -5) . 'Modelos/' . $this->stub . '.stub'); | ||
$this->buildStub($stub); | ||
return $stub; | ||
} | ||
|
||
protected function compileViewsStub() | ||
{ | ||
$stub = $this->files->get(substr(__DIR__, 0, -5) . 'Modelos/views/' . $this->stub . '.stub'); | ||
$this->buildStub($stub); | ||
return $stub; | ||
} | ||
|
||
protected function buildStub(&$template) | ||
{ | ||
$this->param['path'] = $this->tratarPath(); | ||
|
||
$template = str_replace("{{objeto}}", strtolower($this->param['modelo']), $template); | ||
$template = str_replace("{{modelo}}", $this->param['modelo'], $template); | ||
|
||
if (empty($this->param['path'])) { | ||
$path_stub = ""; | ||
} else { | ||
$path_stub = "\\" . $this->param['path']; | ||
$path_stub = substr($path_stub, 0, strlen($path_stub) - 1); | ||
} | ||
|
||
$template = str_replace("{{path}}", $path_stub, $template); | ||
|
||
$path_view = str_replace("\\", ".", $path_stub); | ||
$path_view = (empty($path_view)) ? "" : $path_view . "."; | ||
|
||
$template = str_replace( | ||
"{{path_view}}", | ||
strtolower(substr($path_view, 1) . $this->param['modelo']), | ||
$template | ||
); | ||
|
||
$template = str_replace( | ||
"{{route_detalhar}}", | ||
strtolower($this->param['modelo'] . '.detalhar'), | ||
$template | ||
); | ||
$template = str_replace( | ||
"{{route_editar}}", | ||
strtolower($this->param['modelo'] . '.editar'), | ||
$template | ||
); | ||
$template = str_replace( | ||
"{{route_listar}}", | ||
strtolower($this->param['modelo'] . '.listar'), | ||
$template | ||
); | ||
|
||
return $template; | ||
} | ||
|
||
public function getParametros($input) | ||
{ | ||
$param = explode("_", $input); | ||
$result = []; | ||
foreach ($param as $p) { | ||
$dados = explode(":", $p); | ||
$acao = $dados[0]; | ||
$valor = $dados[1]; | ||
$r = $this->verificarComando($acao, $valor); | ||
$result = array_merge($result, $r); | ||
} | ||
return $result; | ||
} | ||
|
||
public function verificarComando($acao, $valor) | ||
{ | ||
switch ($acao) { | ||
case 'md': | ||
$param['modelo'] = $valor; | ||
break; | ||
case 'pt': | ||
$param['path'] = $valor; | ||
break; | ||
case 'pre': | ||
$param['prefixo'] = $valor; | ||
break; | ||
} | ||
return $param; | ||
} | ||
|
||
public function tratarPathFile() | ||
{ | ||
if ($this->param['path'] == '/') { | ||
$path = "/"; | ||
} else { | ||
$path = $this->param['path']; | ||
} | ||
return $path; | ||
} | ||
|
||
public function tratarPath() | ||
{ | ||
if ($this->param['path'] == '/') { | ||
$path = ""; | ||
} else { | ||
$path = $this->param['path']; | ||
} | ||
$path = str_replace("/", "\\", $path); | ||
return $path; | ||
} | ||
} |
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 App\Console\Scaffold\Makes; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use App\Console\Scaffold\Scaffold; | ||
use App\Console\Scaffold\Makes\BaseMake; | ||
|
||
class MakeController extends BaseMake | ||
{ | ||
|
||
protected $scaffoldCommandObj; | ||
|
||
public $arq = 'Controller'; | ||
public $folder = 'Controllers'; | ||
public $stub = 'controller'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->start(); | ||
} | ||
} |
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 App\Console\Scaffold\Makes; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use App\Console\Scaffold\Scaffold; | ||
use App\Console\Scaffold\Makes\BaseMake; | ||
|
||
class MakeEntity extends BaseMake | ||
{ | ||
|
||
protected $scaffoldCommandObj; | ||
|
||
public $arq = ''; | ||
public $folder = 'Entities'; | ||
public $stub = 'entity'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->start(); | ||
} | ||
} |
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 App\Console\Scaffold\Makes; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use App\Console\Scaffold\Scaffold; | ||
use App\Console\Scaffold\Makes\BaseMake; | ||
|
||
class MakeRepository extends BaseMake | ||
{ | ||
|
||
protected $scaffoldCommandObj; | ||
|
||
public $arq = 'Repository'; | ||
public $folder = 'Repositories'; | ||
public $stub = 'repository'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->start(); | ||
} | ||
} |
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 App\Console\Scaffold\Makes; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use App\Console\Scaffold\Scaffold; | ||
use App\Console\Scaffold\Makes\BaseMake; | ||
|
||
class MakeRequest extends BaseMake | ||
{ | ||
|
||
protected $scaffoldCommandObj; | ||
|
||
public $arq = 'Request'; | ||
public $folder = 'Requests'; | ||
public $stub = 'request'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->start(); | ||
} | ||
} |
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 App\Console\Scaffold\Makes; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use App\Console\Scaffold\Scaffold; | ||
use App\Console\Scaffold\Makes\BaseMake; | ||
|
||
class MakeService extends BaseMake | ||
{ | ||
|
||
protected $scaffoldCommandObj; | ||
|
||
public $arq = 'Service'; | ||
public $folder = 'Services'; | ||
public $stub = 'service'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->start(); | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
namespace App\Console\Scaffold\Makes; | ||
|
||
use App\Console\Scaffold\Scaffold; | ||
use Illuminate\Filesystem\Filesystem; | ||
|
||
class MakeView extends BaseMake | ||
{ | ||
protected $scaffoldCommandObj; | ||
|
||
protected $views = [ | ||
'_form', | ||
'cadastrar', | ||
'listar', | ||
'editar', | ||
'detalhar' | ||
]; | ||
|
||
public $arq = 'Service'; | ||
public $folder = 'Services'; | ||
public $stub = 'service'; | ||
|
||
public function __construct(Scaffold $scaffold, Filesystem $files, $param) | ||
{ | ||
$this->files = $files; | ||
$this->scaffoldCommandObj = $scaffold; | ||
$this->param = $param; | ||
$this->createViews(); | ||
} | ||
|
||
private function createViews() | ||
{ | ||
foreach ($this->views as $view) { | ||
$this->startView($view); | ||
} | ||
} | ||
|
||
protected function startView($view) | ||
{ | ||
$name = $view . '.blade.php'; | ||
$this->param['path'] = $this->tratarPathFile(); | ||
|
||
$path = base_path() . '/resources/views/' . strtolower($this->param['path']); | ||
if (!$this->files->exists($path)) { | ||
mkdir($path); | ||
} | ||
|
||
$path = $path . strtolower($this->param['modelo']); | ||
if (!$this->files->exists($path)) { | ||
mkdir($path); | ||
} | ||
|
||
$stub = $this->files->get(substr(__DIR__, 0, -5) . 'Modelos/views/'. $view . '.stub'); | ||
$stub = str_replace("{{objeto}}", strtolower($this->param['modelo']), $stub); | ||
$stub = str_replace("{{modelo}}", $this->param['modelo'], $stub); | ||
|
||
if (empty($this->param['path'])) { | ||
$path_stub = ""; | ||
} else { | ||
$path_stub = "\\".$this->param['path']; | ||
$path_stub = substr($path_stub, 0, strlen($path_stub)-1); | ||
} | ||
|
||
$stub = str_replace("{{path}}", $path_stub, $stub); | ||
|
||
$path_view = str_replace("\\", ".", $path_stub); | ||
$path_view = (empty($path_view)) ? "" : $path_view."."; | ||
|
||
$stub = str_replace("{{path_view}}", strtolower(substr($path_view, 1).$this->param['modelo']), $stub); | ||
|
||
$stub = str_replace("{{route_detalhar}}", strtolower($this->param['modelo'].'.detalhar'), $stub); | ||
$stub = str_replace("{{route_editar}}", strtolower($this->param['modelo'].'.editar'), $stub); | ||
$stub = str_replace("{{route_listar}}", strtolower($this->param['modelo'].'.listar'), $stub); | ||
|
||
$this->files->put($path . '/' . $name, $stub); | ||
$this->scaffoldCommandObj->comment("+ $name"); | ||
} | ||
} |
Oops, something went wrong.