Skip to content

Commit

Permalink
Add "--empty" option in "create:controller", "create:model"
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 7, 2024
1 parent ada3899 commit 28cc0c8
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ $ vendor/bin/combustor install:doctrine
```

> [!NOTE]
> Using the `install:wildfire` command installs [Wildfire](https://roug.in/wildfire/) package while the `install:doctrine` installs [Credo](https://roug.in/credo/) package.
> Using the `install:wildfire` command installs the [Wildfire](https://roug.in/wildfire/) package while the `install:doctrine` installs the [Credo](https://roug.in/credo/) package.
## Reminders

Prior in executing any commands, kindly ensure that the **database tables are defined properly** (foreign keys, indexes, relationships, normalizations) in order to minimize the modifications after the code structure has been generated.
Prior in executing any commands, kindly ensure that the _**database tables are defined properly**_ (foreign keys, indexes, relationships, normalizations) in order to minimize the modifications after the code structure has been generated.

Also, please proceed first in generating models, views, or controllers to database tables that are having _**no relationship with other tables**_ in the database.

Expand Down Expand Up @@ -116,6 +116,7 @@ Create a new HTTP controller.

* `--doctrine` - generates a Doctrine-based controller
* `--wildfire` - generates a Wildfire-based controller
* `--empty` - generates an empty HTTP controller

> [!NOTE]
> If either `Wildfire` or `Doctrine` is installed, no need to specify it as option for executing a specified command (e.g. `--wildfire`). However if both are installed, a command must have a `--wildfire` or `--doctrine` option added.
Expand All @@ -138,6 +139,7 @@ Create a new model.

* `--doctrine` - generates a Doctrine-based model
* `--wildfire` - generates a Wildfire-based model
* `--empty` - generates an empty model

**Example**

Expand Down
11 changes: 4 additions & 7 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[x] bootstrap
- [ ] index pagination
[ ] --empty
[ ] bootstrap pagination
[ ] --force
[x] custom fields
- [ ] email
[ ] multi relations
[*] create:repository
[ ] custom field email
[ ] custom field gender
[ ] multi relations
10 changes: 10 additions & 0 deletions src/Commands/CreateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function init()
$this->addOption('doctrine', 'generates a Doctrine-based model');

$this->addOption('wildfire', 'generates a Wildfire-based model');

$this->addOption('empty', 'generates an empty model');
}

/**
Expand All @@ -52,6 +54,9 @@ public function run()
/** @var boolean */
$wildfire = $this->getOption('wildfire');

/** @var boolean */
$empty = $this->getOption('empty');

try
{
$type = $this->getInstalled($doctrine, $wildfire);
Expand All @@ -74,6 +79,11 @@ public function run()

$plate = $this->getTemplate($type);

if ($empty)
{
$plate->setEmpty();
}

$plate = $this->maker->make($plate);

file_put_contents($file, $plate);
Expand Down
10 changes: 10 additions & 0 deletions src/Commands/CreateRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function init()
$this->addOption('doctrine', 'generates a Doctrine-based controller');

$this->addOption('wildfire', 'generates a Wildfire-based controller');

$this->addOption('empty', 'generates an empty HTTP controller');
}

/**
Expand All @@ -52,6 +54,9 @@ public function run()
/** @var boolean */
$wildfire = $this->getOption('wildfire');

/** @var boolean */
$empty = $this->getOption('empty');

try
{
$type = $this->getInstalled($doctrine, $wildfire);
Expand All @@ -74,6 +79,11 @@ public function run()

$plate = $this->getTemplate($type);

if ($empty)
{
$plate->setEmpty();
}

$plate = $this->maker->make($plate);

file_put_contents($file, $plate);
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/CreateScaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function init()
$this->addOption('doctrine', 'generates a Doctrine-based controller, models, and views');

$this->addOption('wildfire', 'generates a Wildfire-based controller, models, and views');

$this->addOption('empty', 'generates an empty HTTP controller and model');
}

/**
Expand All @@ -56,6 +58,9 @@ public function run()
/** @var boolean */
$doctrine = $this->getOption('doctrine');

/** @var boolean */
$empty = $this->getOption('empty');

/** @var boolean */
$wildfire = $this->getOption('wildfire');

Expand All @@ -75,6 +80,7 @@ public function run()

$input = array('table' => $table);
$input['--doctrine'] = $doctrine;
$input['--empty'] = $empty;
$input['--wildfire'] = $wildfire;

// Execute the "create:controller" command ----
Expand All @@ -89,6 +95,8 @@ public function run()
/** @var boolean */
$bootstrap = $this->getOption('bootstrap');

unset($input['--empty']);

$input['--bootstrap'] = $bootstrap;

$this->runCommand('create:views', $input);
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixture/Plates/Empty/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Rougin\SparkPlug\Controller;

class Users extends Controller
{
}
7 changes: 7 additions & 0 deletions tests/Fixture/Plates/Empty/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Rougin\Wildfire\Model;

class User extends Model
{
}
56 changes: 56 additions & 0 deletions tests/PlateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,46 @@ public function test_doctrine_view_with_bootstrap()
$this->assertEquals($expected, $actual);
}

/**
* @return void
*/
public function test_empty_controller()
{
$test = $this->findCommand('create:controller');

$input = array('table' => 'users');
$input['--empty'] = true;
$input['--wildfire'] = true;

$test->execute($input);

$expected = $this->getEmptyCtrl();

$actual = $this->getActualCtrl('Users');

$this->assertEquals($expected, $actual);
}

/**
* @return void
*/
public function test_empty_model()
{
$test = $this->findCommand('create:model');

$input = array('table' => 'users');
$input['--empty'] = true;
$input['--wildfire'] = true;

$test->execute($input);

$expected = $this->getEmptyModel();

$actual = $this->getActualModel('User');

$this->assertEquals($expected, $actual);
}

/**
* @return void
*/
Expand Down Expand Up @@ -480,6 +520,22 @@ protected function getDoctrineView($type = self::VIEW_COMMON)
return $create . "\n" . $edit . "\n" . $index;
}

/**
* @return string
*/
protected function getEmptyCtrl()
{
return $this->getTemplate('Empty/Controller');
}

/**
* @return string
*/
protected function getEmptyModel()
{
return $this->getTemplate('Empty/Model');
}

/**
* @param integer $type
*
Expand Down

0 comments on commit 28cc0c8

Please sign in to comment.