@@ -7,56 +7,56 @@ |
||
| 7 | 7 | |
| 8 | 8 | class PushNotificationDeviceRepository extends AbstractRepository |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Return the model full namespace. |
|
| 12 | - * |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - protected function getModel() |
|
| 16 | - { |
|
| 17 | - return 'App\Modules\V1\Notifications\PushNotificationDevice'; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Register the given device to the logged in user. |
|
| 22 | - * |
|
| 23 | - * @param string $data |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - public function registerDevice($data) |
|
| 27 | - { |
|
| 28 | - $data['access_token'] = \Auth::user()->token(); |
|
| 29 | - $data['user_id'] = \Auth::id(); |
|
| 30 | - if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) |
|
| 31 | - { |
|
| 32 | - $data['id'] = $device->id; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - return $this->save($data); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Generate the given message data. |
|
| 40 | - * |
|
| 41 | - * @param string $title |
|
| 42 | - * @param string $message |
|
| 43 | - * @param string $data |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function generateMessageData($title, $message, $data = []) |
|
| 47 | - { |
|
| 48 | - $optionBuilder = new OptionsBuilder(); |
|
| 49 | - $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 50 | - $dataBuilder = new PayloadDataBuilder(); |
|
| 51 | - |
|
| 52 | - $optionBuilder->setTimeToLive(60*20); |
|
| 53 | - $notificationBuilder->setBody($message); |
|
| 54 | - $dataBuilder->addData($data); |
|
| 55 | - |
|
| 56 | - $options = $optionBuilder->build(); |
|
| 57 | - $notification = $notificationBuilder->build(); |
|
| 58 | - $data = $dataBuilder->build(); |
|
| 59 | - |
|
| 60 | - return compact('options', 'notification', 'data'); |
|
| 61 | - } |
|
| 10 | + /** |
|
| 11 | + * Return the model full namespace. |
|
| 12 | + * |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + protected function getModel() |
|
| 16 | + { |
|
| 17 | + return 'App\Modules\V1\Notifications\PushNotificationDevice'; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Register the given device to the logged in user. |
|
| 22 | + * |
|
| 23 | + * @param string $data |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + public function registerDevice($data) |
|
| 27 | + { |
|
| 28 | + $data['access_token'] = \Auth::user()->token(); |
|
| 29 | + $data['user_id'] = \Auth::id(); |
|
| 30 | + if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) |
|
| 31 | + { |
|
| 32 | + $data['id'] = $device->id; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + return $this->save($data); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Generate the given message data. |
|
| 40 | + * |
|
| 41 | + * @param string $title |
|
| 42 | + * @param string $message |
|
| 43 | + * @param string $data |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function generateMessageData($title, $message, $data = []) |
|
| 47 | + { |
|
| 48 | + $optionBuilder = new OptionsBuilder(); |
|
| 49 | + $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 50 | + $dataBuilder = new PayloadDataBuilder(); |
|
| 51 | + |
|
| 52 | + $optionBuilder->setTimeToLive(60*20); |
|
| 53 | + $notificationBuilder->setBody($message); |
|
| 54 | + $dataBuilder->addData($data); |
|
| 55 | + |
|
| 56 | + $options = $optionBuilder->build(); |
|
| 57 | + $notification = $notificationBuilder->build(); |
|
| 58 | + $data = $dataBuilder->build(); |
|
| 59 | + |
|
| 60 | + return compact('options', 'notification', 'data'); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -5,53 +5,53 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class NotificationObserver { |
| 7 | 7 | |
| 8 | - public function saving($model) |
|
| 9 | - { |
|
| 10 | - // |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function saved($model) |
|
| 14 | - { |
|
| 15 | - // |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function creating($model) |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function created($model) |
|
| 24 | - { |
|
| 25 | - // |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function updating($model) |
|
| 29 | - { |
|
| 30 | - // |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function updated($model) |
|
| 34 | - { |
|
| 35 | - // |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function deleting($model) |
|
| 39 | - { |
|
| 40 | - // |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function deleted($model) |
|
| 44 | - { |
|
| 45 | - // |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function restoring($model) |
|
| 49 | - { |
|
| 50 | - // |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function restored($model) |
|
| 54 | - { |
|
| 55 | - // |
|
| 56 | - } |
|
| 8 | + public function saving($model) |
|
| 9 | + { |
|
| 10 | + // |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function saved($model) |
|
| 14 | + { |
|
| 15 | + // |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function creating($model) |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function created($model) |
|
| 24 | + { |
|
| 25 | + // |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function updating($model) |
|
| 29 | + { |
|
| 30 | + // |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function updated($model) |
|
| 34 | + { |
|
| 35 | + // |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function deleting($model) |
|
| 39 | + { |
|
| 40 | + // |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function deleted($model) |
|
| 44 | + { |
|
| 45 | + // |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function restoring($model) |
|
| 49 | + { |
|
| 50 | + // |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function restored($model) |
|
| 54 | + { |
|
| 55 | + // |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -4,65 +4,65 @@ |
||
| 4 | 4 | |
| 5 | 5 | class MakeNotificationsCommand extends GeneratorCommand |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * The name and signature of the console command. |
|
| 9 | - * |
|
| 10 | - * @var string |
|
| 11 | - */ |
|
| 12 | - protected $signature = 'make:module:notification |
|
| 7 | + /** |
|
| 8 | + * The name and signature of the console command. |
|
| 9 | + * |
|
| 10 | + * @var string |
|
| 11 | + */ |
|
| 12 | + protected $signature = 'make:module:notification |
|
| 13 | 13 | {name : The name of the notification class.}'; |
| 14 | - /** |
|
| 15 | - * The console command description. |
|
| 16 | - * |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $description = 'Create a new module notification class'; |
|
| 20 | - /** |
|
| 21 | - * String to store the command type. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $type = 'Module notification'; |
|
| 26 | - /** |
|
| 27 | - * Get the stub file for the generator. |
|
| 28 | - * |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - protected function getStub() |
|
| 32 | - { |
|
| 33 | - return __DIR__.'/stubs/notification.stub'; |
|
| 34 | - } |
|
| 35 | - /** |
|
| 36 | - * Get the destination class path. |
|
| 37 | - * |
|
| 38 | - * @param string $name |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - protected function getPath($name) |
|
| 43 | - { |
|
| 44 | - return module_path('notifications', 'Notifications/'.$name.'.php'); |
|
| 45 | - } |
|
| 46 | - /** |
|
| 47 | - * Parse the name and format according to the root namespace. |
|
| 48 | - * |
|
| 49 | - * @param string $name |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - protected function qualifyClass($name) |
|
| 54 | - { |
|
| 55 | - return $name; |
|
| 56 | - } |
|
| 57 | - /** |
|
| 58 | - * Replace namespace in notification stub. |
|
| 59 | - * |
|
| 60 | - * @param string $name |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - protected function getNamespace($name) |
|
| 65 | - { |
|
| 66 | - return module_class('notifications', 'Notifications'); |
|
| 67 | - } |
|
| 14 | + /** |
|
| 15 | + * The console command description. |
|
| 16 | + * |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $description = 'Create a new module notification class'; |
|
| 20 | + /** |
|
| 21 | + * String to store the command type. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $type = 'Module notification'; |
|
| 26 | + /** |
|
| 27 | + * Get the stub file for the generator. |
|
| 28 | + * |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + protected function getStub() |
|
| 32 | + { |
|
| 33 | + return __DIR__.'/stubs/notification.stub'; |
|
| 34 | + } |
|
| 35 | + /** |
|
| 36 | + * Get the destination class path. |
|
| 37 | + * |
|
| 38 | + * @param string $name |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + protected function getPath($name) |
|
| 43 | + { |
|
| 44 | + return module_path('notifications', 'Notifications/'.$name.'.php'); |
|
| 45 | + } |
|
| 46 | + /** |
|
| 47 | + * Parse the name and format according to the root namespace. |
|
| 48 | + * |
|
| 49 | + * @param string $name |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + protected function qualifyClass($name) |
|
| 54 | + { |
|
| 55 | + return $name; |
|
| 56 | + } |
|
| 57 | + /** |
|
| 58 | + * Replace namespace in notification stub. |
|
| 59 | + * |
|
| 60 | + * @param string $name |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + protected function getNamespace($name) |
|
| 65 | + { |
|
| 66 | + return module_class('notifications', 'Notifications'); |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -6,46 +6,46 @@ |
||
| 6 | 6 | |
| 7 | 7 | class NotificationsTableSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - /** |
|
| 17 | - * Insert the permissions related to settings table. |
|
| 18 | - */ |
|
| 19 | - \DB::table('permissions')->insert( |
|
| 20 | - [ |
|
| 21 | - /** |
|
| 22 | - * notifications model permissions. |
|
| 23 | - */ |
|
| 24 | - [ |
|
| 25 | - 'name' => 'all', |
|
| 26 | - 'model' => 'notifications', |
|
| 27 | - 'created_at' => \DB::raw('NOW()'), |
|
| 28 | - 'updated_at' => \DB::raw('NOW()') |
|
| 29 | - ], |
|
| 30 | - [ |
|
| 31 | - 'name' => 'unread', |
|
| 32 | - 'model' => 'notifications', |
|
| 33 | - 'created_at' => \DB::raw('NOW()'), |
|
| 34 | - 'updated_at' => \DB::raw('NOW()') |
|
| 35 | - ], |
|
| 36 | - [ |
|
| 37 | - 'name' => 'markAsRead', |
|
| 38 | - 'model' => 'notifications', |
|
| 39 | - 'created_at' => \DB::raw('NOW()'), |
|
| 40 | - 'updated_at' => \DB::raw('NOW()') |
|
| 41 | - ], |
|
| 42 | - [ |
|
| 43 | - 'name' => 'markAllAsRead', |
|
| 44 | - 'model' => 'notifications', |
|
| 45 | - 'created_at' => \DB::raw('NOW()'), |
|
| 46 | - 'updated_at' => \DB::raw('NOW()') |
|
| 47 | - ] |
|
| 48 | - ] |
|
| 49 | - ); |
|
| 50 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + /** |
|
| 17 | + * Insert the permissions related to settings table. |
|
| 18 | + */ |
|
| 19 | + \DB::table('permissions')->insert( |
|
| 20 | + [ |
|
| 21 | + /** |
|
| 22 | + * notifications model permissions. |
|
| 23 | + */ |
|
| 24 | + [ |
|
| 25 | + 'name' => 'all', |
|
| 26 | + 'model' => 'notifications', |
|
| 27 | + 'created_at' => \DB::raw('NOW()'), |
|
| 28 | + 'updated_at' => \DB::raw('NOW()') |
|
| 29 | + ], |
|
| 30 | + [ |
|
| 31 | + 'name' => 'unread', |
|
| 32 | + 'model' => 'notifications', |
|
| 33 | + 'created_at' => \DB::raw('NOW()'), |
|
| 34 | + 'updated_at' => \DB::raw('NOW()') |
|
| 35 | + ], |
|
| 36 | + [ |
|
| 37 | + 'name' => 'markAsRead', |
|
| 38 | + 'model' => 'notifications', |
|
| 39 | + 'created_at' => \DB::raw('NOW()'), |
|
| 40 | + 'updated_at' => \DB::raw('NOW()') |
|
| 41 | + ], |
|
| 42 | + [ |
|
| 43 | + 'name' => 'markAllAsRead', |
|
| 44 | + 'model' => 'notifications', |
|
| 45 | + 'created_at' => \DB::raw('NOW()'), |
|
| 46 | + 'updated_at' => \DB::raw('NOW()') |
|
| 47 | + ] |
|
| 48 | + ] |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\V1\Notifications\Notification::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 4 | + return [ |
|
| 5 | 5 | 'type' => '', |
| 6 | 6 | 'notifiable_type' => '', |
| 7 | 7 | 'notifiable_id' => '', |
@@ -9,5 +9,5 @@ discard block |
||
| 9 | 9 | 'read_at' => null, |
| 10 | 10 | 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
| 11 | 11 | 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
| 12 | - ]; |
|
| 12 | + ]; |
|
| 13 | 13 | }); |
| 14 | 14 | \ No newline at end of file |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\V1\Notifications\PushNotificationDevice::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 4 | + return [ |
|
| 5 | 5 | 'device_token' => $faker->sha1(), |
| 6 | 6 | 'user_id' => $faker->randomDigitNotNull(), |
| 7 | 7 | 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
| 8 | 8 | 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
| 9 | - ]; |
|
| 9 | + ]; |
|
| 10 | 10 | }); |
| 11 | 11 | \ No newline at end of file |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Notifications extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create('notifications', function (Blueprint $table) { |
|
| 17 | - $table->uuid('id')->primary(); |
|
| 18 | - $table->string('type'); |
|
| 19 | - $table->morphs('notifiable'); |
|
| 20 | - $table->text('data'); |
|
| 21 | - $table->timestamp('read_at')->nullable(); |
|
| 22 | - $table->timestamps(); |
|
| 23 | - }); |
|
| 24 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create('notifications', function (Blueprint $table) { |
|
| 17 | + $table->uuid('id')->primary(); |
|
| 18 | + $table->string('type'); |
|
| 19 | + $table->morphs('notifiable'); |
|
| 20 | + $table->text('data'); |
|
| 21 | + $table->timestamp('read_at')->nullable(); |
|
| 22 | + $table->timestamps(); |
|
| 23 | + }); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Reverse the migrations. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function down() |
|
| 32 | - { |
|
| 33 | - Schema::dropIfExists('notifications'); |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Reverse the migrations. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function down() |
|
| 32 | + { |
|
| 33 | + Schema::dropIfExists('notifications'); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateFailedJobsTable extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create('failed_jobs', function (Blueprint $table) { |
|
| 17 | - $table->bigIncrements('id'); |
|
| 18 | - $table->text('connection'); |
|
| 19 | - $table->text('queue'); |
|
| 20 | - $table->longText('payload'); |
|
| 21 | - $table->longText('exception'); |
|
| 22 | - $table->timestamp('failed_at')->useCurrent(); |
|
| 23 | - }); |
|
| 24 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create('failed_jobs', function (Blueprint $table) { |
|
| 17 | + $table->bigIncrements('id'); |
|
| 18 | + $table->text('connection'); |
|
| 19 | + $table->text('queue'); |
|
| 20 | + $table->longText('payload'); |
|
| 21 | + $table->longText('exception'); |
|
| 22 | + $table->timestamp('failed_at')->useCurrent(); |
|
| 23 | + }); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Reverse the migrations. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function down() |
|
| 32 | - { |
|
| 33 | - Schema::dropIfExists('failed_jobs'); |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Reverse the migrations. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function down() |
|
| 32 | + { |
|
| 33 | + Schema::dropIfExists('failed_jobs'); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -2,117 +2,117 @@ |
||
| 2 | 2 | |
| 3 | 3 | class CachingDecorator |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * The repo implementation. |
|
| 7 | - * |
|
| 8 | - * @var string |
|
| 9 | - */ |
|
| 10 | - public $repo; |
|
| 5 | + /** |
|
| 6 | + * The repo implementation. |
|
| 7 | + * |
|
| 8 | + * @var string |
|
| 9 | + */ |
|
| 10 | + public $repo; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * The cache implementation. |
|
| 14 | - * |
|
| 15 | - * @var object |
|
| 16 | - */ |
|
| 17 | - protected $cache; |
|
| 12 | + /** |
|
| 13 | + * The cache implementation. |
|
| 14 | + * |
|
| 15 | + * @var object |
|
| 16 | + */ |
|
| 17 | + protected $cache; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The modelKey implementation. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $modelKey; |
|
| 19 | + /** |
|
| 20 | + * The modelKey implementation. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $modelKey; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The model implementation. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - public $model; |
|
| 26 | + /** |
|
| 27 | + * The model implementation. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + public $model; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The modelClass implementation. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $modelClass; |
|
| 33 | + /** |
|
| 34 | + * The modelClass implementation. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $modelClass; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The cacheConfig implementation. |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - public $cacheConfig; |
|
| 40 | + /** |
|
| 41 | + * The cacheConfig implementation. |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + public $cacheConfig; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The cacheTag implementation. |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - public $cacheTag; |
|
| 47 | + /** |
|
| 48 | + * The cacheTag implementation. |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + public $cacheTag; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Create new CachingDecorator instance. |
|
| 56 | - */ |
|
| 57 | - public function __construct($repo, $cache) |
|
| 58 | - { |
|
| 59 | - $this->repo = $repo; |
|
| 60 | - $this->cache = $cache; |
|
| 61 | - $this->model = $this->repo->model; |
|
| 62 | - $this->modelClass = get_class($this->model); |
|
| 63 | - $repoClass = explode('\\', get_class($this->repo)); |
|
| 64 | - $repoName = end($repoClass); |
|
| 65 | - $this->cacheTag = str_plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
| 66 | - } |
|
| 54 | + /** |
|
| 55 | + * Create new CachingDecorator instance. |
|
| 56 | + */ |
|
| 57 | + public function __construct($repo, $cache) |
|
| 58 | + { |
|
| 59 | + $this->repo = $repo; |
|
| 60 | + $this->cache = $cache; |
|
| 61 | + $this->model = $this->repo->model; |
|
| 62 | + $this->modelClass = get_class($this->model); |
|
| 63 | + $repoClass = explode('\\', get_class($this->repo)); |
|
| 64 | + $repoName = end($repoClass); |
|
| 65 | + $this->cacheTag = str_plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Handle the cache mechanism for the called method |
|
| 70 | - * based the configurations. |
|
| 71 | - * |
|
| 72 | - * @param string $name the called method name |
|
| 73 | - * @param array $arguments the method arguments |
|
| 74 | - * @return object |
|
| 75 | - */ |
|
| 76 | - public function __call($name, $arguments) |
|
| 77 | - { |
|
| 78 | - $this->setCacheConfig($name); |
|
| 68 | + /** |
|
| 69 | + * Handle the cache mechanism for the called method |
|
| 70 | + * based the configurations. |
|
| 71 | + * |
|
| 72 | + * @param string $name the called method name |
|
| 73 | + * @param array $arguments the method arguments |
|
| 74 | + * @return object |
|
| 75 | + */ |
|
| 76 | + public function __call($name, $arguments) |
|
| 77 | + { |
|
| 78 | + $this->setCacheConfig($name); |
|
| 79 | 79 | |
| 80 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') |
|
| 81 | - { |
|
| 82 | - $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
| 83 | - $cacheKey = $name . $page . \Session::get('locale') . serialize($arguments); |
|
| 84 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
| 85 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
| 86 | - }); |
|
| 87 | - } |
|
| 88 | - else if ($this->cacheConfig) |
|
| 89 | - { |
|
| 90 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
| 91 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
| 92 | - } |
|
| 80 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') |
|
| 81 | + { |
|
| 82 | + $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
| 83 | + $cacheKey = $name . $page . \Session::get('locale') . serialize($arguments); |
|
| 84 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
| 85 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
| 86 | + }); |
|
| 87 | + } |
|
| 88 | + else if ($this->cacheConfig) |
|
| 89 | + { |
|
| 90 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
| 91 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
| 95 | - } |
|
| 94 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Set cache config based on the called method. |
|
| 99 | - * |
|
| 100 | - * @param string $name |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - private function setCacheConfig($name) |
|
| 104 | - { |
|
| 105 | - $config = \CoreConfig::getConfig(); |
|
| 106 | - $cacheConfig = array_key_exists($this->cacheTag, $config['cacheConfig']) ? $config['cacheConfig'][$this->cacheTag] : false; |
|
| 107 | - $this->cacheConfig = false; |
|
| 97 | + /** |
|
| 98 | + * Set cache config based on the called method. |
|
| 99 | + * |
|
| 100 | + * @param string $name |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + private function setCacheConfig($name) |
|
| 104 | + { |
|
| 105 | + $config = \CoreConfig::getConfig(); |
|
| 106 | + $cacheConfig = array_key_exists($this->cacheTag, $config['cacheConfig']) ? $config['cacheConfig'][$this->cacheTag] : false; |
|
| 107 | + $this->cacheConfig = false; |
|
| 108 | 108 | |
| 109 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) |
|
| 110 | - { |
|
| 111 | - $this->cacheConfig = 'cache'; |
|
| 112 | - } |
|
| 113 | - else if ($cacheConfig && isset($cacheConfig['clear'][$name])) |
|
| 114 | - { |
|
| 115 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
| 116 | - } |
|
| 117 | - } |
|
| 109 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) |
|
| 110 | + { |
|
| 111 | + $this->cacheConfig = 'cache'; |
|
| 112 | + } |
|
| 113 | + else if ($cacheConfig && isset($cacheConfig['clear'][$name])) |
|
| 114 | + { |
|
| 115 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | \ No newline at end of file |