-
Notifications
You must be signed in to change notification settings - Fork 13
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 #17 from AmrAhmedFekry/master
Add new commands and make some modifications on the old of it
- Loading branch information
Showing
20 changed files
with
1,302 additions
and
254 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,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
78
cloneable-modules/users/Repositories/MYSQL/UsersRepository.php
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,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); | ||
} | ||
} |
File renamed without changes.
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
172 changes: 172 additions & 0 deletions
172
src/HZ/Illuminate/Organizer/Console/Commands/EngezController.php
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,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'); | ||
} | ||
} | ||
} |
Oops, something went wrong.