Skip to content

Commit

Permalink
Merge pull request #2 from hassanzohdy/master
Browse files Browse the repository at this point in the history
Update to last version
  • Loading branch information
Amr Ahmed Fekry committed Sep 25, 2019
2 parents e3d0062 + e29d756 commit 30a7a67
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 162 deletions.
4 changes: 2 additions & 2 deletions cloneable-modules/users/Middleware/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Auth
*/
public function handle(Request $request, Closure $next)
{
$this->apiKey = config('app.api-key');

$this->apiKey = env('API_KEY');
// set default auth
if (Str::contains($request->uri(), '/admin')) {
$this->appType = 'admin';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A Robust application handler for building neat laravel application(s).",
"keywords": ["laravel","mongez"],
"license": "MIT",
"version": "1.5.6",
"version": "1.5.15",
"require": {
"php": ">=7",
"illuminate/support": "5.6.x|5.7.x|5.8.x|6.0.x",
Expand Down
1 change: 1 addition & 0 deletions files/config/mongez.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
Illuminate\Filesystem\Filesystem::class => HZ\Illuminate\Mongez\Macros\FileSystem\FileSystem::class,
Illuminate\Database\Query\Builder::class => HZ\Illuminate\Mongez\Macros\Database\Query\Builder::class,
Illuminate\Database\Schema\Blueprint::class => HZ\Illuminate\Mongez\Macros\Database\Schema\Blueprint::class,
Illuminate\Console\Command::class => HZ\Illuminate\Mongez\Macros\Console\Command::class,
],
/*
|--------------------------------------------------------------------------
Expand Down
20 changes: 16 additions & 4 deletions module/Migrations/mongodb-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class TableName extends Migration
class className extends Migration
{
/**
* Run the migrations.
Expand All @@ -14,9 +14,21 @@ class TableName extends Migration
public function up()
{
Schema::create('TableName', function (Blueprint $table) {
$table->int('id')->unique();
// Table-Schema

// this is very important to create a unique index for the id
$table->unique('id');

// the auto increment is just dummy pass, it is auto generated for every single model
$table->int('id');
$table->increments('id');

// all of it are just dummy pass, it can be changed from the model class
$table->string('createdAt');
$table->string('createdBy');
$table->string('updatedAt ');
$table->string('updatedBy');
$table->string('deletedAt');
$table->string('deletedBy');
// Table-Schema
});
}

Expand Down
100 changes: 47 additions & 53 deletions src/Console/Commands/EngezController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace HZ\Illuminate\Mongez\Console\Commands;

use File;
Expand All @@ -8,16 +9,16 @@
use HZ\Illuminate\Mongez\Traits\Console\EngezTrait;
use HZ\Illuminate\Mongez\Contracts\Console\EngezInterface;

class EngezController extends Command implements EngezInterface
class EngezController extends Command implements EngezInterface
{
use EngezTrait;

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

/**
* The name and signature of the console command.
Expand All @@ -26,7 +27,7 @@ class EngezController extends Command implements EngezInterface
*/
protected $signature = 'engez:controller {controller}
{--module=}
{type=site}
{--type=all}
{--repository=}';

/**
Expand All @@ -49,7 +50,7 @@ class EngezController extends Command implements EngezInterface
* @var string
*/
protected $root;

/**
* Execute the console command.
*
Expand All @@ -58,11 +59,11 @@ class EngezController extends Command implements EngezInterface
public function handle()
{
$this->init();
$this->validateArguments();
$this->validateArguments();
$this->create();
$this->info('Controller created successfully');
$this->info('Controller has been created successfully.');
}

/**
* Validate The module name
*
Expand All @@ -72,15 +73,15 @@ public function validateArguments()
{
$availableModules = Mongez::getStored('modules');

if (! $this->option('module')) {
if (!$this->option('module')) {
return $this->missingRequiredOption('Module option is required');
}
if (! in_array($this->info['moduleName'], $availableModules)) {

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

if (! in_array($this->info['type'], static::CONTROLLER_TYPES)) {
if (!in_array($this->info['type'], static::CONTROLLER_TYPES)) {
return $this->missingRequiredOption('This controller type does not exits');
}
}
Expand All @@ -94,77 +95,70 @@ public function init()
{
$this->info['controllerName'] = Str::studly($this->argument('controller'));
$this->info['moduleName'] = Str::studly($this->option('module'));
$this->info['type'] = $this->argument('type');
$this->info['type'] = $this->option('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'])) {
$this->createController('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);
if (in_array($controllerType, ['all', 'admin'])) {
$this->createController('admin');
}
}

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

$controllerDirectory = $this->modulePath("Controllers/Site");
/**
* Create a controller for the given type
*
* @param string $controllerType
* @return void
*/
private function createController(string $controllerType)
{
$controller = $this->info['controllerName'];

$this->checkDirectory($controllerDirectory);
$controllerName = basename(str_replace('\\', '/', $controller));

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

$this->createFile($filePath, $content, 'Controller');
}
// admin controller
$this->info("Creating $controllerType controller...");

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

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

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

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

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

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

$this->checkDirectory($controllerDirectory);
$this->checkDirectory($controllerDirectory);

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

$this->createFile($filePath, $content, 'Admin Controller');
}
$this->createFile($filePath, $content, "$bigControllerType Controller");
}
}
13 changes: 8 additions & 5 deletions src/Console/Commands/EngezMigrate.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace HZ\Illuminate\Mongez\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use HZ\Illuminate\Mongez\Helpers\Mongez;
use HZ\Illuminate\Mongez\Traits\Console\EngezTrait;

class EngezMigrate extends Command
{
Expand Down Expand Up @@ -42,7 +44,6 @@ class EngezMigrate extends Command
*/
public function handle()
{

if ($this->hasArgument('modules') && $this->argument('modules')) {
$this->availableModules = explode(',', $this->argument('modules'));
} else {
Expand All @@ -60,7 +61,8 @@ public function handle()
*/
protected function makeMigrate()
{
Artisan::call('migrate', ['--path' => $this->paths]);
Artisan::call('migrate', ['--path' => $this->paths, '--realpath' => true]);

return $this->info('Migrate tables has been created Successfully ');
}

Expand All @@ -70,10 +72,11 @@ protected function makeMigrate()
* @return void
*/
protected function generateModulesPaths()
{
{
foreach ($this->availableModules as $moduleName) {
$this->paths[]= "app\Modules\\{$moduleName}\\database\\migrations";
$this->paths[] = app_path("Modules/{$moduleName}/database/migrations");
}

$this->paths[] = Mongez::packagePath('src/database/migrations/' . config('database.default'));
}
}

21 changes: 17 additions & 4 deletions src/Console/Commands/EngezMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class EngezMigration extends Command implements EngezInterface
*
* @var string
*/
protected $signature = 'engez:migration {moduleName} {--data=} {--uploads=} {--index=} {--unique=}';
protected $signature = 'engez:migration {migration}
{--module=}
{--table=}
{--data=}
{--uploads=}
{--index=}
{--unique=}';

/**
* The console command description.
Expand Down Expand Up @@ -61,7 +67,8 @@ public function init()
{
$this->root = Mongez::packagePath();

$this->info['moduleName'] = Str::studly($this->argument('moduleName'));
$this->info['migration'] = $this->argument('migration');
$this->info['moduleName'] = Str::studly($this->option('module'));
$this->info['index'] = [];
$this->info['unique'] = [];
$this->info['uploads'] = [];
Expand Down Expand Up @@ -108,13 +115,19 @@ public function create()

$path = 'app/modules/'.$this->info['moduleName'].'/database/migrations';

$databaseFileName = strtolower(str::plural($this->info['moduleName']));
// $databaseFileName = strtolower(str::plural($this->info['moduleName']));
$databaseFileName = $this->info['migration'];

$className = Str::studly($databaseFileName);

$this->checkDirectory($path);

$content = File::get($this->path("Migrations/".$databaseDriver."-migration.php"));

$tableName = Str::camel(Str::plural($this->optionHasValue('table') ? $this->option('table') : $databaseFileName));

$content = str_ireplace("TableName", "{$databaseFileName}", $content);
$content = str_ireplace("className", $className, $content);
$content = str_ireplace("TableName", $tableName, $content);

foreach($this->info['index'] as $singleIndexData) {
if (in_array($singleIndexData, $this->info['unique'])) {
Expand Down
Loading

0 comments on commit 30a7a67

Please sign in to comment.