Skip to content

Commit

Permalink
Allow creating state or action as initial state with option
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersai committed Dec 28, 2023
1 parent 0e87ac6 commit b701ae4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Commands/ActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ class ActionCommand extends GeneratorCommand

protected $signature = 'ussd:action
{name : The name of the USSD Action}
{--init : Create the class as the initial USSD action}
{--force : Create the class even if USSD action already exists}';

protected function getStub()
{
if ($this->option('init')) {
return __DIR__.'/../../stubs/action.init.stub';
}

return __DIR__.'/../../stubs/action.stub';
}

Expand Down
5 changes: 5 additions & 0 deletions src/Commands/StateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ class StateCommand extends GeneratorCommand

protected $signature = 'ussd:state
{name : The name of the USSD State}
{--init : Create the class as the initial USSD state}
{--force : Create the class even if USSD state already exists}';

protected function getStub()
{
if ($this->option('init')) {
return __DIR__.'/../../stubs/state.init.stub';
}

return __DIR__.'/../../stubs/state.stub';
}

Expand Down
13 changes: 13 additions & 0 deletions stubs/action.init.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace {{ namespace }};

use Sparors\Ussd\Contracts\InitialAction;

class {{ class }} implements InitialAction
{
public function execute(): string
{
//
}
}
4 changes: 2 additions & 2 deletions stubs/response.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace {{ namespace }};

use Sparors\Ussd\Contracts\Action;
use Sparors\Ussd\Contracts\Response;

class {{ class }} implements Action
class {{ class }} implements Response
{
public function respond(string $message, bool $terminating): mixed
{
Expand Down
14 changes: 14 additions & 0 deletions stubs/state.init.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace {{ namespace }};

use Sparors\Ussd\Menu;
use Sparors\Ussd\Contracts\InitialState;

class {{ class }} implements InitialState
{
public function render(): Menu
{
return Menu::build()->text('');
}
}

0 comments on commit b701ae4

Please sign in to comment.