Skip to content

Commit b03673b

Browse files
committed
Refactor ShortcodeServiceProvider and ThemeServiceProvider for improved readability and maintainability; update caching logic in Helpers to enhance performance and reduce redundancy.
1 parent 9d8513e commit b03673b

8 files changed

+37
-36
lines changed

src/Http/Controllers/ApplicationController.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
use Coderstm\Models\Task;
77
use Illuminate\Support\Str;
88
use Coderstm\Mail\TestEmail;
9+
use Coderstm\Services\Theme;
910
use Illuminate\Http\Request;
1011
use Coderstm\Models\AppSetting;
1112
use Coderstm\Models\PaymentMethod;
1213
use Illuminate\Support\Facades\DB;
1314
use Illuminate\Support\Facades\Mail;
1415
use Illuminate\Support\Facades\Blade;
16+
use Illuminate\Support\Facades\Cache;
1517
use Illuminate\Support\Facades\Config;
1618
use Coderstm\Http\Controllers\Controller;
17-
use Coderstm\Services\Theme;
1819

1920
class ApplicationController extends Controller
2021
{
@@ -83,6 +84,10 @@ public function updateSettings(Request $request)
8384

8485
AppSetting::updateOptions($request->key, $request->options ?? [], $merge);
8586

87+
// Clear the cache for the specific key
88+
$cacheKey = "app_config_{$request->key}";
89+
Cache::forget($cacheKey);
90+
8691
return response()->json([
8792
'message' => trans('messages.settings_update')
8893
], 200);

src/Providers/CoderstmEventServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/* __________________________________________________
33
| Obfuscated by YAK Pro - Php Obfuscator 2.0.16 |
4-
| on 2025-04-16 10:35:11 |
4+
| on 2025-04-20 17:43:38 |
55
| GitHub: https://github.com/pk-fr/yakpro-po |
66
|__________________________________________________|
77
*/
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/* __________________________________________________
33
| Obfuscated by YAK Pro - Php Obfuscator 2.0.16 |
4-
| on 2025-04-16 10:35:11 |
4+
| on 2025-04-20 17:43:37 |
55
| GitHub: https://github.com/pk-fr/yakpro-po |
66
|__________________________________________________|
77
*/
88
/*
99
1010
*/
11-
namespace Coderstm\Providers; use Coderstm\Models\Permission; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; class CoderstmPermissionsServiceProvider extends ServiceProvider { public function register() { } public function boot() { try { goto V8Kjt; V8Kjt: Permission::get()->map(function ($permission) { Gate::define($permission->scope, function ($user) use($permission) { return $user->hasPermission($permission->scope); }); }); goto gEwVd; dzcAW: Blade::directive("\145\x6e\x64\147\x72\x6f\165\x70", function ($group) { return "\145\156\x64\x69\146\73"; }); goto CPFJ5; gEwVd: Blade::directive("\x67\x72\157\165\160", function ($group, $guard = "\x75\163\145\x72\163") { return "\151\x66\50\x67\165\141\162\144\x28\51\40\75\x3d\40{$guard}\40\46\46\40\x75\163\145\x72\x28\51\55\x3e\150\x61\163\107\162\x6f\x75\160\50{$group}\51\51\x20\x3a"; }); goto dzcAW; CPFJ5: } catch (\Exception $e) { report($e); } } }
11+
namespace Coderstm\Providers; use Coderstm\Models\Permission; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; class CoderstmPermissionsServiceProvider extends ServiceProvider { public function register() { } public function boot() { try { goto sUg0T; sUg0T: Permission::get()->map(function ($permission) { Gate::define($permission->scope, function ($user) use($permission) { return $user->hasPermission($permission->scope); }); }); goto Qos4u; Qos4u: Blade::directive("\147\x72\x6f\x75\x70", function ($group, $guard = "\x75\163\x65\x72\x73") { return "\151\x66\x28\x67\x75\x61\162\144\50\x29\40\x3d\x3d\40{$guard}\40\x26\x26\40\165\163\x65\x72\x28\x29\x2d\x3e\x68\141\x73\x47\x72\x6f\165\x70\50{$group}\51\x29\x20\x3a"; }); goto f0wJQ; f0wJQ: Blade::directive("\145\156\144\x67\x72\157\165\x70", function ($group) { return "\x65\156\144\151\x66\x3b"; }); goto SOTNr; SOTNr: } catch (\Exception $e) { report($e); } } }

src/Providers/CoderstmServiceProvider.php

+2-2
Large diffs are not rendered by default.

src/Providers/License.php

+2-2
Large diffs are not rendered by default.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/* __________________________________________________
33
| Obfuscated by YAK Pro - Php Obfuscator 2.0.16 |
4-
| on 2025-04-16 10:35:11 |
4+
| on 2025-04-20 17:43:37 |
55
| GitHub: https://github.com/pk-fr/yakpro-po |
66
|__________________________________________________|
77
*/
88
/*
99
1010
*/
11-
namespace Coderstm\Providers; use Coderstm\Shortcodes as Component; use Illuminate\Support\ServiceProvider; use Vedmant\LaravelShortcodes\Facades\Shortcodes; class ShortcodeServiceProvider extends ServiceProvider { public function register() : void { } public function boot() : void { goto hd9XF; SPNPC: Shortcodes::add("\160\x61\147\x65\55\x74\x69\164\x6c\145", function ($atts, $content, $tag, $manager) { return request()->input("\160\141\147\145\56\164\x69\164\x6c\145"); }); goto x8l5o; hd9XF: Shortcodes::add(["\x70\x6c\x61\156\163" => Component\Plans::class, "\143\141\154\x65\156\144\x61\x72" => Component\Calendar::class, "\157\160\145\156\x69\156\x67\x2d\164\151\x6d\145\163" => Component\OpeningTimes::class, "\143\157\x6e\x74\x61\143\164\x2d\146\x6f\162\x6d" => Component\ContactForm::class, "\x62\154\x6f\x67\163" => Component\Blogs::class, "\150\145\141\144\x65\162" => Component\Header::class, "\x66\x6f\x6f\x74\x65\162" => Component\Footer::class, "\x6d\145\x6e\165" => Component\Menu::class, "\143\157\155\x70\141\156\x79\x2d\x61\144\144\162\145\x73\x73" => Component\CompanyAddress::class, "\x65\x6d\141\x69\154" => Component\Email::class, "\160\150\x6f\x6e\x65" => Component\Phone::class, "\163\x6f\143\x69\141\x6c\163" => Component\Socials::class, "\142\x6c\157\147" => Component\Blog::class, "\162\145\x63\145\x6e\164\55\142\x6c\157\x67\163" => Component\RecentBlogs::class, "\142\x6c\157\147\55\x74\141\x67\163" => Component\BlogTags::class]); goto pCJIp; pCJIp: Shortcodes::add("\142\154\157\147\x2d\164\151\x74\x6c\145", function ($atts, $content, $tag, $manager) { return request()->input("\142\154\157\147\x2e\164\x69\x74\x6c\x65"); }); goto SPNPC; x8l5o: } }
11+
namespace Coderstm\Providers; use Coderstm\Shortcodes as Component; use Illuminate\Support\ServiceProvider; use Vedmant\LaravelShortcodes\Facades\Shortcodes; class ShortcodeServiceProvider extends ServiceProvider { public function register() : void { } public function boot() : void { goto PFJml; Bwzza: Shortcodes::add("\160\141\147\x65\x2d\x74\x69\164\x6c\x65", function ($atts, $content, $tag, $manager) { return request()->input("\x70\141\x67\x65\x2e\164\x69\164\x6c\145"); }); goto HEP4p; PFJml: Shortcodes::add(["\x70\x6c\x61\x6e\x73" => Component\Plans::class, "\x63\141\154\145\156\x64\141\162" => Component\Calendar::class, "\x6f\x70\145\156\151\156\147\x2d\164\151\155\x65\x73" => Component\OpeningTimes::class, "\x63\x6f\156\164\x61\x63\x74\55\x66\x6f\162\x6d" => Component\ContactForm::class, "\142\154\x6f\x67\163" => Component\Blogs::class, "\x68\x65\141\144\x65\x72" => Component\Header::class, "\x66\157\157\x74\145\x72" => Component\Footer::class, "\155\x65\156\165" => Component\Menu::class, "\143\157\x6d\160\x61\156\171\x2d\x61\144\144\162\x65\x73\x73" => Component\CompanyAddress::class, "\x65\x6d\x61\151\154" => Component\Email::class, "\x70\x68\x6f\156\x65" => Component\Phone::class, "\163\157\143\151\141\x6c\x73" => Component\Socials::class, "\x62\154\157\x67" => Component\Blog::class, "\x72\x65\x63\145\156\x74\x2d\x62\154\x6f\x67\163" => Component\RecentBlogs::class, "\x62\154\157\x67\x2d\164\141\147\163" => Component\BlogTags::class]); goto AtDWM; AtDWM: Shortcodes::add("\142\x6c\x6f\147\55\164\x69\x74\x6c\145", function ($atts, $content, $tag, $manager) { return request()->input("\x62\154\x6f\x67\56\x74\x69\x74\154\x65"); }); goto Bwzza; HEP4p: } }
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
/* __________________________________________________
33
| Obfuscated by YAK Pro - Php Obfuscator 2.0.16 |
4-
| on 2025-04-16 10:35:11 |
4+
| on 2025-04-20 17:43:38 |
55
| GitHub: https://github.com/pk-fr/yakpro-po |
66
|__________________________________________________|
77
*/
88
/*
99
1010
*/
11-
namespace Coderstm\Providers; use Coderstm\Services\Mix; use Coderstm\Services\Theme; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Coderstm\Services\MaskSensitiveConfig; use Coderstm\Http\Middleware\RequestThemeMiddleware; class ThemeServiceProvider extends ServiceProvider { public function register() : void { $this->app->singleton(Mix::class); $this->app->singleton("\x62\x6c\x61\x64\145\56\x63\x6f\155\160\x69\x6c\x65\162", function () { return new MaskSensitiveConfig($this->app["\x66\x69\154\145\163"], $this->app["\x63\x6f\x6e\146\x69\147"]["\x76\151\145\167\x2e\x63\x6f\x6d\160\x69\154\145\144"]); }); } public function boot() : void { goto s0bN5; FgOvj: $kernel->pushMiddleware(RequestThemeMiddleware::class); goto ewMFa; znVG6: $kernel = $this->app->make("\111\154\154\x75\155\x69\156\x61\164\x65\134\x43\157\156\164\162\141\x63\x74\163\x5c\110\164\164\160\x5c\113\145\x72\x6e\145\154"); goto FgOvj; H6AJc: y7UYF: goto znVG6; s0bN5: if (!($theme = settings("\164\x68\x65\x6d\145", "\141\x63\x74\x69\x76\x65"))) { goto y7UYF; } goto tBggu; tBggu: Theme::set($theme); goto H6AJc; ewMFa: } }
11+
namespace Coderstm\Providers; use Coderstm\Services\Mix; use Coderstm\Services\Theme; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Coderstm\Services\MaskSensitiveConfig; use Coderstm\Http\Middleware\RequestThemeMiddleware; class ThemeServiceProvider extends ServiceProvider { public function register() : void { $this->app->singleton(Mix::class); $this->app->singleton("\142\154\x61\x64\145\x2e\143\157\x6d\x70\151\154\145\162", function () { return new MaskSensitiveConfig($this->app["\x66\151\154\145\163"], $this->app["\x63\157\156\146\x69\147"]["\x76\151\x65\x77\x2e\x63\x6f\155\160\x69\x6c\x65\x64"]); }); } public function boot() : void { goto Em0HD; y5R_i: thG7u: goto I6mnz; IzWD7: Theme::set($theme); goto y5R_i; Em0HD: if (!($theme = settings("\164\x68\x65\x6d\145", "\x61\143\x74\x69\x76\145"))) { goto thG7u; } goto IzWD7; P9k3f: $kernel->pushMiddleware(RequestThemeMiddleware::class); goto sM7Za; I6mnz: $kernel = $this->app->make("\111\x6c\154\165\155\x69\x6e\x61\164\145\x5c\x43\157\156\x74\162\x61\x63\164\x73\134\110\x74\164\x70\134\113\145\162\x6e\145\x6c"); goto P9k3f; sM7Za: } }

src/Services/Helpers.php

+20-24
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ public static function location()
3535
public static function loadConfigFromDatabase(...$keys): void
3636
{
3737
try {
38-
$cacheKey = 'app_config_' . md5(implode('_', $keys));
39-
$cacheDuration = 60; // Cache for 60 minutes
40-
41-
// Return from cache if available
42-
if (Cache::has($cacheKey)) {
43-
$cachedConfigs = Cache::get($cacheKey);
44-
foreach ($cachedConfigs as $key => $configs) {
45-
foreach ($configs as $alias => $items) {
46-
foreach ($items as $attr => $value) {
47-
Config::set("$alias.$attr", $value);
48-
}
49-
}
50-
}
51-
return;
52-
}
53-
5438
$options = [
5539
'config' => [
5640
'alias' => 'app',
@@ -64,19 +48,31 @@ public static function loadConfigFromDatabase(...$keys): void
6448
]
6549
];
6650

67-
$cachedConfigs = [];
68-
6951
foreach ($keys as $key) {
52+
$cacheKey = "app_config_{$key}";
53+
$cacheDuration = 24 * 60 * 60; // Cache for 24 hours
54+
55+
// Return from cache if available
56+
if (Cache::has($cacheKey)) {
57+
$cachedConfig = Cache::get($cacheKey);
58+
$alias = array_key_first($cachedConfig);
59+
60+
foreach ($cachedConfig[$alias] as $attr => $value) {
61+
Config::set("$alias.$attr", $value);
62+
}
63+
64+
continue;
65+
}
66+
7067
// Determine the alias to use, defaulting to the key if not specified
7168
$option = $options[$key] ?? [];
7269
$alias = $option['alias'] ?? $key;
73-
$cachedConfigs[$key] = [];
74-
$cachedConfigs[$key][$alias] = [];
70+
$cachedConfig = [$alias => []];
7571

7672
// Fetch settings from the database
7773
foreach (app_settings($key) as $attr => $value) {
7874
// Store for caching
79-
$cachedConfigs[$key][$alias][$attr] = $value;
75+
$cachedConfig[$alias][$attr] = $value;
8076

8177
// Set the configuration value in the application's config
8278
Config::set("$alias.$attr", $value);
@@ -99,10 +95,10 @@ public static function loadConfigFromDatabase(...$keys): void
9995
}
10096
}
10197
}
102-
}
10398

104-
// Store in cache
105-
Cache::put($cacheKey, $cachedConfigs, now()->addMinutes($cacheDuration));
99+
// Store in cache
100+
Cache::put($cacheKey, $cachedConfig, now()->addMinutes($cacheDuration));
101+
}
106102
} catch (\Exception $e) {
107103
throw $e;
108104
}

0 commit comments

Comments
 (0)