From 9f7d3616618a31bc3944f81cbcbd3a0b87871730 Mon Sep 17 00:00:00 2001 From: Andy Wermke Date: Thu, 6 Aug 2015 21:59:16 +0200 Subject: [PATCH] Implement ConfigCachingService, update controller and add JS code --- README.md | 18 ++++- config/config.php | 19 +++++ gulpfile.js | 4 +- package.json | 1 + public/js/localization.min.js | 2 +- resources/js/config.js | 35 +++++++++ src/Caching/AbstractCachingService.php | 37 +++++++-- src/Caching/ConfigCachingService.php | 67 ++++++++++++++-- src/Caching/MessageCachingService.php | 10 +-- src/Console/RefreshCommand.php | 2 + src/Facades/ConfigCachingService.php | 28 +++++++ src/Facades/MessageCachingService.php | 2 +- .../Controllers/JsLocalizationController.php | 77 +++++++++++++++---- src/Http/routes.php | 3 +- src/bindings.php | 6 ++ .../Caching/ConfigCachingServiceTest.php | 57 ++++++++++++++ .../Caching/MessageCachingServiceTest.php | 4 +- .../JsLocalizationControllerTest.php | 74 +++++++++++++++--- .../Http/LocalizationScriptTest.php | 11 ++- tests/TestCase.php | 17 +++- 20 files changed, 414 insertions(+), 60 deletions(-) create mode 100644 resources/js/config.js create mode 100644 src/Facades/ConfigCachingService.php create mode 100644 tests/JsLocalization/Caching/ConfigCachingServiceTest.php diff --git a/README.md b/README.md index 799edd0..f9d0ff7 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ return [ 'reminder' => [ 'password', 'user', 'token' ] - ] + ], /* * in short: @@ -82,18 +82,29 @@ return [ * 'reminder.token' * ] */ + + // Set the keys of config properties you want to use in javascript. + // Caution: Do not expose any configuration values that should be kept privately! + 'config' => [ + 'app.debug' + ], + + // Disables the config cache if set to true, so you don't have to run `php artisan js-localization:refresh` + // each time you change configuration files. + // Attention: Should not be used in production mode due to decreased performance. + 'disable_config_cache' => false, ]; ``` __Important:__ -The messages configuration will be cached when the JsLocalizationController is used for the first time. After changing the messages configuration you will need to call __`php artisan js-localization:refresh`__ to refresh that cache. +The messages configuration will be cached when the JsLocalizationController is used for the first time. After changing the messages configuration you will need to call __`php artisan js-localization:refresh`__ to refresh that cache. That also affects the config properties you export to javascript, since they are cached, too. Usage ----- -You just need to add the neccessary `