Skip to content

Commit

Permalink
#142. Change code generation with custom business logic preserve (by …
Browse files Browse the repository at this point in the history
…default), if --regenerate option not used
  • Loading branch information
arthurkushman committed Feb 23, 2019
1 parent b5b0f8c commit 85ff3ed
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/Controllers/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@
use SoliDry\Types\ApiInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Trait GeneratorTrait
*
* @package SoliDry\Controllers
*/
trait GeneratorTrait
{
// all generated entities/resources
private $forms;
private $mappers;
private $routes;
private $migrations;
private $controllers;
private $tests;

// gen dir found in history
private $genDir;

/**
Expand All @@ -40,19 +47,13 @@ private function generateResources(): void
$this->createControllers();

// create controller
$this->controllers = new Controllers($this);
$this->controllers->createDefault();
$this->controllers->createEntity($this->formatControllersPath(), DefaultInterface::CONTROLLER_POSTFIX);
$this->createControllers();

// create FormRequest
$this->forms = new FormRequest($this);
$this->forms->createEntity($this->formatRequestsPath(), DefaultInterface::FORM_REQUEST_POSTFIX);
$this->forms->createAccessToken();
$this->solveFormRequest();

// create entities/models
$this->mappers = new Entities($this);
$this->mappers->createPivot();
$this->mappers->createEntity($this->formatEntitiesPath());
$this->solveEntities();

// create routes
$this->routes = new Routes($this);
Expand Down Expand Up @@ -81,29 +82,44 @@ private function mergeResources(): void
$this->outputEntity();
$this->createControllers();

$this->solveFormRequest();

$this->solveEntities();

// create routes
$this->routes = new Routes($this);
$this->routes->create();

$this->createMigrations();
}

private function solveFormRequest(): void
{
$this->forms = new FormRequest($this);
$formRequestPath = $this->formatRequestsPath();
if (true === file_exists($this->forms->getEntityFile($formRequestPath, DefaultInterface::FORM_REQUEST_POSTFIX))) {
if (empty($this->options[ConsoleInterface::OPTION_MERGE]) === false
&& file_exists($this->forms->getEntityFile($formRequestPath, DefaultInterface::FORM_REQUEST_POSTFIX)) === true) {
$this->forms->recreateEntity($formRequestPath, DefaultInterface::FORM_REQUEST_POSTFIX);
} else {
$this->forms->createEntity($formRequestPath, DefaultInterface::FORM_REQUEST_POSTFIX);
}
}

/**
* Decide whether to generate new Entities or mutate existing
*/
private function solveEntities(): void
{
// create entities/models
$this->mappers = new Entities($this);
$this->mappers->createPivot();
$entitiesPath = $this->formatEntitiesPath();
if (true === file_exists($this->forms->getEntityFile($entitiesPath))) {
if (empty($this->options[ConsoleInterface::OPTION_MERGE]) === false
&& file_exists($this->forms->getEntityFile($entitiesPath)) === true) {
$this->mappers->recreateEntity($entitiesPath);
} else {
$this->mappers->createEntity($entitiesPath);
}

// create routes
$this->routes = new Routes($this);
$this->routes->create();

$this->createMigrations();
}

private function outputEntity(): void
Expand Down

0 comments on commit 85ff3ed

Please sign in to comment.