-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Elsayed93/main
Add new stubs and MakeClass command
- Loading branch information
Showing
17 changed files
with
439 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeAction extends Command | ||
{ | ||
protected $description = 'Create a new Artisan action of a module'; | ||
protected $signature = 'module:make:action {module : Module\'s name} {name : Action\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Action} | ||
{--pest : Generate an accompanying Pest test for the Action}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE ACTIONS DIRECTORY IF NOT FOUND | ||
if (!file_exists($actions = $this->getPath('Actions'))) | ||
File::makeDirectory($actions, 0777, true, true); | ||
|
||
$content = str_replace('{{ class }}', $this->name, file_get_contents(__DIR__ . '/stubs/action.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Actions'), $content); | ||
|
||
// SAVING action | ||
if (file_exists($path = $this->getPath('Actions/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Action is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Action created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Actions/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeClass extends Command | ||
{ | ||
protected $description = 'Create a new Artisan class of a module'; | ||
protected $signature = 'module:make:class {module : Module\'s name} {name : Class\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Class} | ||
{--pest : Generate an accompanying Pest test for the Class}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE CLASSES DIRECTORY IF NOT FOUND | ||
if (!file_exists($classes = $this->getPath('Classes'))) | ||
File::makeDirectory($classes, 0777, true, true); | ||
|
||
$content = str_replace('{{ class }}', $this->name, file_get_contents(__DIR__ . '/stubs/class.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Classes'), $content); | ||
|
||
// SAVING CLASS | ||
if (file_exists($path = $this->getPath('Classes/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Class is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Class created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Classes/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeEnum extends Command | ||
{ | ||
protected $description = 'Create a new Artisan enum of a module'; | ||
protected $signature = 'module:make:enum {module : Module\'s name} {name : Enum\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Enum} | ||
{--pest : Generate an accompanying Pest test for the Enum}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE ENUMS DIRECTORY IF NOT FOUND | ||
if (!file_exists($enums = $this->getPath('Enums'))) | ||
File::makeDirectory($enums, 0777, true, true); | ||
|
||
$content = str_replace('{{ class }}', $this->name, file_get_contents(__DIR__ . '/stubs/enum.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Enums'), $content); | ||
|
||
// SAVING ENUM | ||
if (file_exists($path = $this->getPath('Enums/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Enum is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Enum created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Enums/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeInterface extends Command | ||
{ | ||
protected $description = 'Create a new Artisan interface of a module'; | ||
protected $signature = 'module:make:interface {module : Module\'s name} {name : Interface\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Interface} | ||
{--pest : Generate an accompanying Pest test for the Interface}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE INTERFACES DIRECTORY IF NOT FOUND | ||
if (!file_exists($interfaces = $this->getPath('Interfaces'))) | ||
File::makeDirectory($interfaces, 0777, true, true); | ||
|
||
$content = str_replace('{{ interface }}', $this->name, file_get_contents(__DIR__ . '/stubs/interface.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Interfaces'), $content); | ||
|
||
// SAVING INTERFACE | ||
if (file_exists($path = $this->getPath('Interfaces/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Interface is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Interface created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Interfaces/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeScope extends Command | ||
{ | ||
protected $description = 'Create a new Artisan scope of a module'; | ||
protected $signature = 'module:make:scope {module : Module\'s name} {name : Scope\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Scope} | ||
{--pest : Generate an accompanying Pest test for the Scope}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE SCOPES DIRECTORY IF NOT FOUND | ||
if (!file_exists($scopes = $this->getPath('Scopes'))) | ||
File::makeDirectory($scopes, 0777, true, true); | ||
|
||
$content = str_replace('{{ class }}', $this->name, file_get_contents(__DIR__ . '/stubs/scope.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Scopes'), $content); | ||
|
||
// SAVING SCOPE | ||
if (file_exists($path = $this->getPath('Scopes/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Scope is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Scope created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Scopes/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeService extends Command | ||
{ | ||
protected $description = 'Create a new Artisan service class of a module'; | ||
protected $signature = 'module:make:service {module : Module\'s name} {name : Service\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Service} | ||
{--pest : Generate an accompanying Pest test for the Service}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE SERVICES DIRECTORY IF NOT FOUND | ||
if (!file_exists($services = $this->getPath('Services'))) | ||
File::makeDirectory($services, 0777, true, true); | ||
|
||
$content = str_replace('{{ class }}', $this->name, file_get_contents(__DIR__ . '/stubs/service.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Services'), $content); | ||
|
||
// SAVING SERVICE CLASS | ||
if (file_exists($path = $this->getPath('Services/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Service is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Service created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Services/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Pharaonic\Laravel\Modulator\Core\Commands; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
use Pharaonic\Laravel\Modulator\Core\Command; | ||
|
||
class MakeTrait extends Command | ||
{ | ||
protected $description = 'Create a new Artisan trait of a module'; | ||
protected $signature = 'module:make:trait {module : Module\'s name} {name : Trait\'s name} | ||
{--test : Generate an accompanying PHPUnit test for the Trait} | ||
{--pest : Generate an accompanying Pest test for the Trait}'; | ||
|
||
public function exec() | ||
{ | ||
if (!$this->moduleExists()) return; | ||
|
||
// CREATE TRAITS DIRECTORY IF NOT FOUND | ||
if (!file_exists($traits = $this->getPath('Traits'))) | ||
File::makeDirectory($traits, 0777, true, true); | ||
|
||
$content = str_replace('{{ trait }}', $this->name, file_get_contents(__DIR__ . '/stubs/trait.stub')); | ||
$content = str_replace('{{ namespace }}', $this->getNamespace('Traits'), $content); | ||
|
||
// SAVING TRAIT | ||
if (file_exists($path = $this->getPath('Traits/' . $this->fullName . '.php')) && !$this->option('force')) { | ||
$this->error('Trait is already exists!'); | ||
return false; | ||
} | ||
|
||
if (!File::isDirectory($dir = dirname($path))) | ||
File::makeDirectory($dir, 0755, true, true); | ||
|
||
if (File::put($path, $content)) { | ||
$this->info('Trait created successfully.'); | ||
} else { | ||
$this->warn('There is something wrong.'); | ||
} | ||
|
||
// CREATE TEST | ||
if ($this->option('test') || $this->option('pest')) { | ||
$command = 'module:make:test ' . $this->module . ' Traits/' . $this->fullName; | ||
$command .= $this->option('pest') ? ' --pest' : null; | ||
Artisan::call($command, [], $this->getOutput()); | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
/** | ||
* @method void handle() | ||
*/ | ||
class {{ class }} | ||
{ | ||
public function handle() | ||
{ | ||
// | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
class {{ class }} | ||
{ | ||
/** | ||
* Create a new class instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
} |
Oops, something went wrong.