Skip to content

Commit

Permalink
Merge pull request #17 from AmrAhmedFekry/master
Browse files Browse the repository at this point in the history
Add new commands and make some modifications on the old of it
  • Loading branch information
hassanzohdy committed Sep 14, 2019
2 parents 85fd344 + feff6e5 commit 92ec383
Show file tree
Hide file tree
Showing 20 changed files with 1,302 additions and 254 deletions.
27 changes: 27 additions & 0 deletions cloneable-modules/users/Models/MYSQL/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Modules\Users\Models;


use Illuminate\Contracts\Auth\Authenticatable;
use App\Modules\Users\Traits\Auth\updatePassword;
use Illuminate\Auth\Authenticatable as AuthenticatableTrait;
use HZ\Illuminate\Organizer\Managers\Database\MYSQL\Model;

class User extends Model implements Authenticatable
{
use AuthenticatableTrait, updatePassword;

/**
* Get shared info for the user that will be stored as a sub document of another collection
*
* @return array
*/
public function sharedInfo(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
];
}
}
File renamed without changes.
78 changes: 78 additions & 0 deletions cloneable-modules/users/Repositories/MYSQL/UsersRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Modules\Users\Repositories;

use Illuminate\Http\Request;
use App\Modules\Users\{
Models\User,
Traits\Auth\AccessToken,
Resources\User as Resource
};

use HZ\Illuminate\Organizer\{
Contracts\Repositories\RepositoryInterface,
Managers\Database\MYSQL\RepositoryManager
};

class UsersRepository extends RepositoryManager implements RepositoryInterface
{
use AccessToken;

/**
* {@inheritDoc}
*/
const NAME = 'users';

/**
* {@inheritDoc}
*/
const MODEL = User::class;

/**
* {@inheritDoc}
*/
const RESOURCE = Resource::CLASS;

/**
* {@inheritDoc}
*/
const DATA = ['name', 'email'];

/**
* Store the list here as array
*
* @const array
*/
const ARRAYBLE_DATA = [];

/**
* {@inheritDoc}
*/
const UPLOADS = [];

/**
* {@inheritDoc}
*/
const FILTER_BY = [];

/**
* {@inheritDoc}
*/
public $deleteDependenceTables = [];

/**
* {@inheritDoc}
*/
protected function setData($model, $request)
{
// add additional data
}

/**
* {@inheritDoc}
*/
public function onCreate($user, Request $request)
{
$this->generateAccessToken($user, $request);
}
}
1 change: 1 addition & 0 deletions files/config/organizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
Illuminate\Support\Arr::class => HZ\Illuminate\Organizer\Macros\Support\Arr::class,
Illuminate\Http\Request::class => HZ\Illuminate\Organizer\Macros\Http\Request::class,
Illuminate\Support\Collection::class => HZ\Illuminate\Organizer\Macros\Support\Collection::class,
Illuminate\Filesystem\Filesystem::class => HZ\Illuminate\Organizer\Macros\FileSystem\FileSystem::class,
Illuminate\Database\Query\Builder::class => HZ\Illuminate\Organizer\Macros\Database\Query\Builder::class,
Illuminate\Database\Schema\Blueprint::class => HZ\Illuminate\Organizer\Macros\Database\Schema\Blueprint::class,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace HZ\Illuminate\Organizer\Console\Commands;

use File;
use Illuminate\Console\Command;
use HZ\Illuminate\Organizer\Helpers\Mongez;

class CloneModuleBuilder extends Command
{
Expand All @@ -19,7 +19,7 @@ class CloneModuleBuilder extends Command
*
* @var string
*/
protected $signature = 'clone:module {moduleName}';
protected $signature = 'clone:module {module}';

/**
* The console command description.
Expand All @@ -42,7 +42,7 @@ class CloneModuleBuilder extends Command
*/
public function handle()
{
$this->moduleName = $this->argument('moduleName');
$this->moduleName = $this->argument('module');

if (! in_array($this->moduleName, static::AVAILABLE_MODULES)) {
return $this->info('This module does not exits');
Expand All @@ -57,6 +57,8 @@ public function handle()
}

$this->cloneModule();

return $this->info('Module cloned successfully');
}

/**
Expand All @@ -66,7 +68,7 @@ public function handle()
*/
protected function cloneModule()
{
$modulePath = dirname(__DIR__, 6) . '/' . 'cloneable-modules/' . $this->moduleName;
$modulePath = Mongez::packagePath('cloneable-modules/' . $this->moduleName);

File::copyDirectory($modulePath, base_path("app/Modules/" . $this->moduleName));
}
Expand Down
172 changes: 172 additions & 0 deletions src/HZ/Illuminate/Organizer/Console/Commands/EngezController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php
namespace HZ\Illuminate\Organizer\Console\Commands;

use File;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use HZ\Illuminate\Organizer\Helpers\Mongez;
use HZ\Illuminate\Organizer\Traits\Console\EngezTrait;
use HZ\Illuminate\Organizer\Contracts\Console\EngezInterface;

class EngezController extends Command implements EngezInterface
{
use EngezTrait;

/**
* The controller types
*
* @var array
*/
const CONTROLLER_TYPES = ['admin','site','all'];

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'engez:controller {controller}
{--module=}
{type=site}
{--repository=}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Make new controller into module';

/**
* info used for creating controller
*
* @var array
*/
protected $info = [];

/**
* Module directory path
*
* @var string
*/
protected $root;

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->init();
$this->validateArguments();
$this->create();
$this->info('Controller created successfully');
}

/**
* Validate The module name
*
* @return void
*/
public function validateArguments()
{
$availableModules = Mongez::getStored('modules');

if (! $this->option('module')) {
return $this->missingRequiredOption('Module option is required');
}

if (! in_array($this->info['moduleName'], $availableModules)) {
return $this->missingRequiredOption('This module is not available');
}

if (! in_array($this->info['type'], static::CONTROLLER_TYPES)) {
return $this->missingRequiredOption('This controller type does not exits');
}
}

/**
* Set controller info
*
* @return void
*/
public function init()
{
// $this->root = Mongez::packagePath();

$this->info['controllerName'] = Str::studly($this->argument('controller'));
$this->info['moduleName'] = Str::studly($this->option('module'));
$this->info['type'] = $this->argument('type');

$repositoryName = $this->info['controllerName'];

if ($this->option('repository')) {
$repositoryName = $this->option('repository');
}

$this->info['repositoryName'] = $repositoryName;

}

/**
* Create controller File.
*
* @return void
*/
public function create()
{
$controller = $this->info['controllerName'];

$controllerName = basename(str_replace('\\', '/', $controller));

$controllerType = $this->info['type'];

if (in_array($controllerType, ['all', 'site'])) {

$content = File::get($this->path("Controllers/Site/controller.php"));

// replace controller name
$content = str_ireplace("ControllerName", "{$controllerName}Controller", $content);

// replace moule name
$content = str_ireplace("ModuleName", $this->info['moduleName'], $content);

// repository name
$content = str_ireplace('repo-name', $this->info['repositoryName'], $content);

$controllerDirectory = $this->modulePath("Controllers/Site");

$this->checkDirectory($controllerDirectory);

// create the file
$filePath = "$controllerDirectory/{$controllerName}Controller.php";

$this->createFile($filePath, $content, 'Controller');
}

if (in_array($controllerType, ['all', 'admin'])) {
// admin controller
$this->info('Creating admin controller...');

$content = File::get($this->path("Controllers/Admin/controller.php"));

// replace controller name
$content = str_ireplace("ControllerName", "{$controllerName}Controller", $content);

// replace module name
$content = str_ireplace("ModuleName", $this->info['moduleName'], $content);

// repository name
$content = str_ireplace('repo-name', $this->info['repositoryName'], $content);

$controllerDirectory = $this->modulePath("Controllers/Admin");

$this->checkDirectory($controllerDirectory);

// create the file
$filePath = "$controllerDirectory/{$controllerName}Controller.php";

$this->createFile($filePath, $content, 'Admin Controller');
}
}
}
Loading

0 comments on commit 92ec383

Please sign in to comment.