Skip to content

Commit

Permalink
Merge pull request #3 from Elsayed93/main
Browse files Browse the repository at this point in the history
Add new stubs and MakeClass command
  • Loading branch information
MoamenEltouny authored Aug 30, 2024
2 parents e48b84d + 3113886 commit dff2f23
Show file tree
Hide file tree
Showing 17 changed files with 439 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
],
"require": {
"php": ">=7.4",
"laravel/framework": ">=8.0"
"php": "^8.2",
"laravel/framework": "11.*"
},
"config": {
"sort-packages": true
Expand Down
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeAction.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeClass.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeEnum.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeInterface.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeScope.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeService.php
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());
}
}
}
49 changes: 49 additions & 0 deletions src/Core/Commands/MakeTrait.php
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());
}
}
}
14 changes: 14 additions & 0 deletions src/Core/Commands/stubs/action.stub
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()
{
//
}
}
14 changes: 14 additions & 0 deletions src/Core/Commands/stubs/class.stub
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()
{
//
}
}
Loading

0 comments on commit dff2f23

Please sign in to comment.