@@ -10,63 +10,63 @@ |
||
| 10 | 10 | |
| 11 | 11 | class PushNotificationDeviceService extends BaseService |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Init new object. |
|
| 15 | - * |
|
| 16 | - * @param PushNotificationDeviceRepository $repo |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function __construct(PushNotificationDeviceRepository $repo) |
|
| 20 | - { |
|
| 21 | - parent::__construct($repo); |
|
| 22 | - } |
|
| 13 | + /** |
|
| 14 | + * Init new object. |
|
| 15 | + * |
|
| 16 | + * @param PushNotificationDeviceRepository $repo |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function __construct(PushNotificationDeviceRepository $repo) |
|
| 20 | + { |
|
| 21 | + parent::__construct($repo); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Register the given device to the logged in user. |
|
| 26 | - * |
|
| 27 | - * @param array $data |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function registerDevice($data) |
|
| 31 | - { |
|
| 32 | - $data['access_token'] = \Auth::user()->token(); |
|
| 33 | - $data['user_id'] = \Auth::id(); |
|
| 34 | - $device = $this->repo->first([ |
|
| 35 | - 'and' => [ |
|
| 36 | - 'device_token' => $data['device_token'], |
|
| 37 | - 'user_id' => $data['user_id'] |
|
| 38 | - ] |
|
| 39 | - ]); |
|
| 24 | + /** |
|
| 25 | + * Register the given device to the logged in user. |
|
| 26 | + * |
|
| 27 | + * @param array $data |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function registerDevice($data) |
|
| 31 | + { |
|
| 32 | + $data['access_token'] = \Auth::user()->token(); |
|
| 33 | + $data['user_id'] = \Auth::id(); |
|
| 34 | + $device = $this->repo->first([ |
|
| 35 | + 'and' => [ |
|
| 36 | + 'device_token' => $data['device_token'], |
|
| 37 | + 'user_id' => $data['user_id'] |
|
| 38 | + ] |
|
| 39 | + ]); |
|
| 40 | 40 | |
| 41 | - if ($device) { |
|
| 42 | - $data['id'] = $device->id; |
|
| 43 | - } |
|
| 41 | + if ($device) { |
|
| 42 | + $data['id'] = $device->id; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $this->repo->save($data); |
|
| 46 | - } |
|
| 45 | + return $this->repo->save($data); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Generate the given message data. |
|
| 50 | - * |
|
| 51 | - * @param string $title |
|
| 52 | - * @param string $message |
|
| 53 | - * @param array $data |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function generateMessageData($title, $message, $data = []) |
|
| 57 | - { |
|
| 58 | - $optionBuilder = new OptionsBuilder(); |
|
| 59 | - $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 60 | - $dataBuilder = new PayloadDataBuilder(); |
|
| 48 | + /** |
|
| 49 | + * Generate the given message data. |
|
| 50 | + * |
|
| 51 | + * @param string $title |
|
| 52 | + * @param string $message |
|
| 53 | + * @param array $data |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function generateMessageData($title, $message, $data = []) |
|
| 57 | + { |
|
| 58 | + $optionBuilder = new OptionsBuilder(); |
|
| 59 | + $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 60 | + $dataBuilder = new PayloadDataBuilder(); |
|
| 61 | 61 | |
| 62 | - $optionBuilder->setTimeToLive(60 * 20); |
|
| 63 | - $notificationBuilder->setBody($message); |
|
| 64 | - $dataBuilder->addData($data); |
|
| 62 | + $optionBuilder->setTimeToLive(60 * 20); |
|
| 63 | + $notificationBuilder->setBody($message); |
|
| 64 | + $dataBuilder->addData($data); |
|
| 65 | 65 | |
| 66 | - $options = $optionBuilder->build(); |
|
| 67 | - $notification = $notificationBuilder->build(); |
|
| 68 | - $data = $dataBuilder->build(); |
|
| 66 | + $options = $optionBuilder->build(); |
|
| 67 | + $notification = $notificationBuilder->build(); |
|
| 68 | + $data = $dataBuilder->build(); |
|
| 69 | 69 | |
| 70 | - return compact('options', 'notification', 'data'); |
|
| 71 | - } |
|
| 70 | + return compact('options', 'notification', 'data'); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -2,14 +2,14 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Here goes your error messages. |
|
| 7 | - */ |
|
| 8 | - 'connectionError' => 'Connection error', |
|
| 9 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 10 | - 'dbQueryError' => 'Please check the given inputes', |
|
| 11 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 12 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 13 | - 'notFound' => 'The requested :replace not found' |
|
| 5 | + /** |
|
| 6 | + * Here goes your error messages. |
|
| 7 | + */ |
|
| 8 | + 'connectionError' => 'Connection error', |
|
| 9 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 10 | + 'dbQueryError' => 'Please check the given inputes', |
|
| 11 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 12 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 13 | + 'notFound' => 'The requested :replace not found' |
|
| 14 | 14 | |
| 15 | 15 | ]; |
@@ -2,14 +2,14 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Here goes your error messages. |
|
| 7 | - */ |
|
| 8 | - 'connectionError' => 'خطأ في الاتصال', |
|
| 9 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 10 | - 'dbQueryError' => 'خطا في البيانات', |
|
| 11 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 12 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 13 | - 'notFound' => 'ال :replace المطلوب غير موجود' |
|
| 5 | + /** |
|
| 6 | + * Here goes your error messages. |
|
| 7 | + */ |
|
| 8 | + 'connectionError' => 'خطأ في الاتصال', |
|
| 9 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 10 | + 'dbQueryError' => 'خطا في البيانات', |
|
| 11 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 12 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 13 | + 'notFound' => 'ال :replace المطلوب غير موجود' |
|
| 14 | 14 | |
| 15 | 15 | ]; |
@@ -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\Errors\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\Errors\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\Errors\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,243 +10,243 @@ |
||
| 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 | - 'Errors' => 'Errors', |
|
| 67 | - ]; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Create a new command instance. |
|
| 71 | - * |
|
| 72 | - * @param Filesystem $files |
|
| 73 | - * @param RepositoryManager $module |
|
| 74 | - */ |
|
| 75 | - public function __construct(Filesystem $files, RepositoryManager $module) |
|
| 76 | - { |
|
| 77 | - parent::__construct(); |
|
| 78 | - |
|
| 79 | - $this->files = $files; |
|
| 80 | - $this->module = $module; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Execute the console command. |
|
| 85 | - * |
|
| 86 | - * @return mixed |
|
| 87 | - */ |
|
| 88 | - public function handle() |
|
| 89 | - { |
|
| 90 | - $this->container['slug'] = Str::slug($this->argument('slug')); |
|
| 91 | - $this->container['name'] = Str::studly($this->container['slug']); |
|
| 92 | - $this->container['version'] = '1.0'; |
|
| 93 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 94 | - $this->container['location'] = config('modules.default_location'); |
|
| 95 | - $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
| 96 | - $this->container['basename'] = Str::studly($this->container['slug']); |
|
| 97 | - $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
| 98 | - |
|
| 99 | - return $this->generate(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Generate the module. |
|
| 104 | - */ |
|
| 105 | - protected function generate() |
|
| 106 | - { |
|
| 107 | - $steps = [ |
|
| 108 | - 'Generating module...' => 'generateModule', |
|
| 109 | - 'Optimizing module cache...' => 'optimizeModules', |
|
| 110 | - 'Generating migrations...' => 'generateMigration', |
|
| 111 | - ]; |
|
| 112 | - |
|
| 113 | - $progress = new ProgressBar($this->output, count($steps)); |
|
| 114 | - $progress->start(); |
|
| 115 | - |
|
| 116 | - foreach ($steps as $message => $function) { |
|
| 117 | - $progress->setMessage($message); |
|
| 118 | - |
|
| 119 | - $this->$function(); |
|
| 120 | - |
|
| 121 | - $progress->advance(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $progress->finish(); |
|
| 125 | - |
|
| 126 | - event($this->container['slug'] . '.module.made'); |
|
| 127 | - |
|
| 128 | - $this->info("\nModule generated successfully."); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Generate defined module folders. |
|
| 133 | - */ |
|
| 134 | - protected function generateModule() |
|
| 135 | - { |
|
| 136 | - $location = $this->container['location']; |
|
| 137 | - $root = module_path(null, '', $location); |
|
| 138 | - $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
| 139 | - $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
| 140 | - |
|
| 141 | - if (!$this->files->isDirectory($root)) { |
|
| 142 | - $this->files->makeDirectory($root); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $directory = module_path(null, $this->container['basename'], $location); |
|
| 146 | - $source = __DIR__ . '/Stubs/Module'; |
|
| 147 | - |
|
| 148 | - $this->files->makeDirectory($directory); |
|
| 149 | - |
|
| 150 | - $sourceFiles = $this->files->allFiles($source, true); |
|
| 151 | - |
|
| 152 | - if (!empty($this->mapping)) { |
|
| 153 | - $search = array_keys($this->mapping); |
|
| 154 | - $replace = array_values($this->mapping); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - foreach ($sourceFiles as $file) { |
|
| 158 | - $contents = $this->replacePlaceholders($file->getContents()); |
|
| 159 | - $subPath = $file->getRelativePathname(); |
|
| 160 | - |
|
| 161 | - if (!empty($this->mapping)) { |
|
| 162 | - $subPath = str_replace($search, $replace, $subPath); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $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 | + 'Errors' => 'Errors', |
|
| 67 | + ]; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Create a new command instance. |
|
| 71 | + * |
|
| 72 | + * @param Filesystem $files |
|
| 73 | + * @param RepositoryManager $module |
|
| 74 | + */ |
|
| 75 | + public function __construct(Filesystem $files, RepositoryManager $module) |
|
| 76 | + { |
|
| 77 | + parent::__construct(); |
|
| 78 | + |
|
| 79 | + $this->files = $files; |
|
| 80 | + $this->module = $module; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Execute the console command. |
|
| 85 | + * |
|
| 86 | + * @return mixed |
|
| 87 | + */ |
|
| 88 | + public function handle() |
|
| 89 | + { |
|
| 90 | + $this->container['slug'] = Str::slug($this->argument('slug')); |
|
| 91 | + $this->container['name'] = Str::studly($this->container['slug']); |
|
| 92 | + $this->container['version'] = '1.0'; |
|
| 93 | + $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 94 | + $this->container['location'] = config('modules.default_location'); |
|
| 95 | + $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
|
| 96 | + $this->container['basename'] = Str::studly($this->container['slug']); |
|
| 97 | + $this->container['namespace'] = config("modules.locations.{$this->container['location']}.namespace").$this->container['basename']; |
|
| 98 | + |
|
| 99 | + return $this->generate(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Generate the module. |
|
| 104 | + */ |
|
| 105 | + protected function generate() |
|
| 106 | + { |
|
| 107 | + $steps = [ |
|
| 108 | + 'Generating module...' => 'generateModule', |
|
| 109 | + 'Optimizing module cache...' => 'optimizeModules', |
|
| 110 | + 'Generating migrations...' => 'generateMigration', |
|
| 111 | + ]; |
|
| 112 | + |
|
| 113 | + $progress = new ProgressBar($this->output, count($steps)); |
|
| 114 | + $progress->start(); |
|
| 115 | + |
|
| 116 | + foreach ($steps as $message => $function) { |
|
| 117 | + $progress->setMessage($message); |
|
| 118 | + |
|
| 119 | + $this->$function(); |
|
| 120 | + |
|
| 121 | + $progress->advance(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $progress->finish(); |
|
| 125 | + |
|
| 126 | + event($this->container['slug'] . '.module.made'); |
|
| 127 | + |
|
| 128 | + $this->info("\nModule generated successfully."); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Generate defined module folders. |
|
| 133 | + */ |
|
| 134 | + protected function generateModule() |
|
| 135 | + { |
|
| 136 | + $location = $this->container['location']; |
|
| 137 | + $root = module_path(null, '', $location); |
|
| 138 | + $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
|
| 139 | + $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
|
| 140 | + |
|
| 141 | + if (!$this->files->isDirectory($root)) { |
|
| 142 | + $this->files->makeDirectory($root); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $directory = module_path(null, $this->container['basename'], $location); |
|
| 146 | + $source = __DIR__ . '/Stubs/Module'; |
|
| 147 | + |
|
| 148 | + $this->files->makeDirectory($directory); |
|
| 149 | + |
|
| 150 | + $sourceFiles = $this->files->allFiles($source, true); |
|
| 151 | + |
|
| 152 | + if (!empty($this->mapping)) { |
|
| 153 | + $search = array_keys($this->mapping); |
|
| 154 | + $replace = array_values($this->mapping); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + foreach ($sourceFiles as $file) { |
|
| 158 | + $contents = $this->replacePlaceholders($file->getContents()); |
|
| 159 | + $subPath = $file->getRelativePathname(); |
|
| 160 | + |
|
| 161 | + if (!empty($this->mapping)) { |
|
| 162 | + $subPath = str_replace($search, $replace, $subPath); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $filePath = $directory . '/' . $subPath; |
|
| 166 | 166 | |
| 167 | - // if the file is module.json, replace it with the custom manifest file name |
|
| 168 | - if ($file->getFilename() === 'module.json' && $manifest) { |
|
| 169 | - $filePath = str_replace('module.json', $manifest, $filePath); |
|
| 170 | - } |
|
| 167 | + // if the file is module.json, replace it with the custom manifest file name |
|
| 168 | + if ($file->getFilename() === 'module.json' && $manifest) { |
|
| 169 | + $filePath = str_replace('module.json', $manifest, $filePath); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
| 173 | - if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
| 174 | - $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
| 175 | - } |
|
| 176 | - $filePath = $this->replacePlaceholders($filePath); |
|
| 172 | + // if the file is ModuleServiceProvider.php, replace it with the custom provider file name |
|
| 173 | + if ($file->getFilename() === 'ModuleServiceProvider.php') { |
|
| 174 | + $filePath = str_replace('ModuleServiceProvider', $provider, $filePath); |
|
| 175 | + } |
|
| 176 | + $filePath = $this->replacePlaceholders($filePath); |
|
| 177 | 177 | |
| 178 | - $dir = dirname($filePath); |
|
| 178 | + $dir = dirname($filePath); |
|
| 179 | 179 | |
| 180 | - if (! $this->files->isDirectory($dir)) { |
|
| 181 | - $this->files->makeDirectory($dir, 0755, true); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $this->files->put($filePath, $contents); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - protected function replacePlaceholders($contents) |
|
| 189 | - { |
|
| 190 | - $modelName = \Str::camel($this->container['slug']); |
|
| 191 | - $modelNameSingular = \Str::singular($modelName); |
|
| 192 | - |
|
| 193 | - $find = [ |
|
| 194 | - 'DummyFactory', |
|
| 195 | - 'DummyModelName', |
|
| 196 | - 'DummyModuleSlug', |
|
| 197 | - 'DummyModule', |
|
| 198 | - 'DummyModel', |
|
| 199 | - 'DummyDatabaseSeeder', |
|
| 200 | - 'DummyTableSeeder', |
|
| 201 | - 'DummyController', |
|
| 202 | - 'DummyService', |
|
| 203 | - 'DummyRepository', |
|
| 204 | - 'DummyErrors', |
|
| 205 | - 'InsertDummy', |
|
| 206 | - 'UpdateDummy', |
|
| 207 | - 'DummyResource', |
|
| 208 | - 'DummyObserver', |
|
| 209 | - 'DummyTableName', |
|
| 210 | - 'DummyRoutePrefix', |
|
| 211 | - ]; |
|
| 212 | - |
|
| 213 | - $replace = [ |
|
| 214 | - ucfirst($modelNameSingular) . 'Factory', |
|
| 215 | - $modelNameSingular, |
|
| 216 | - $this->container['slug'], |
|
| 217 | - ucfirst($modelName), |
|
| 218 | - ucfirst($modelNameSingular), |
|
| 219 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
| 220 | - ucfirst($modelName) . 'TableSeeder', |
|
| 221 | - ucfirst($modelNameSingular) . 'Controller', |
|
| 222 | - ucfirst($modelNameSingular) . 'Service', |
|
| 223 | - ucfirst($modelNameSingular) . 'Repository', |
|
| 224 | - ucfirst($modelName) . 'Errors', |
|
| 225 | - 'Insert' . ucfirst($modelNameSingular), |
|
| 226 | - 'Update' . ucfirst($modelNameSingular), |
|
| 227 | - ucfirst($modelNameSingular), |
|
| 228 | - ucfirst($modelNameSingular) . 'Observer', |
|
| 229 | - $modelName, |
|
| 230 | - $modelName, |
|
| 231 | - ]; |
|
| 232 | - |
|
| 233 | - return str_replace($find, $replace, $contents); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Reset module cache of enabled and disabled modules. |
|
| 238 | - */ |
|
| 239 | - protected function optimizeModules() |
|
| 240 | - { |
|
| 241 | - return $this->callSilent('module:optimize'); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Generate table migrations. |
|
| 246 | - */ |
|
| 247 | - protected function generateMigration() |
|
| 248 | - { |
|
| 249 | - $modelName = $this->container['slug']; |
|
| 250 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 251 | - } |
|
| 180 | + if (! $this->files->isDirectory($dir)) { |
|
| 181 | + $this->files->makeDirectory($dir, 0755, true); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $this->files->put($filePath, $contents); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + protected function replacePlaceholders($contents) |
|
| 189 | + { |
|
| 190 | + $modelName = \Str::camel($this->container['slug']); |
|
| 191 | + $modelNameSingular = \Str::singular($modelName); |
|
| 192 | + |
|
| 193 | + $find = [ |
|
| 194 | + 'DummyFactory', |
|
| 195 | + 'DummyModelName', |
|
| 196 | + 'DummyModuleSlug', |
|
| 197 | + 'DummyModule', |
|
| 198 | + 'DummyModel', |
|
| 199 | + 'DummyDatabaseSeeder', |
|
| 200 | + 'DummyTableSeeder', |
|
| 201 | + 'DummyController', |
|
| 202 | + 'DummyService', |
|
| 203 | + 'DummyRepository', |
|
| 204 | + 'DummyErrors', |
|
| 205 | + 'InsertDummy', |
|
| 206 | + 'UpdateDummy', |
|
| 207 | + 'DummyResource', |
|
| 208 | + 'DummyObserver', |
|
| 209 | + 'DummyTableName', |
|
| 210 | + 'DummyRoutePrefix', |
|
| 211 | + ]; |
|
| 212 | + |
|
| 213 | + $replace = [ |
|
| 214 | + ucfirst($modelNameSingular) . 'Factory', |
|
| 215 | + $modelNameSingular, |
|
| 216 | + $this->container['slug'], |
|
| 217 | + ucfirst($modelName), |
|
| 218 | + ucfirst($modelNameSingular), |
|
| 219 | + ucfirst($modelName) . 'DatabaseSeeder', |
|
| 220 | + ucfirst($modelName) . 'TableSeeder', |
|
| 221 | + ucfirst($modelNameSingular) . 'Controller', |
|
| 222 | + ucfirst($modelNameSingular) . 'Service', |
|
| 223 | + ucfirst($modelNameSingular) . 'Repository', |
|
| 224 | + ucfirst($modelName) . 'Errors', |
|
| 225 | + 'Insert' . ucfirst($modelNameSingular), |
|
| 226 | + 'Update' . ucfirst($modelNameSingular), |
|
| 227 | + ucfirst($modelNameSingular), |
|
| 228 | + ucfirst($modelNameSingular) . 'Observer', |
|
| 229 | + $modelName, |
|
| 230 | + $modelName, |
|
| 231 | + ]; |
|
| 232 | + |
|
| 233 | + return str_replace($find, $replace, $contents); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Reset module cache of enabled and disabled modules. |
|
| 238 | + */ |
|
| 239 | + protected function optimizeModules() |
|
| 240 | + { |
|
| 241 | + return $this->callSilent('module:optimize'); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Generate table migrations. |
|
| 246 | + */ |
|
| 247 | + protected function generateMigration() |
|
| 248 | + { |
|
| 249 | + $modelName = $this->container['slug']; |
|
| 250 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $this->container['slug'] = Str::slug($this->argument('slug')); |
| 91 | 91 | $this->container['name'] = Str::studly($this->container['slug']); |
| 92 | 92 | $this->container['version'] = '1.0'; |
| 93 | - $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; |
|
| 93 | + $this->container['description'] = 'This is the description for the '.$this->container['name'].' module.'; |
|
| 94 | 94 | $this->container['location'] = config('modules.default_location'); |
| 95 | 95 | $this->container['provider'] = config("modules.locations.{$this->container['location']}.provider"); |
| 96 | 96 | $this->container['basename'] = Str::studly($this->container['slug']); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $progress->finish(); |
| 125 | 125 | |
| 126 | - event($this->container['slug'] . '.module.made'); |
|
| 126 | + event($this->container['slug'].'.module.made'); |
|
| 127 | 127 | |
| 128 | 128 | $this->info("\nModule generated successfully."); |
| 129 | 129 | } |
@@ -138,18 +138,18 @@ discard block |
||
| 138 | 138 | $manifest = config("modules.locations.$location.manifest") ?: 'module.json'; |
| 139 | 139 | $provider = config("modules.locations.$location.provider") ?: 'ModuleServiceProvider'; |
| 140 | 140 | |
| 141 | - if (!$this->files->isDirectory($root)) { |
|
| 141 | + if ( ! $this->files->isDirectory($root)) { |
|
| 142 | 142 | $this->files->makeDirectory($root); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $directory = module_path(null, $this->container['basename'], $location); |
| 146 | - $source = __DIR__ . '/Stubs/Module'; |
|
| 146 | + $source = __DIR__.'/Stubs/Module'; |
|
| 147 | 147 | |
| 148 | 148 | $this->files->makeDirectory($directory); |
| 149 | 149 | |
| 150 | 150 | $sourceFiles = $this->files->allFiles($source, true); |
| 151 | 151 | |
| 152 | - if (!empty($this->mapping)) { |
|
| 152 | + if ( ! empty($this->mapping)) { |
|
| 153 | 153 | $search = array_keys($this->mapping); |
| 154 | 154 | $replace = array_values($this->mapping); |
| 155 | 155 | } |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | $contents = $this->replacePlaceholders($file->getContents()); |
| 159 | 159 | $subPath = $file->getRelativePathname(); |
| 160 | 160 | |
| 161 | - if (!empty($this->mapping)) { |
|
| 161 | + if ( ! empty($this->mapping)) { |
|
| 162 | 162 | $subPath = str_replace($search, $replace, $subPath); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $filePath = $directory . '/' . $subPath; |
|
| 165 | + $filePath = $directory.'/'.$subPath; |
|
| 166 | 166 | |
| 167 | 167 | // if the file is module.json, replace it with the custom manifest file name |
| 168 | 168 | if ($file->getFilename() === 'module.json' && $manifest) { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $dir = dirname($filePath); |
| 179 | 179 | |
| 180 | - if (! $this->files->isDirectory($dir)) { |
|
| 180 | + if ( ! $this->files->isDirectory($dir)) { |
|
| 181 | 181 | $this->files->makeDirectory($dir, 0755, true); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $replace = [ |
| 214 | - ucfirst($modelNameSingular) . 'Factory', |
|
| 214 | + ucfirst($modelNameSingular).'Factory', |
|
| 215 | 215 | $modelNameSingular, |
| 216 | 216 | $this->container['slug'], |
| 217 | 217 | ucfirst($modelName), |
| 218 | 218 | ucfirst($modelNameSingular), |
| 219 | - ucfirst($modelName) . 'DatabaseSeeder', |
|
| 220 | - ucfirst($modelName) . 'TableSeeder', |
|
| 221 | - ucfirst($modelNameSingular) . 'Controller', |
|
| 222 | - ucfirst($modelNameSingular) . 'Service', |
|
| 223 | - ucfirst($modelNameSingular) . 'Repository', |
|
| 224 | - ucfirst($modelName) . 'Errors', |
|
| 225 | - 'Insert' . ucfirst($modelNameSingular), |
|
| 226 | - 'Update' . ucfirst($modelNameSingular), |
|
| 219 | + ucfirst($modelName).'DatabaseSeeder', |
|
| 220 | + ucfirst($modelName).'TableSeeder', |
|
| 221 | + ucfirst($modelNameSingular).'Controller', |
|
| 222 | + ucfirst($modelNameSingular).'Service', |
|
| 223 | + ucfirst($modelNameSingular).'Repository', |
|
| 224 | + ucfirst($modelName).'Errors', |
|
| 225 | + 'Insert'.ucfirst($modelNameSingular), |
|
| 226 | + 'Update'.ucfirst($modelNameSingular), |
|
| 227 | 227 | ucfirst($modelNameSingular), |
| 228 | - ucfirst($modelNameSingular) . 'Observer', |
|
| 228 | + ucfirst($modelNameSingular).'Observer', |
|
| 229 | 229 | $modelName, |
| 230 | 230 | $modelName, |
| 231 | 231 | ]; |
@@ -247,6 +247,6 @@ discard block |
||
| 247 | 247 | protected function generateMigration() |
| 248 | 248 | { |
| 249 | 249 | $modelName = $this->container['slug']; |
| 250 | - return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_' . $modelName . '_table']); |
|
| 250 | + return $this->callSilent('make:module:migration', ['slug' => $modelName, 'name' => 'create_'.$modelName.'_table']); |
|
| 251 | 251 | } |
| 252 | 252 | } |
@@ -8,275 +8,275 @@ |
||
| 8 | 8 | |
| 9 | 9 | class GenerateDoc extends Command |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name and signature of the console command. |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $signature = 'doc:generate'; |
|
| 11 | + /** |
|
| 12 | + * The name and signature of the console command. |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $signature = 'doc:generate'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The console command description. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $description = 'Generate api documentation'; |
|
| 18 | + /** |
|
| 19 | + * The console command description. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $description = 'Generate api documentation'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var ReprotService |
|
| 27 | - */ |
|
| 28 | - protected $reportService; |
|
| 25 | + /** |
|
| 26 | + * @var ReprotService |
|
| 27 | + */ |
|
| 28 | + protected $reportService; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Init new object. |
|
| 32 | - * |
|
| 33 | - * @return void |
|
| 34 | - */ |
|
| 35 | - public function __construct(ReportService $reportService) |
|
| 36 | - { |
|
| 37 | - $this->reportService = $reportService; |
|
| 38 | - parent::__construct(); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Init new object. |
|
| 32 | + * |
|
| 33 | + * @return void |
|
| 34 | + */ |
|
| 35 | + public function __construct(ReportService $reportService) |
|
| 36 | + { |
|
| 37 | + $this->reportService = $reportService; |
|
| 38 | + parent::__construct(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Execute the console command. |
|
| 43 | - * |
|
| 44 | - * @return mixed |
|
| 45 | - */ |
|
| 46 | - public function handle() |
|
| 47 | - { |
|
| 48 | - $docData = []; |
|
| 49 | - $docData['models'] = []; |
|
| 50 | - $routes = $this->getRoutes(); |
|
| 51 | - foreach ($routes as $route) { |
|
| 52 | - if ($route) { |
|
| 53 | - $actoinArray = explode('@', $route['action']); |
|
| 54 | - if (Arr::get($actoinArray, 1, false)) { |
|
| 55 | - $controller = $actoinArray[0]; |
|
| 56 | - $method = $actoinArray[1]; |
|
| 57 | - $route['name'] = $method !== 'index' ? $method : 'list'; |
|
| 41 | + /** |
|
| 42 | + * Execute the console command. |
|
| 43 | + * |
|
| 44 | + * @return mixed |
|
| 45 | + */ |
|
| 46 | + public function handle() |
|
| 47 | + { |
|
| 48 | + $docData = []; |
|
| 49 | + $docData['models'] = []; |
|
| 50 | + $routes = $this->getRoutes(); |
|
| 51 | + foreach ($routes as $route) { |
|
| 52 | + if ($route) { |
|
| 53 | + $actoinArray = explode('@', $route['action']); |
|
| 54 | + if (Arr::get($actoinArray, 1, false)) { |
|
| 55 | + $controller = $actoinArray[0]; |
|
| 56 | + $method = $actoinArray[1]; |
|
| 57 | + $route['name'] = $method !== 'index' ? $method : 'list'; |
|
| 58 | 58 | |
| 59 | - $reflectionClass = new \ReflectionClass($controller); |
|
| 60 | - $reflectionMethod = $reflectionClass->getMethod($method); |
|
| 61 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 62 | - $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
| 63 | - $modelName = explode('\\', $controller); |
|
| 64 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 59 | + $reflectionClass = new \ReflectionClass($controller); |
|
| 60 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
| 61 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 62 | + $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
| 63 | + $modelName = explode('\\', $controller); |
|
| 64 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 65 | 65 | |
| 66 | - $this->processDocBlock($route, $reflectionMethod); |
|
| 67 | - $this->getHeaders($route, $method, $skipLoginCheck); |
|
| 68 | - $this->getPostData($route, $reflectionMethod); |
|
| 66 | + $this->processDocBlock($route, $reflectionMethod); |
|
| 67 | + $this->getHeaders($route, $method, $skipLoginCheck); |
|
| 68 | + $this->getPostData($route, $reflectionMethod); |
|
| 69 | 69 | |
| 70 | - $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
| 70 | + $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
| 71 | 71 | |
| 72 | - $module = $route['prefix']; |
|
| 73 | - $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
| 74 | - $docData['modules'][$module][] = $route; |
|
| 72 | + $module = $route['prefix']; |
|
| 73 | + $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
| 74 | + $docData['modules'][$module][] = $route; |
|
| 75 | 75 | |
| 76 | - $this->getModels($modelName, $docData, $reflectionClass); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 76 | + $this->getModels($modelName, $docData, $reflectionClass); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $docData['errors'] = $this->getErrors(); |
|
| 82 | - $docData['reports'] = $this->reportService->all(); |
|
| 83 | - \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
| 84 | - } |
|
| 81 | + $docData['errors'] = $this->getErrors(); |
|
| 82 | + $docData['reports'] = $this->reportService->all(); |
|
| 83 | + \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get list of all registered routes. |
|
| 88 | - * |
|
| 89 | - * @return collection |
|
| 90 | - */ |
|
| 91 | - protected function getRoutes() |
|
| 92 | - { |
|
| 93 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
| 94 | - if (strpos($route->uri(), 'api/') !== false) { |
|
| 95 | - return [ |
|
| 96 | - 'method' => $route->methods()[0], |
|
| 97 | - 'uri' => $route->uri(), |
|
| 98 | - 'action' => $route->getActionName(), |
|
| 99 | - 'prefix' => $route->getPrefix() |
|
| 100 | - ]; |
|
| 101 | - } |
|
| 102 | - return false; |
|
| 103 | - })->all(); |
|
| 104 | - } |
|
| 86 | + /** |
|
| 87 | + * Get list of all registered routes. |
|
| 88 | + * |
|
| 89 | + * @return collection |
|
| 90 | + */ |
|
| 91 | + protected function getRoutes() |
|
| 92 | + { |
|
| 93 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
| 94 | + if (strpos($route->uri(), 'api/') !== false) { |
|
| 95 | + return [ |
|
| 96 | + 'method' => $route->methods()[0], |
|
| 97 | + 'uri' => $route->uri(), |
|
| 98 | + 'action' => $route->getActionName(), |
|
| 99 | + 'prefix' => $route->getPrefix() |
|
| 100 | + ]; |
|
| 101 | + } |
|
| 102 | + return false; |
|
| 103 | + })->all(); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Generate headers for the given route. |
|
| 108 | - * |
|
| 109 | - * @param array &$route |
|
| 110 | - * @param string $method |
|
| 111 | - * @param array $skipLoginCheck |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
| 115 | - { |
|
| 116 | - $route['headers'] = [ |
|
| 117 | - 'Accept' => 'application/json', |
|
| 118 | - 'Content-Type' => 'application/json', |
|
| 119 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
| 120 | - 'time-zone' => 'Your locale time zone', |
|
| 121 | - ]; |
|
| 106 | + /** |
|
| 107 | + * Generate headers for the given route. |
|
| 108 | + * |
|
| 109 | + * @param array &$route |
|
| 110 | + * @param string $method |
|
| 111 | + * @param array $skipLoginCheck |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
| 115 | + { |
|
| 116 | + $route['headers'] = [ |
|
| 117 | + 'Accept' => 'application/json', |
|
| 118 | + 'Content-Type' => 'application/json', |
|
| 119 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
| 120 | + 'time-zone' => 'Your locale time zone', |
|
| 121 | + ]; |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 125 | - $route['headers']['Authorization'] = 'Bearer {token}'; |
|
| 126 | - } |
|
| 127 | - } |
|
| 124 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 125 | + $route['headers']['Authorization'] = 'Bearer {token}'; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Generate description and params for the given route |
|
| 131 | - * based on the docblock. |
|
| 132 | - * |
|
| 133 | - * @param array &$route |
|
| 134 | - * @param \ReflectionMethod $reflectionMethod |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 137 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
| 138 | - { |
|
| 139 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
| 140 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
| 141 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
| 142 | - $params = $docblock->getTagsByName('param'); |
|
| 143 | - $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
| 129 | + /** |
|
| 130 | + * Generate description and params for the given route |
|
| 131 | + * based on the docblock. |
|
| 132 | + * |
|
| 133 | + * @param array &$route |
|
| 134 | + * @param \ReflectionMethod $reflectionMethod |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
| 138 | + { |
|
| 139 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
| 140 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
| 141 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
| 142 | + $params = $docblock->getTagsByName('param'); |
|
| 143 | + $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
| 144 | 144 | |
| 145 | - foreach ($params as $param) { |
|
| 146 | - $name = $param->getVariableName(); |
|
| 147 | - if ($name !== 'request') { |
|
| 148 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 145 | + foreach ($params as $param) { |
|
| 146 | + $name = $param->getVariableName(); |
|
| 147 | + if ($name !== 'request') { |
|
| 148 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - if ($route['name'] === 'list') { |
|
| 153 | - $route['parametars']['perPage'] = 'perPage'; |
|
| 154 | - $route['parametars']['sortBy'] = 'sortBy'; |
|
| 155 | - $route['parametars']['desc'] = 'desc'; |
|
| 156 | - } |
|
| 157 | - } |
|
| 152 | + if ($route['name'] === 'list') { |
|
| 153 | + $route['parametars']['perPage'] = 'perPage'; |
|
| 154 | + $route['parametars']['sortBy'] = 'sortBy'; |
|
| 155 | + $route['parametars']['desc'] = 'desc'; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Generate post body for the given route. |
|
| 161 | - * |
|
| 162 | - * @param array &$route |
|
| 163 | - * @param \ReflectionMethod $reflectionMethod |
|
| 164 | - * @return void |
|
| 165 | - */ |
|
| 166 | - protected function getPostData(&$route, $reflectionMethod) |
|
| 167 | - { |
|
| 168 | - $parameters = $reflectionMethod->getParameters(); |
|
| 169 | - if (count($parameters)) { |
|
| 170 | - $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
| 171 | - if ($className) { |
|
| 172 | - $reflectionClass = new \ReflectionClass($className); |
|
| 159 | + /** |
|
| 160 | + * Generate post body for the given route. |
|
| 161 | + * |
|
| 162 | + * @param array &$route |
|
| 163 | + * @param \ReflectionMethod $reflectionMethod |
|
| 164 | + * @return void |
|
| 165 | + */ |
|
| 166 | + protected function getPostData(&$route, $reflectionMethod) |
|
| 167 | + { |
|
| 168 | + $parameters = $reflectionMethod->getParameters(); |
|
| 169 | + if (count($parameters)) { |
|
| 170 | + $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
| 171 | + if ($className) { |
|
| 172 | + $reflectionClass = new \ReflectionClass($className); |
|
| 173 | 173 | |
| 174 | - if ($reflectionClass->hasMethod('rules')) { |
|
| 175 | - $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
| 176 | - $route['body'] = $reflectionMethod->invoke(new $className); |
|
| 174 | + if ($reflectionClass->hasMethod('rules')) { |
|
| 175 | + $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
| 176 | + $route['body'] = $reflectionMethod->invoke(new $className); |
|
| 177 | 177 | |
| 178 | - foreach ($route['body'] as &$rule) { |
|
| 179 | - if (strpos($rule, 'unique')) { |
|
| 180 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
| 181 | - } elseif (strpos($rule, 'exists')) { |
|
| 182 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } |
|
| 178 | + foreach ($route['body'] as &$rule) { |
|
| 179 | + if (strpos($rule, 'unique')) { |
|
| 180 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
| 181 | + } elseif (strpos($rule, 'exists')) { |
|
| 182 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Generate application errors. |
|
| 192 | - * |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - protected function getErrors() |
|
| 196 | - { |
|
| 197 | - $errors = []; |
|
| 198 | - foreach (\Module::all() as $module) { |
|
| 199 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 200 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 201 | - $reflectionClass = new \ReflectionClass($class); |
|
| 202 | - foreach ($reflectionClass->getMethods() as $method) { |
|
| 203 | - $methodName = $method->name; |
|
| 204 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
| 205 | - $body = $this->getMethodBody($reflectionMethod); |
|
| 190 | + /** |
|
| 191 | + * Generate application errors. |
|
| 192 | + * |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + protected function getErrors() |
|
| 196 | + { |
|
| 197 | + $errors = []; |
|
| 198 | + foreach (\Module::all() as $module) { |
|
| 199 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 200 | + $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 201 | + $reflectionClass = new \ReflectionClass($class); |
|
| 202 | + foreach ($reflectionClass->getMethods() as $method) { |
|
| 203 | + $methodName = $method->name; |
|
| 204 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
| 205 | + $body = $this->getMethodBody($reflectionMethod); |
|
| 206 | 206 | |
| 207 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
| 207 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
| 208 | 208 | |
| 209 | - if (count($match)) { |
|
| 210 | - $errors[$match[1]][] = $methodName; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 209 | + if (count($match)) { |
|
| 210 | + $errors[$match[1]][] = $methodName; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return $errors; |
|
| 216 | - } |
|
| 215 | + return $errors; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * Get the given method body code. |
|
| 220 | - * |
|
| 221 | - * @param object $reflectionMethod |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - protected function getMethodBody($reflectionMethod) |
|
| 225 | - { |
|
| 226 | - $filename = $reflectionMethod->getFileName(); |
|
| 227 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
| 228 | - $end_line = $reflectionMethod->getEndLine(); |
|
| 229 | - $length = $end_line - $start_line; |
|
| 230 | - $source = file($filename); |
|
| 231 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
| 232 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
| 218 | + /** |
|
| 219 | + * Get the given method body code. |
|
| 220 | + * |
|
| 221 | + * @param object $reflectionMethod |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + protected function getMethodBody($reflectionMethod) |
|
| 225 | + { |
|
| 226 | + $filename = $reflectionMethod->getFileName(); |
|
| 227 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
| 228 | + $end_line = $reflectionMethod->getEndLine(); |
|
| 229 | + $length = $end_line - $start_line; |
|
| 230 | + $source = file($filename); |
|
| 231 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
| 232 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
| 233 | 233 | |
| 234 | - return $body; |
|
| 235 | - } |
|
| 234 | + return $body; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Get example object of all availble models. |
|
| 239 | - * |
|
| 240 | - * @param string $modelName |
|
| 241 | - * @param array $docData |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - protected function getModels($modelName, &$docData, $reflectionClass) |
|
| 245 | - { |
|
| 246 | - if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
| 247 | - $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
| 248 | - $model = factory($modelClass)->make(); |
|
| 237 | + /** |
|
| 238 | + * Get example object of all availble models. |
|
| 239 | + * |
|
| 240 | + * @param string $modelName |
|
| 241 | + * @param array $docData |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + protected function getModels($modelName, &$docData, $reflectionClass) |
|
| 245 | + { |
|
| 246 | + if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
| 247 | + $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
| 248 | + $model = factory($modelClass)->make(); |
|
| 249 | 249 | |
| 250 | - $property = $reflectionClass->getProperty('modelResource'); |
|
| 251 | - $property->setAccessible(true); |
|
| 252 | - $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
| 253 | - $modelResource = new $modelResource($model); |
|
| 254 | - $modelArr = $modelResource->toArray([]); |
|
| 250 | + $property = $reflectionClass->getProperty('modelResource'); |
|
| 251 | + $property->setAccessible(true); |
|
| 252 | + $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
| 253 | + $modelResource = new $modelResource($model); |
|
| 254 | + $modelArr = $modelResource->toArray([]); |
|
| 255 | 255 | |
| 256 | - foreach ($modelArr as $key => $attr) { |
|
| 257 | - if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
| 258 | - unset($modelArr[$key]); |
|
| 259 | - } |
|
| 260 | - } |
|
| 256 | + foreach ($modelArr as $key => $attr) { |
|
| 257 | + if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
| 258 | + unset($modelArr[$key]); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
| 263 | - } |
|
| 264 | - } |
|
| 262 | + $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Get the route response object type. |
|
| 268 | - * |
|
| 269 | - * @param string $modelName |
|
| 270 | - * @param string $method |
|
| 271 | - * @param string $returnDocBlock |
|
| 272 | - * @return array |
|
| 273 | - */ |
|
| 274 | - protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
| 275 | - { |
|
| 276 | - $config = \CoreConfig::getConfig(); |
|
| 277 | - $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
| 278 | - $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
| 266 | + /** |
|
| 267 | + * Get the route response object type. |
|
| 268 | + * |
|
| 269 | + * @param string $modelName |
|
| 270 | + * @param string $method |
|
| 271 | + * @param string $returnDocBlock |
|
| 272 | + * @return array |
|
| 273 | + */ |
|
| 274 | + protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
| 275 | + { |
|
| 276 | + $config = \CoreConfig::getConfig(); |
|
| 277 | + $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
| 278 | + $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
| 279 | 279 | |
| 280 | - return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
| 281 | - } |
|
| 280 | + return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
| 281 | + } |
|
| 282 | 282 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected function getRoutes() |
| 92 | 92 | { |
| 93 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
| 93 | + return collect(\Route::getRoutes())->map(function($route) { |
|
| 94 | 94 | if (strpos($route->uri(), 'api/') !== false) { |
| 95 | 95 | return [ |
| 96 | 96 | 'method' => $route->methods()[0], |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | ]; |
| 122 | 122 | |
| 123 | 123 | |
| 124 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 124 | + if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
| 125 | 125 | $route['headers']['Authorization'] = 'Bearer {token}'; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | if (count($parameters)) { |
| 170 | 170 | $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
| 171 | 171 | if ($className) { |
| 172 | - $reflectionClass = new \ReflectionClass($className); |
|
| 172 | + $reflectionClass = new \ReflectionClass($className); |
|
| 173 | 173 | |
| 174 | 174 | if ($reflectionClass->hasMethod('rules')) { |
| 175 | 175 | $reflectionMethod = $reflectionClass->getMethod('rules'); |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | $errors = []; |
| 198 | 198 | foreach (\Module::all() as $module) { |
| 199 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 200 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 199 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
| 200 | + $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors'; |
|
| 201 | 201 | $reflectionClass = new \ReflectionClass($class); |
| 202 | 202 | foreach ($reflectionClass->getMethods() as $method) { |
| 203 | 203 | $methodName = $method->name; |
@@ -4,46 +4,46 @@ |
||
| 4 | 4 | |
| 5 | 5 | trait Translatable |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Create a new model instance that is existing. |
|
| 9 | - * |
|
| 10 | - * @param array $attributes |
|
| 11 | - * @param string|null $connection |
|
| 12 | - * @return static |
|
| 13 | - */ |
|
| 14 | - public function newFromBuilder($attributes = [], $connection = null) |
|
| 15 | - { |
|
| 16 | - $model = parent::newFromBuilder($attributes, $connection); |
|
| 17 | - |
|
| 18 | - foreach ($model->attributes as $key => $value) { |
|
| 19 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
| 20 | - $model->$key = $this->getTranslatedAttribute($value); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - return $model; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | - * |
|
| 30 | - * @param $values |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - protected function getTranslatedAttribute($values) |
|
| 34 | - { |
|
| 35 | - $values = json_decode($values); |
|
| 36 | - $primaryLocale = \Session::get('locale'); |
|
| 37 | - $fallbackLocale = 'en'; |
|
| 38 | - |
|
| 39 | - if ($primaryLocale == 'all') { |
|
| 40 | - return $values; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 44 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 48 | - } |
|
| 7 | + /** |
|
| 8 | + * Create a new model instance that is existing. |
|
| 9 | + * |
|
| 10 | + * @param array $attributes |
|
| 11 | + * @param string|null $connection |
|
| 12 | + * @return static |
|
| 13 | + */ |
|
| 14 | + public function newFromBuilder($attributes = [], $connection = null) |
|
| 15 | + { |
|
| 16 | + $model = parent::newFromBuilder($attributes, $connection); |
|
| 17 | + |
|
| 18 | + foreach ($model->attributes as $key => $value) { |
|
| 19 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
| 20 | + $model->$key = $this->getTranslatedAttribute($value); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + return $model; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | + * |
|
| 30 | + * @param $values |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + protected function getTranslatedAttribute($values) |
|
| 34 | + { |
|
| 35 | + $values = json_decode($values); |
|
| 36 | + $primaryLocale = \Session::get('locale'); |
|
| 37 | + $fallbackLocale = 'en'; |
|
| 38 | + |
|
| 39 | + if ($primaryLocale == 'all') { |
|
| 40 | + return $values; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 44 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -4,33 +4,33 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CoreErrors |
| 6 | 6 | { |
| 7 | - public function connectionError() |
|
| 8 | - { |
|
| 9 | - abort(500, trans('core::errors.connectionError')); |
|
| 10 | - } |
|
| 7 | + public function connectionError() |
|
| 8 | + { |
|
| 9 | + abort(500, trans('core::errors.connectionError')); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function redisNotRunning() |
|
| 13 | - { |
|
| 14 | - abort(500, trans('core::errors.redisNotRunning')); |
|
| 15 | - } |
|
| 12 | + public function redisNotRunning() |
|
| 13 | + { |
|
| 14 | + abort(500, trans('core::errors.redisNotRunning')); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function dbQueryError() |
|
| 18 | - { |
|
| 19 | - abort(500, trans('core::errors.dbQueryError')); |
|
| 20 | - } |
|
| 17 | + public function dbQueryError() |
|
| 18 | + { |
|
| 19 | + abort(500, trans('core::errors.dbQueryError')); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function cannotCreateSetting() |
|
| 23 | - { |
|
| 24 | - abort(400, trans('core::errors.cannotCreateSetting')); |
|
| 25 | - } |
|
| 22 | + public function cannotCreateSetting() |
|
| 23 | + { |
|
| 24 | + abort(400, trans('core::errors.cannotCreateSetting')); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function cannotUpdateSettingKey() |
|
| 28 | - { |
|
| 29 | - abort(400, trans('core::errors.cannotUpdateSettingKey')); |
|
| 30 | - } |
|
| 27 | + public function cannotUpdateSettingKey() |
|
| 28 | + { |
|
| 29 | + abort(400, trans('core::errors.cannotUpdateSettingKey')); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function notFound($text) |
|
| 33 | - { |
|
| 34 | - abort(404, trans('core::errors.notFound', ['replace' => $text])); |
|
| 35 | - } |
|
| 32 | + public function notFound($text) |
|
| 33 | + { |
|
| 34 | + abort(404, trans('core::errors.notFound', ['replace' => $text])); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -6,26 +6,26 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Errors implements BaseFactoryInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Construct the repository class name based on |
|
| 11 | - * the method name called, search in the |
|
| 12 | - * given namespaces for the class and |
|
| 13 | - * return an instance. |
|
| 14 | - * |
|
| 15 | - * @param string $name the called method name |
|
| 16 | - * @param array $arguments the method arguments |
|
| 17 | - * @return object |
|
| 18 | - */ |
|
| 19 | - public function __call($name, $arguments) |
|
| 20 | - { |
|
| 21 | - foreach (\Module::all() as $module) { |
|
| 22 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
| 23 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 9 | + /** |
|
| 10 | + * Construct the repository class name based on |
|
| 11 | + * the method name called, search in the |
|
| 12 | + * given namespaces for the class and |
|
| 13 | + * return an instance. |
|
| 14 | + * |
|
| 15 | + * @param string $name the called method name |
|
| 16 | + * @param array $arguments the method arguments |
|
| 17 | + * @return object |
|
| 18 | + */ |
|
| 19 | + public function __call($name, $arguments) |
|
| 20 | + { |
|
| 21 | + foreach (\Module::all() as $module) { |
|
| 22 | + $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
| 23 | + $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 24 | 24 | |
| 25 | - if (class_exists($class)) { |
|
| 26 | - $class = \App::make($class); |
|
| 27 | - if (method_exists($class, $name)) return call_user_func_array([$class, $name], $arguments); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - } |
|
| 25 | + if (class_exists($class)) { |
|
| 26 | + $class = \App::make($class); |
|
| 27 | + if (method_exists($class, $name)) return call_user_func_array([$class, $name], $arguments); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | public function __call($name, $arguments) |
| 20 | 20 | { |
| 21 | 21 | foreach (\Module::all() as $module) { |
| 22 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
| 23 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 22 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
| 23 | + $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors'; |
|
| 24 | 24 | |
| 25 | 25 | if (class_exists($class)) { |
| 26 | 26 | $class = \App::make($class); |
@@ -24,7 +24,9 @@ |
||
| 24 | 24 | |
| 25 | 25 | if (class_exists($class)) { |
| 26 | 26 | $class = \App::make($class); |
| 27 | - if (method_exists($class, $name)) return call_user_func_array([$class, $name], $arguments); |
|
| 27 | + if (method_exists($class, $name)) { |
|
| 28 | + return call_user_func_array([$class, $name], $arguments); |
|
| 29 | + } |
|
| 28 | 30 | } |
| 29 | 31 | } |
| 30 | 32 | } |