@@ -8,37 +8,37 @@ |
||
| 8 | 8 | class Permission extends Model |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - use SoftDeletes; |
|
| 12 | - protected $table = 'permissions'; |
|
| 13 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | - protected $hidden = ['deleted_at']; |
|
| 15 | - protected $guarded = ['id']; |
|
| 16 | - protected $fillable = ['name', 'model']; |
|
| 17 | - public $searchable = ['name', 'model']; |
|
| 11 | + use SoftDeletes; |
|
| 12 | + protected $table = 'permissions'; |
|
| 13 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | + protected $hidden = ['deleted_at']; |
|
| 15 | + protected $guarded = ['id']; |
|
| 16 | + protected $fillable = ['name', 'model']; |
|
| 17 | + public $searchable = ['name', 'model']; |
|
| 18 | 18 | |
| 19 | - public function getCreatedAtAttribute($value) |
|
| 20 | - { |
|
| 21 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | - } |
|
| 19 | + public function getCreatedAtAttribute($value) |
|
| 20 | + { |
|
| 21 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function getUpdatedAtAttribute($value) |
|
| 25 | - { |
|
| 26 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | - } |
|
| 24 | + public function getUpdatedAtAttribute($value) |
|
| 25 | + { |
|
| 26 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function getDeletedAtAttribute($value) |
|
| 30 | - { |
|
| 31 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | - } |
|
| 29 | + public function getDeletedAtAttribute($value) |
|
| 30 | + { |
|
| 31 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function roles() |
|
| 35 | - { |
|
| 36 | - return $this->belongsToMany(Role::class, 'permission_role', 'permission_id', 'role_id')->whereNull('permission_role.deleted_at')->withTimestamps(); |
|
| 37 | - } |
|
| 34 | + public function roles() |
|
| 35 | + { |
|
| 36 | + return $this->belongsToMany(Role::class, 'permission_role', 'permission_id', 'role_id')->whereNull('permission_role.deleted_at')->withTimestamps(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public static function boot() |
|
| 40 | - { |
|
| 41 | - parent::boot(); |
|
| 42 | - Permission::observe(PermissionObserver::class); |
|
| 43 | - } |
|
| 39 | + public static function boot() |
|
| 40 | + { |
|
| 41 | + parent::boot(); |
|
| 42 | + Permission::observe(PermissionObserver::class); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -8,48 +8,48 @@ |
||
| 8 | 8 | class PushNotificationDevice extends Model |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - use SoftDeletes; |
|
| 12 | - protected $table = 'push_notification_devices'; |
|
| 13 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | - protected $hidden = ['deleted_at', 'access_token']; |
|
| 15 | - protected $guarded = ['id']; |
|
| 16 | - protected $fillable = ['device_token', 'user_id', 'access_token']; |
|
| 17 | - public $searchable = ['device_token']; |
|
| 18 | - |
|
| 19 | - public function getCreatedAtAttribute($value) |
|
| 20 | - { |
|
| 21 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function getUpdatedAtAttribute($value) |
|
| 25 | - { |
|
| 26 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function getDeletedAtAttribute($value) |
|
| 30 | - { |
|
| 31 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | - } |
|
| 11 | + use SoftDeletes; |
|
| 12 | + protected $table = 'push_notification_devices'; |
|
| 13 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | + protected $hidden = ['deleted_at', 'access_token']; |
|
| 15 | + protected $guarded = ['id']; |
|
| 16 | + protected $fillable = ['device_token', 'user_id', 'access_token']; |
|
| 17 | + public $searchable = ['device_token']; |
|
| 18 | + |
|
| 19 | + public function getCreatedAtAttribute($value) |
|
| 20 | + { |
|
| 21 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function getUpdatedAtAttribute($value) |
|
| 25 | + { |
|
| 26 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function getDeletedAtAttribute($value) |
|
| 30 | + { |
|
| 31 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function user() |
|
| 35 | - { |
|
| 36 | - return $this->belongsTo(AclUser::class); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Encrypt the access_token attribute before |
|
| 41 | - * saving it in the storage. |
|
| 42 | - * |
|
| 43 | - * @param string $value |
|
| 44 | - */ |
|
| 45 | - public function setLoginTokenAttribute($value) |
|
| 46 | - { |
|
| 47 | - $this->attributes['access_token'] = encrypt($value); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public static function boot() |
|
| 51 | - { |
|
| 52 | - parent::boot(); |
|
| 53 | - PushNotificationDevice::observe(PushNotificationDeviceObserver::class); |
|
| 54 | - } |
|
| 34 | + public function user() |
|
| 35 | + { |
|
| 36 | + return $this->belongsTo(AclUser::class); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Encrypt the access_token attribute before |
|
| 41 | + * saving it in the storage. |
|
| 42 | + * |
|
| 43 | + * @param string $value |
|
| 44 | + */ |
|
| 45 | + public function setLoginTokenAttribute($value) |
|
| 46 | + { |
|
| 47 | + $this->attributes['access_token'] = encrypt($value); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public static function boot() |
|
| 51 | + { |
|
| 52 | + parent::boot(); |
|
| 53 | + PushNotificationDevice::observe(PushNotificationDeviceObserver::class); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -11,68 +11,68 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CheckPermissions |
| 13 | 13 | { |
| 14 | - protected $route; |
|
| 15 | - protected $auth; |
|
| 16 | - protected $authMiddleware; |
|
| 17 | - protected $userService; |
|
| 18 | - protected $arr; |
|
| 14 | + protected $route; |
|
| 15 | + protected $auth; |
|
| 16 | + protected $authMiddleware; |
|
| 17 | + protected $userService; |
|
| 18 | + protected $arr; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Init new object. |
|
| 22 | - * |
|
| 23 | - * @param Route $route |
|
| 24 | - * @param Auth $auth |
|
| 25 | - * @param AuthMiddleware $authMiddleware |
|
| 26 | - * @param UserService $userService |
|
| 27 | - * @param Arr $arr |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function __construct(Route $route, Auth $auth, AuthMiddleware $authMiddleware, UserService $userService, Arr $arr) |
|
| 32 | - { |
|
| 33 | - $this->route = $route; |
|
| 34 | - $this->auth = $auth; |
|
| 35 | - $this->authMiddleware = $authMiddleware; |
|
| 36 | - $this->userService = $userService; |
|
| 37 | - $this->arr = $arr; |
|
| 38 | - } |
|
| 20 | + /** |
|
| 21 | + * Init new object. |
|
| 22 | + * |
|
| 23 | + * @param Route $route |
|
| 24 | + * @param Auth $auth |
|
| 25 | + * @param AuthMiddleware $authMiddleware |
|
| 26 | + * @param UserService $userService |
|
| 27 | + * @param Arr $arr |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function __construct(Route $route, Auth $auth, AuthMiddleware $authMiddleware, UserService $userService, Arr $arr) |
|
| 32 | + { |
|
| 33 | + $this->route = $route; |
|
| 34 | + $this->auth = $auth; |
|
| 35 | + $this->authMiddleware = $authMiddleware; |
|
| 36 | + $this->userService = $userService; |
|
| 37 | + $this->arr = $arr; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Handle an incoming request. |
|
| 42 | - * |
|
| 43 | - * @param \Illuminate\Http\Request $request |
|
| 44 | - * @param \Closure $next |
|
| 45 | - * @return mixed |
|
| 46 | - */ |
|
| 47 | - public function handle($request, Closure $next) |
|
| 48 | - { |
|
| 49 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 50 | - $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 51 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 52 | - $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 53 | - $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 54 | - $modelName = explode('\\', $routeActions[0]); |
|
| 55 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 56 | - $permission = $routeActions[1]; |
|
| 40 | + /** |
|
| 41 | + * Handle an incoming request. |
|
| 42 | + * |
|
| 43 | + * @param \Illuminate\Http\Request $request |
|
| 44 | + * @param \Closure $next |
|
| 45 | + * @return mixed |
|
| 46 | + */ |
|
| 47 | + public function handle($request, Closure $next) |
|
| 48 | + { |
|
| 49 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 50 | + $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 51 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 52 | + $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 53 | + $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 54 | + $modelName = explode('\\', $routeActions[0]); |
|
| 55 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 56 | + $permission = $routeActions[1]; |
|
| 57 | 57 | |
| 58 | - $this->auth->shouldUse('api'); |
|
| 59 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 61 | - $user = $this->auth->user(); |
|
| 62 | - $isPasswordClient = $user->token()->client->password_client; |
|
| 58 | + $this->auth->shouldUse('api'); |
|
| 59 | + if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | + $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 61 | + $user = $this->auth->user(); |
|
| 62 | + $isPasswordClient = $user->token()->client->password_client; |
|
| 63 | 63 | |
| 64 | - if ($user->blocked) { |
|
| 65 | - \Errors::userIsBlocked(); |
|
| 66 | - } |
|
| 64 | + if ($user->blocked) { |
|
| 65 | + \Errors::userIsBlocked(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
|
| 69 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | - } else { |
|
| 71 | - \Errors::noPermissions(); |
|
| 72 | - } |
|
| 73 | - }); |
|
| 74 | - } |
|
| 68 | + if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
|
| 69 | + } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | + } else { |
|
| 71 | + \Errors::noPermissions(); |
|
| 72 | + } |
|
| 73 | + }); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return $next($request); |
|
| 77 | - } |
|
| 76 | + return $next($request); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | $permission = $routeActions[1]; |
| 57 | 57 | |
| 58 | 58 | $this->auth->shouldUse('api'); |
| 59 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 59 | + if ( ! in_array($permission, $skipLoginCheck)) { |
|
| 60 | + $this->authMiddleware->handle($request, function($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 61 | 61 | $user = $this->auth->user(); |
| 62 | 62 | $isPasswordClient = $user->token()->client->password_client; |
| 63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
| 69 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 69 | + } elseif ( ! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | 70 | } else { |
| 71 | 71 | \Errors::noPermissions(); |
| 72 | 72 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Errors extends Facade |
| 6 | 6 | { |
| 7 | - protected static function getFacadeAccessor() |
|
| 8 | - { |
|
| 9 | - return 'Errors'; |
|
| 10 | - } |
|
| 7 | + protected static function getFacadeAccessor() |
|
| 8 | + { |
|
| 9 | + return 'Errors'; |
|
| 10 | + } |
|
| 11 | 11 | } |
@@ -2,123 +2,123 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Errors |
| 4 | 4 | { |
| 5 | - public function unAuthorized() |
|
| 6 | - { |
|
| 7 | - $error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')]; |
|
| 8 | - abort($error['status'], $error['message']); |
|
| 9 | - } |
|
| 10 | - |
|
| 11 | - public function invalidRefreshToken() |
|
| 12 | - { |
|
| 13 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')]; |
|
| 14 | - abort($error['status'], $error['message']); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - public function noPermissions() |
|
| 18 | - { |
|
| 19 | - $error = ['status' => 403, 'message' => trans('core::errors.noPermissions')]; |
|
| 20 | - abort($error['status'], $error['message']); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function loginFailed() |
|
| 24 | - { |
|
| 25 | - $error = ['status' => 400, 'message' => trans('core::errors.loginFailed')]; |
|
| 26 | - abort($error['status'], $error['message']); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function noSocialEmail() |
|
| 30 | - { |
|
| 31 | - $error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')]; |
|
| 32 | - abort($error['status'], $error['message']); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function userAlreadyRegistered() |
|
| 36 | - { |
|
| 37 | - $error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')]; |
|
| 38 | - abort($error['status'], $error['message']); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function connectionError() |
|
| 42 | - { |
|
| 43 | - $error = ['status' => 400, 'message' => trans('core::errors.connectionError')]; |
|
| 44 | - abort($error['status'], $error['message']); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function redisNotRunning() |
|
| 48 | - { |
|
| 49 | - $error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')]; |
|
| 50 | - abort($error['status'], $error['message']); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function dbQueryError() |
|
| 54 | - { |
|
| 55 | - $error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')]; |
|
| 56 | - abort($error['status'], $error['message']); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function cannotCreateSetting() |
|
| 60 | - { |
|
| 61 | - $error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')]; |
|
| 62 | - abort($error['status'], $error['message']); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function cannotUpdateSettingKey() |
|
| 66 | - { |
|
| 67 | - $error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')]; |
|
| 68 | - abort($error['status'], $error['message']); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function userIsBlocked() |
|
| 72 | - { |
|
| 73 | - $error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')]; |
|
| 74 | - abort($error['status'], $error['message']); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function emailNotConfirmed() |
|
| 78 | - { |
|
| 79 | - $error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')]; |
|
| 80 | - abort($error['status'], $error['message']); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function emailAlreadyConfirmed() |
|
| 84 | - { |
|
| 85 | - $error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')]; |
|
| 86 | - abort($error['status'], $error['message']); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function invalidResetToken() |
|
| 90 | - { |
|
| 91 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')]; |
|
| 92 | - abort($error['status'], $error['message']); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function invalidResetPassword() |
|
| 96 | - { |
|
| 97 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')]; |
|
| 98 | - abort($error['status'], $error['message']); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function invalidOldPassword() |
|
| 102 | - { |
|
| 103 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')]; |
|
| 104 | - abort($error['status'], $error['message']); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function invalidConfirmationCode() |
|
| 108 | - { |
|
| 109 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | - abort($error['status'], $error['message']); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function notFound($text) |
|
| 114 | - { |
|
| 115 | - $error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])]; |
|
| 116 | - abort($error['status'], $error['message']); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function generalError() |
|
| 120 | - { |
|
| 121 | - $error = ['status' => 400, 'message' => trans('core::errors.generalError')]; |
|
| 122 | - abort($error['status'], $error['message']); |
|
| 123 | - } |
|
| 5 | + public function unAuthorized() |
|
| 6 | + { |
|
| 7 | + $error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')]; |
|
| 8 | + abort($error['status'], $error['message']); |
|
| 9 | + } |
|
| 10 | + |
|
| 11 | + public function invalidRefreshToken() |
|
| 12 | + { |
|
| 13 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')]; |
|
| 14 | + abort($error['status'], $error['message']); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + public function noPermissions() |
|
| 18 | + { |
|
| 19 | + $error = ['status' => 403, 'message' => trans('core::errors.noPermissions')]; |
|
| 20 | + abort($error['status'], $error['message']); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function loginFailed() |
|
| 24 | + { |
|
| 25 | + $error = ['status' => 400, 'message' => trans('core::errors.loginFailed')]; |
|
| 26 | + abort($error['status'], $error['message']); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function noSocialEmail() |
|
| 30 | + { |
|
| 31 | + $error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')]; |
|
| 32 | + abort($error['status'], $error['message']); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function userAlreadyRegistered() |
|
| 36 | + { |
|
| 37 | + $error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')]; |
|
| 38 | + abort($error['status'], $error['message']); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function connectionError() |
|
| 42 | + { |
|
| 43 | + $error = ['status' => 400, 'message' => trans('core::errors.connectionError')]; |
|
| 44 | + abort($error['status'], $error['message']); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function redisNotRunning() |
|
| 48 | + { |
|
| 49 | + $error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')]; |
|
| 50 | + abort($error['status'], $error['message']); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function dbQueryError() |
|
| 54 | + { |
|
| 55 | + $error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')]; |
|
| 56 | + abort($error['status'], $error['message']); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function cannotCreateSetting() |
|
| 60 | + { |
|
| 61 | + $error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')]; |
|
| 62 | + abort($error['status'], $error['message']); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function cannotUpdateSettingKey() |
|
| 66 | + { |
|
| 67 | + $error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')]; |
|
| 68 | + abort($error['status'], $error['message']); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function userIsBlocked() |
|
| 72 | + { |
|
| 73 | + $error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')]; |
|
| 74 | + abort($error['status'], $error['message']); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function emailNotConfirmed() |
|
| 78 | + { |
|
| 79 | + $error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')]; |
|
| 80 | + abort($error['status'], $error['message']); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function emailAlreadyConfirmed() |
|
| 84 | + { |
|
| 85 | + $error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')]; |
|
| 86 | + abort($error['status'], $error['message']); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function invalidResetToken() |
|
| 90 | + { |
|
| 91 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')]; |
|
| 92 | + abort($error['status'], $error['message']); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function invalidResetPassword() |
|
| 96 | + { |
|
| 97 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')]; |
|
| 98 | + abort($error['status'], $error['message']); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function invalidOldPassword() |
|
| 102 | + { |
|
| 103 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')]; |
|
| 104 | + abort($error['status'], $error['message']); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function invalidConfirmationCode() |
|
| 108 | + { |
|
| 109 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | + abort($error['status'], $error['message']); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function notFound($text) |
|
| 114 | + { |
|
| 115 | + $error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])]; |
|
| 116 | + abort($error['status'], $error['message']); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function generalError() |
|
| 120 | + { |
|
| 121 | + $error = ['status' => 400, 'message' => trans('core::errors.generalError')]; |
|
| 122 | + abort($error['status'], $error['message']); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -6,53 +6,53 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ModuleServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Bootstrap the module services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 18 | - |
|
| 19 | - $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
| 20 | - $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Register the module services. |
|
| 25 | - * |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function register() |
|
| 29 | - { |
|
| 30 | - //Bind Core Facade to the Service Container |
|
| 31 | - $this->app->singleton('Core', function () { |
|
| 32 | - return new \App\Modules\Core\Core; |
|
| 33 | - }); |
|
| 34 | - |
|
| 35 | - //Bind Errors Facade to the Service Container |
|
| 36 | - $this->app->singleton('Errors', function () { |
|
| 37 | - return new \App\Modules\Core\Utl\Errors; |
|
| 38 | - }); |
|
| 39 | - |
|
| 40 | - //Bind CoreConfig Facade to the Service Container |
|
| 41 | - $this->app->singleton('CoreConfig', function () { |
|
| 42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
| 43 | - }); |
|
| 44 | - |
|
| 45 | - //Bind Media Facade to the Service Container |
|
| 46 | - $this->app->singleton('Media', function () { |
|
| 47 | - return new \App\Modules\Core\Utl\Media; |
|
| 48 | - }); |
|
| 49 | - |
|
| 50 | - //Bind ApiConsumer Facade to the Service Container |
|
| 51 | - $this->app->singleton('ApiConsumer', function () { |
|
| 52 | - $app = app(); |
|
| 53 | - return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
| 54 | - }); |
|
| 9 | + /** |
|
| 10 | + * Bootstrap the module services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 18 | + |
|
| 19 | + $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
| 20 | + $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Register the module services. |
|
| 25 | + * |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function register() |
|
| 29 | + { |
|
| 30 | + //Bind Core Facade to the Service Container |
|
| 31 | + $this->app->singleton('Core', function () { |
|
| 32 | + return new \App\Modules\Core\Core; |
|
| 33 | + }); |
|
| 34 | + |
|
| 35 | + //Bind Errors Facade to the Service Container |
|
| 36 | + $this->app->singleton('Errors', function () { |
|
| 37 | + return new \App\Modules\Core\Utl\Errors; |
|
| 38 | + }); |
|
| 39 | + |
|
| 40 | + //Bind CoreConfig Facade to the Service Container |
|
| 41 | + $this->app->singleton('CoreConfig', function () { |
|
| 42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
| 43 | + }); |
|
| 44 | + |
|
| 45 | + //Bind Media Facade to the Service Container |
|
| 46 | + $this->app->singleton('Media', function () { |
|
| 47 | + return new \App\Modules\Core\Utl\Media; |
|
| 48 | + }); |
|
| 49 | + |
|
| 50 | + //Bind ApiConsumer Facade to the Service Container |
|
| 51 | + $this->app->singleton('ApiConsumer', function () { |
|
| 52 | + $app = app(); |
|
| 53 | + return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
| 54 | + }); |
|
| 55 | 55 | |
| 56 | - $this->app->register(RouteServiceProvider::class); |
|
| 57 | - } |
|
| 56 | + $this->app->register(RouteServiceProvider::class); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -28,27 +28,27 @@ |
||
| 28 | 28 | public function register() |
| 29 | 29 | { |
| 30 | 30 | //Bind Core Facade to the Service Container |
| 31 | - $this->app->singleton('Core', function () { |
|
| 31 | + $this->app->singleton('Core', function() { |
|
| 32 | 32 | return new \App\Modules\Core\Core; |
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | 35 | //Bind Errors Facade to the Service Container |
| 36 | - $this->app->singleton('Errors', function () { |
|
| 36 | + $this->app->singleton('Errors', function() { |
|
| 37 | 37 | return new \App\Modules\Core\Utl\Errors; |
| 38 | 38 | }); |
| 39 | 39 | |
| 40 | 40 | //Bind CoreConfig Facade to the Service Container |
| 41 | - $this->app->singleton('CoreConfig', function () { |
|
| 41 | + $this->app->singleton('CoreConfig', function() { |
|
| 42 | 42 | return new \App\Modules\Core\Utl\CoreConfig; |
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | 45 | //Bind Media Facade to the Service Container |
| 46 | - $this->app->singleton('Media', function () { |
|
| 46 | + $this->app->singleton('Media', function() { |
|
| 47 | 47 | return new \App\Modules\Core\Utl\Media; |
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | //Bind ApiConsumer Facade to the Service Container |
| 51 | - $this->app->singleton('ApiConsumer', function () { |
|
| 51 | + $this->app->singleton('ApiConsumer', function() { |
|
| 52 | 52 | $app = app(); |
| 53 | 53 | return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
| 54 | 54 | }); |
@@ -10,240 +10,240 @@ |
||
| 10 | 10 | |
| 11 | 11 | class MakeModuleCommand extends Command |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The name and signature of the console command. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - protected $signature = 'generate:module |
|
| 13 | + /** |
|
| 14 | + * The name and signature of the console command. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + protected $signature = 'generate:module |
|
| 19 | 19 | {slug : The slug of the module}'; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The console command description. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $description = 'Create a new module'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The modules instance. |
|
| 30 | - * |
|
| 31 | - * @var RepositoryManager |
|
| 32 | - */ |
|
| 33 | - protected $module; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The filesystem instance. |
|
| 37 | - * |
|
| 38 | - * @var Filesystem |
|
| 39 | - */ |
|
| 40 | - protected $files; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Array to store the configuration details. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $container; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Array of folder mappings. |
|
| 51 | - * |
|
| 52 | - * @var Array |
|
| 53 | - */ |
|
| 54 | - protected $mapping = [ |
|
| 55 | - 'Database/Factories' => 'Database/Factories', |
|
| 56 | - 'Database/Migrations' => 'Database/Migrations', |
|
| 57 | - 'Database/Seeds' => 'Database/Seeds', |
|
| 58 | - 'Http/Controllers' => 'Http/Controllers', |
|
| 59 | - 'Http/Requests' => 'Http/Requests', |
|
| 60 | - 'Http/Resources' => 'Http/Resources', |
|
| 61 | - 'ModelObservers' => 'ModelObservers', |
|
| 62 | - 'Providers' => 'Providers', |
|
| 63 | - 'Repositories' => 'Repositories', |
|
| 64 | - 'Services' => 'Services', |
|
| 65 | - 'Routes' => 'Routes' |
|
| 66 | - ]; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Create a new command instance. |
|
| 70 | - * |
|
| 71 | - * @param Filesystem $files |
|
| 72 | - * @param RepositoryManager $module |
|
| 73 | - */ |
|
| 74 | - public function __construct(Filesystem $files, RepositoryManager $module) |
|
| 75 | - { |
|
| 76 | - parent::__construct(); |
|
| 77 | - |
|
| 78 | - $this->files = $files; |
|
| 79 | - $this->module = $module; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Execute the console command. |
|
| 84 | - * |
|
| 85 | - * @return mixed |
|
| 86 | - */ |
|
| 87 | - public function handle() |
|
| 88 | - { |
|
| 89 | - $this->container['slug'] = Str::slug($this->argument('slug')); |
|
| 90 | - $this->container['name'] = Str::studly($this->container['slug']); |
|
| 91 | - $this->container['version'] = '1.0'; |
|
| 92 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 93 | - $this->container['location'] = config('modules.default_location'); |
|
| 94 | - $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
| 95 | - $this->container['basename'] = Str::studly($this->container['slug']); |
|
| 96 | - $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
| 97 | - |
|
| 98 | - return $this->generate(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Generate the module. |
|
| 103 | - */ |
|
| 104 | - protected function generate() |
|
| 105 | - { |
|
| 106 | - $steps = [ |
|
| 107 | - 'Generating module...' => 'generateModule', |
|
| 108 | - 'Optimizing module cache...' => 'optimizeModules', |
|
| 109 | - 'Generating migrations...' => 'generateMigration', |
|
| 110 | - ]; |
|
| 111 | - |
|
| 112 | - $progress = new ProgressBar($this->output, count($steps)); |
|
| 113 | - $progress->start(); |
|
| 114 | - |
|
| 115 | - foreach ($steps as $message => $function) { |
|
| 116 | - $progress->setMessage($message); |
|
| 117 | - |
|
| 118 | - $this->$function(); |
|
| 119 | - |
|
| 120 | - $progress->advance(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $progress->finish(); |
|
| 124 | - |
|
| 125 | - event($this->container['slug'] . '.module.made'); |
|
| 126 | - |
|
| 127 | - $this->info("\nModule generated successfully."); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Generate defined module folders. |
|
| 132 | - */ |
|
| 133 | - protected function generateModule() |
|
| 134 | - { |
|
| 135 | - $location = $this->container['location']; |
|
| 136 | - $root = module_path(null, '', $location); |
|
| 137 | - $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
| 138 | - $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
| 139 | - |
|
| 140 | - if (!$this->files->isDirectory($root)) { |
|
| 141 | - $this->files->makeDirectory($root); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $directory = module_path(null, $this->container['basename'], $location); |
|
| 145 | - $source = __DIR__ . '/Stubs/Module'; |
|
| 146 | - |
|
| 147 | - $this->files->makeDirectory($directory); |
|
| 148 | - |
|
| 149 | - $sourceFiles = $this->files->allFiles($source, true); |
|
| 150 | - |
|
| 151 | - if (!empty($this->mapping)) { |
|
| 152 | - $search = array_keys($this->mapping); |
|
| 153 | - $replace = array_values($this->mapping); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - foreach ($sourceFiles as $file) { |
|
| 157 | - $contents = $this->replacePlaceholders($file->getContents()); |
|
| 158 | - $subPath = $file->getRelativePathname(); |
|
| 159 | - |
|
| 160 | - if (!empty($this->mapping)) { |
|
| 161 | - $subPath = str_replace($search, $replace, $subPath); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $filePath = $directory . '/' . $subPath; |
|
| 21 | + /** |
|
| 22 | + * The console command description. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $description = 'Create a new module'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The modules instance. |
|
| 30 | + * |
|
| 31 | + * @var RepositoryManager |
|
| 32 | + */ |
|
| 33 | + protected $module; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The filesystem instance. |
|
| 37 | + * |
|
| 38 | + * @var Filesystem |
|
| 39 | + */ |
|
| 40 | + protected $files; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Array to store the configuration details. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $container; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Array of folder mappings. |
|
| 51 | + * |
|
| 52 | + * @var Array |
|
| 53 | + */ |
|
| 54 | + protected $mapping = [ |
|
| 55 | + 'Database/Factories' => 'Database/Factories', |
|
| 56 | + 'Database/Migrations' => 'Database/Migrations', |
|
| 57 | + 'Database/Seeds' => 'Database/Seeds', |
|
| 58 | + 'Http/Controllers' => 'Http/Controllers', |
|
| 59 | + 'Http/Requests' => 'Http/Requests', |
|
| 60 | + 'Http/Resources' => 'Http/Resources', |
|
| 61 | + 'ModelObservers' => 'ModelObservers', |
|
| 62 | + 'Providers' => 'Providers', |
|
| 63 | + 'Repositories' => 'Repositories', |
|
| 64 | + 'Services' => 'Services', |
|
| 65 | + 'Routes' => 'Routes' |
|
| 66 | + ]; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Create a new command instance. |
|
| 70 | + * |
|
| 71 | + * @param Filesystem $files |
|
| 72 | + * @param RepositoryManager $module |
|
| 73 | + */ |
|
| 74 | + public function __construct(Filesystem $files, RepositoryManager $module) |
|
| 75 | + { |
|
| 76 | + parent::__construct(); |
|
| 77 | + |
|
| 78 | + $this->files = $files; |
|
| 79 | + $this->module = $module; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Execute the console command. |
|
| 84 | + * |
|
| 85 | + * @return mixed |
|
| 86 | + */ |
|
| 87 | + public function handle() |
|
| 88 | + { |
|
| 89 | + $this->container['slug'] = Str::slug($this->argument('slug')); |
|
| 90 | + $this->container['name'] = Str::studly($this->container['slug']); |
|
| 91 | + $this->container['version'] = '1.0'; |
|
| 92 | + $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 93 | + $this->container['location'] = config('modules.default_location'); |
|
| 94 | + $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
| 95 | + $this->container['basename'] = Str::studly($this->container['slug']); |
|
| 96 | + $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
| 97 | + |
|
| 98 | + return $this->generate(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Generate the module. |
|
| 103 | + */ |
|
| 104 | + protected function generate() |
|
| 105 | + { |
|
| 106 | + $steps = [ |
|
| 107 | + 'Generating module...' => 'generateModule', |
|
| 108 | + 'Optimizing module cache...' => 'optimizeModules', |
|
| 109 | + 'Generating migrations...' => 'generateMigration', |
|
| 110 | + ]; |
|
| 111 | + |
|
| 112 | + $progress = new ProgressBar($this->output, count($steps)); |
|
| 113 | + $progress->start(); |
|
| 114 | + |
|
| 115 | + foreach ($steps as $message => $function) { |
|
| 116 | + $progress->setMessage($message); |
|
| 117 | + |
|
| 118 | + $this->$function(); |
|
| 119 | + |
|
| 120 | + $progress->advance(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $progress->finish(); |
|
| 124 | + |
|
| 125 | + event($this->container['slug'] . '.module.made'); |
|
| 126 | + |
|
| 127 | + $this->info("\nModule generated successfully."); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Generate defined module folders. |
|
| 132 | + */ |
|
| 133 | + protected function generateModule() |
|
| 134 | + { |
|
| 135 | + $location = $this->container['location']; |
|
| 136 | + $root = module_path(null, '', $location); |
|
| 137 | + $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
| 138 | + $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
| 139 | + |
|
| 140 | + if (!$this->files->isDirectory($root)) { |
|
| 141 | + $this->files->makeDirectory($root); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $directory = module_path(null, $this->container['basename'], $location); |
|
| 145 | + $source = __DIR__ . '/Stubs/Module'; |
|
| 146 | + |
|
| 147 | + $this->files->makeDirectory($directory); |
|
| 148 | + |
|
| 149 | + $sourceFiles = $this->files->allFiles($source, true); |
|
| 150 | + |
|
| 151 | + if (!empty($this->mapping)) { |
|
| 152 | + $search = array_keys($this->mapping); |
|
| 153 | + $replace = array_values($this->mapping); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + foreach ($sourceFiles as $file) { |
|
| 157 | + $contents = $this->replacePlaceholders($file->getContents()); |
|
| 158 | + $subPath = $file->getRelativePathname(); |
|
| 159 | + |
|
| 160 | + if (!empty($this->mapping)) { |
|
| 161 | + $subPath = str_replace($search, $replace, $subPath); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $filePath = $directory . '/' . $subPath; |
|
| 165 | 165 | |
| 166 | - // if the file is module.json, replace it with the custom manifest file name |
|
| 167 | - if ($file->getFilename() === 'module.json' && $manifest) { |
|
| 168 | - $filePath = str_replace('module.json', $manifest, $filePath); |
|
| 169 | - } |
|
| 166 | + // if the file is module.json, replace it with the custom manifest file name |
|
| 167 | + if ($file->getFilename() === 'module.json' && $manifest) { |
|
| 168 | + $filePath = str_replace('module.json', $manifest, $filePath); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
| 172 | - if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
| 173 | - $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
| 174 | - } |
|
| 175 | - $filePath = $this->replacePlaceholders($filePath); |
|
| 171 | + // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
| 172 | + if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
| 173 | + $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
| 174 | + } |
|
| 175 | + $filePath = $this->replacePlaceholders($filePath); |
|
| 176 | 176 | |
| 177 | - $dir = dirname($filePath); |
|
| 177 | + $dir = dirname($filePath); |
|
| 178 | 178 | |
| 179 | - if (! $this->files->isDirectory($dir)) { |
|
| 180 | - $this->files->makeDirectory($dir, 0755, true); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $this->files->put($filePath, $contents); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - protected function replacePlaceholders($contents) |
|
| 188 | - { |
|
| 189 | - $modelName = \Str::camel($this->container['slug']); |
|
| 190 | - $modelNameSingular = \Str::singular($modelName); |
|
| 191 | - |
|
| 192 | - $find = [ |
|
| 193 | - 'DummyFactory', |
|
| 194 | - 'DummyModelName', |
|
| 195 | - 'DummyModuleSlug', |
|
| 196 | - 'DummyModule', |
|
| 197 | - 'DummyModel', |
|
| 198 | - 'DummyDatabaseSeeder', |
|
| 199 | - 'DummyTableSeeder', |
|
| 200 | - 'DummyController', |
|
| 201 | - 'DummyService', |
|
| 202 | - 'DummyRepository', |
|
| 203 | - 'InsertDummy', |
|
| 204 | - 'UpdateDummy', |
|
| 205 | - 'DummyResource', |
|
| 206 | - 'DummyObserver', |
|
| 207 | - 'DummyTableName', |
|
| 208 | - 'DummyRoutePrefix', |
|
| 209 | - ]; |
|
| 210 | - |
|
| 211 | - $replace = [ |
|
| 212 | - ucfirst($modelNameSingular) . 'Factory', |
|
| 213 | - $modelNameSingular, |
|
| 214 | - $this->container['slug'], |
|
| 215 | - ucfirst($modelName), |
|
| 216 | - ucfirst($modelNameSingular), |
|
| 217 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
| 218 | - ucfirst($modelName) . 'TableSeeder', |
|
| 219 | - ucfirst($modelNameSingular) . 'Controller', |
|
| 220 | - ucfirst($modelNameSingular) . 'Service', |
|
| 221 | - ucfirst($modelNameSingular) . 'Repository', |
|
| 222 | - 'Insert' . ucfirst($modelNameSingular), |
|
| 223 | - 'Update' . ucfirst($modelNameSingular), |
|
| 224 | - ucfirst($modelNameSingular), |
|
| 225 | - ucfirst($modelNameSingular) . 'Observer', |
|
| 226 | - $modelName, |
|
| 227 | - $modelName, |
|
| 228 | - ]; |
|
| 229 | - |
|
| 230 | - return str_replace($find, $replace, $contents); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Reset module cache of enabled and disabled modules. |
|
| 235 | - */ |
|
| 236 | - protected function optimizeModules() |
|
| 237 | - { |
|
| 238 | - return $this->callSilent('module:optimize'); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Generate table migrations. |
|
| 243 | - */ |
|
| 244 | - protected function generateMigration() |
|
| 245 | - { |
|
| 246 | - $modelName = $this->container['slug']; |
|
| 247 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 248 | - } |
|
| 179 | + if (! $this->files->isDirectory($dir)) { |
|
| 180 | + $this->files->makeDirectory($dir, 0755, true); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $this->files->put($filePath, $contents); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + protected function replacePlaceholders($contents) |
|
| 188 | + { |
|
| 189 | + $modelName = \Str::camel($this->container['slug']); |
|
| 190 | + $modelNameSingular = \Str::singular($modelName); |
|
| 191 | + |
|
| 192 | + $find = [ |
|
| 193 | + 'DummyFactory', |
|
| 194 | + 'DummyModelName', |
|
| 195 | + 'DummyModuleSlug', |
|
| 196 | + 'DummyModule', |
|
| 197 | + 'DummyModel', |
|
| 198 | + 'DummyDatabaseSeeder', |
|
| 199 | + 'DummyTableSeeder', |
|
| 200 | + 'DummyController', |
|
| 201 | + 'DummyService', |
|
| 202 | + 'DummyRepository', |
|
| 203 | + 'InsertDummy', |
|
| 204 | + 'UpdateDummy', |
|
| 205 | + 'DummyResource', |
|
| 206 | + 'DummyObserver', |
|
| 207 | + 'DummyTableName', |
|
| 208 | + 'DummyRoutePrefix', |
|
| 209 | + ]; |
|
| 210 | + |
|
| 211 | + $replace = [ |
|
| 212 | + ucfirst($modelNameSingular) . 'Factory', |
|
| 213 | + $modelNameSingular, |
|
| 214 | + $this->container['slug'], |
|
| 215 | + ucfirst($modelName), |
|
| 216 | + ucfirst($modelNameSingular), |
|
| 217 | + ucfirst($modelName) . 'DatabaseSeeder', |
|
| 218 | + ucfirst($modelName) . 'TableSeeder', |
|
| 219 | + ucfirst($modelNameSingular) . 'Controller', |
|
| 220 | + ucfirst($modelNameSingular) . 'Service', |
|
| 221 | + ucfirst($modelNameSingular) . 'Repository', |
|
| 222 | + 'Insert' . ucfirst($modelNameSingular), |
|
| 223 | + 'Update' . ucfirst($modelNameSingular), |
|
| 224 | + ucfirst($modelNameSingular), |
|
| 225 | + ucfirst($modelNameSingular) . 'Observer', |
|
| 226 | + $modelName, |
|
| 227 | + $modelName, |
|
| 228 | + ]; |
|
| 229 | + |
|
| 230 | + return str_replace($find, $replace, $contents); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Reset module cache of enabled and disabled modules. |
|
| 235 | + */ |
|
| 236 | + protected function optimizeModules() |
|
| 237 | + { |
|
| 238 | + return $this->callSilent('module:optimize'); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Generate table migrations. |
|
| 243 | + */ |
|
| 244 | + protected function generateMigration() |
|
| 245 | + { |
|
| 246 | + $modelName = $this->container['slug']; |
|
| 247 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $this->container['slug'] = Str::slug($this->argument('slug')); |
| 90 | 90 | $this->container['name'] = Str::studly($this->container['slug']); |
| 91 | 91 | $this->container['version'] = '1.0'; |
| 92 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 92 | + $this->container['description'] = 'This is the description for the '.$this->container['name'].' module.'; |
|
| 93 | 93 | $this->container['location'] = config('modules.default_location'); |
| 94 | 94 | $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
| 95 | 95 | $this->container['basename'] = Str::studly($this->container['slug']); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | $progress->finish(); |
| 124 | 124 | |
| 125 | - event($this->container['slug'] . '.module.made'); |
|
| 125 | + event($this->container['slug'].'.module.made'); |
|
| 126 | 126 | |
| 127 | 127 | $this->info("\nModule generated successfully."); |
| 128 | 128 | } |
@@ -137,18 +137,18 @@ discard block |
||
| 137 | 137 | $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
| 138 | 138 | $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
| 139 | 139 | |
| 140 | - if (!$this->files->isDirectory($root)) { |
|
| 140 | + if ( ! $this->files->isDirectory($root)) { |
|
| 141 | 141 | $this->files->makeDirectory($root); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $directory = module_path(null, $this->container['basename'], $location); |
| 145 | - $source = __DIR__ . '/Stubs/Module'; |
|
| 145 | + $source = __DIR__.'/Stubs/Module'; |
|
| 146 | 146 | |
| 147 | 147 | $this->files->makeDirectory($directory); |
| 148 | 148 | |
| 149 | 149 | $sourceFiles = $this->files->allFiles($source, true); |
| 150 | 150 | |
| 151 | - if (!empty($this->mapping)) { |
|
| 151 | + if ( ! empty($this->mapping)) { |
|
| 152 | 152 | $search = array_keys($this->mapping); |
| 153 | 153 | $replace = array_values($this->mapping); |
| 154 | 154 | } |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | $contents = $this->replacePlaceholders($file->getContents()); |
| 158 | 158 | $subPath = $file->getRelativePathname(); |
| 159 | 159 | |
| 160 | - if (!empty($this->mapping)) { |
|
| 160 | + if ( ! empty($this->mapping)) { |
|
| 161 | 161 | $subPath = str_replace($search, $replace, $subPath); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $filePath = $directory . '/' . $subPath; |
|
| 164 | + $filePath = $directory.'/'.$subPath; |
|
| 165 | 165 | |
| 166 | 166 | // if the file is module.json, replace it with the custom manifest file name |
| 167 | 167 | if ($file->getFilename() === 'module.json' && $manifest) { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $dir = dirname($filePath); |
| 178 | 178 | |
| 179 | - if (! $this->files->isDirectory($dir)) { |
|
| 179 | + if ( ! $this->files->isDirectory($dir)) { |
|
| 180 | 180 | $this->files->makeDirectory($dir, 0755, true); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -209,20 +209,20 @@ discard block |
||
| 209 | 209 | ]; |
| 210 | 210 | |
| 211 | 211 | $replace = [ |
| 212 | - ucfirst($modelNameSingular) . 'Factory', |
|
| 212 | + ucfirst($modelNameSingular).'Factory', |
|
| 213 | 213 | $modelNameSingular, |
| 214 | 214 | $this->container['slug'], |
| 215 | 215 | ucfirst($modelName), |
| 216 | 216 | ucfirst($modelNameSingular), |
| 217 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
| 218 | - ucfirst($modelName) . 'TableSeeder', |
|
| 219 | - ucfirst($modelNameSingular) . 'Controller', |
|
| 220 | - ucfirst($modelNameSingular) . 'Service', |
|
| 221 | - ucfirst($modelNameSingular) . 'Repository', |
|
| 222 | - 'Insert' . ucfirst($modelNameSingular), |
|
| 223 | - 'Update' . ucfirst($modelNameSingular), |
|
| 217 | + ucfirst($modelName).'DatabaseSeeder', |
|
| 218 | + ucfirst($modelName).'TableSeeder', |
|
| 219 | + ucfirst($modelNameSingular).'Controller', |
|
| 220 | + ucfirst($modelNameSingular).'Service', |
|
| 221 | + ucfirst($modelNameSingular).'Repository', |
|
| 222 | + 'Insert'.ucfirst($modelNameSingular), |
|
| 223 | + 'Update'.ucfirst($modelNameSingular), |
|
| 224 | 224 | ucfirst($modelNameSingular), |
| 225 | - ucfirst($modelNameSingular) . 'Observer', |
|
| 225 | + ucfirst($modelNameSingular).'Observer', |
|
| 226 | 226 | $modelName, |
| 227 | 227 | $modelName, |
| 228 | 228 | ]; |
@@ -244,6 +244,6 @@ discard block |
||
| 244 | 244 | protected function generateMigration() |
| 245 | 245 | { |
| 246 | 246 | $modelName = $this->container['slug']; |
| 247 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 247 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_'.$modelName.'_table']); |
|
| 248 | 248 | } |
| 249 | 249 | } |
@@ -6,32 +6,32 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DummyModel extends Model |
| 8 | 8 | { |
| 9 | - use SoftDeletes; |
|
| 10 | - protected $table = 'DummyTableName'; |
|
| 11 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 12 | - protected $hidden = ['deleted_at']; |
|
| 13 | - protected $guarded = ['id']; |
|
| 14 | - protected $fillable = []; // Add attributes here |
|
| 15 | - public $searchable = []; // Add earchable attributes here |
|
| 9 | + use SoftDeletes; |
|
| 10 | + protected $table = 'DummyTableName'; |
|
| 11 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 12 | + protected $hidden = ['deleted_at']; |
|
| 13 | + protected $guarded = ['id']; |
|
| 14 | + protected $fillable = []; // Add attributes here |
|
| 15 | + public $searchable = []; // Add earchable attributes here |
|
| 16 | 16 | |
| 17 | - public function getCreatedAtAttribute($value) |
|
| 18 | - { |
|
| 19 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 20 | - } |
|
| 17 | + public function getCreatedAtAttribute($value) |
|
| 18 | + { |
|
| 19 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function getUpdatedAtAttribute($value) |
|
| 23 | - { |
|
| 24 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 25 | - } |
|
| 22 | + public function getUpdatedAtAttribute($value) |
|
| 23 | + { |
|
| 24 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function getDeletedAtAttribute($value) |
|
| 28 | - { |
|
| 29 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 30 | - } |
|
| 27 | + public function getDeletedAtAttribute($value) |
|
| 28 | + { |
|
| 29 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public static function boot() |
|
| 33 | - { |
|
| 34 | - parent::boot(); |
|
| 35 | - DummyModel::observe(DummyObserver::class); |
|
| 36 | - } |
|
| 32 | + public static function boot() |
|
| 33 | + { |
|
| 34 | + parent::boot(); |
|
| 35 | + DummyModel::observe(DummyObserver::class); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -5,14 +5,14 @@ |
||
| 5 | 5 | |
| 6 | 6 | class DummyService extends BaseService |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param DummyRepository $repo |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(DummyRepository $repo) |
|
| 15 | - { |
|
| 16 | - parent::__construct($repo); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param DummyRepository $repo |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(DummyRepository $repo) |
|
| 15 | + { |
|
| 16 | + parent::__construct($repo); |
|
| 17 | + } |
|
| 18 | 18 | } |