Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement ConfigCachingService, update controller and add JS code
- Loading branch information
Andy Wermke
committed
Aug 6, 2015
1 parent
d0d2068
commit 9f7d361
Showing
20 changed files
with
414 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(function() { | ||
|
||
var configData = {}; | ||
|
||
|
||
/* Config: */ | ||
|
||
var Config = { | ||
get: function(propertyName, defaultValue) { | ||
if (typeof configData[propertyName] !== 'undefined') { | ||
return configData[propertyName]; | ||
} | ||
|
||
// Config property not set | ||
|
||
if (arguments.length > 1) { | ||
return defaultValue; | ||
} else { | ||
return null; | ||
} | ||
}, | ||
|
||
addConfig: function(data) { | ||
for (var propertyName in data) { | ||
configData[propertyName] = data[propertyName]; | ||
} | ||
} | ||
}; | ||
|
||
|
||
/* Export: */ | ||
|
||
this.Config = Config; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,69 @@ | ||
<?php | ||
namespace JsLocalization\Caching; | ||
|
||
use Config; | ||
use Event; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: andy | ||
* Date: 03.08.15 | ||
* Time: 00:11 | ||
* Class ConfigCachingService | ||
* @package JsLocalization\Caching | ||
*/ | ||
class ConfigCachingService extends AbstractCachingService { | ||
|
||
namespace JsLocalization\Caching; | ||
const CACHE_KEY = 'js-localization-config-json'; | ||
|
||
const CACHE_TIMESTAMP_KEY = 'js-localization-config-last-modified'; | ||
|
||
class ConfigCachingService extends AbstractCachingService { | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(self::CACHE_KEY, self::CACHE_TIMESTAMP_KEY); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function refreshCache() | ||
{ | ||
Event::fire('JsLocalization.registerConfig'); | ||
|
||
$configJson = $this->createConfigJson(); | ||
$this->refreshCacheUsing($configJson); | ||
} | ||
|
||
/** | ||
* @return string The JSON-encoded config exports. | ||
*/ | ||
public function getConfigJson() | ||
{ | ||
if ($this->isDisabled()) { | ||
return $this->createConfigJson(); | ||
} else { | ||
return $this->getData(); | ||
} | ||
} | ||
|
||
/** | ||
* @return bool Is config caching disabled? `true` means that this class does not cache, but create the data on the fly. | ||
*/ | ||
public function isDisabled() | ||
{ | ||
return Config::get('js-localization.disable_config_cache', false); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function createConfigJson() | ||
{ | ||
$propertyNames = Config::get('js-localization.config', []); | ||
$configArray = []; | ||
|
||
foreach ($propertyNames as $propertyName) { | ||
$configArray[$propertyName] = Config::get($propertyName); | ||
} | ||
|
||
return json_encode((object)$configArray); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: andy | ||
* Date: 03.08.15 | ||
* Time: 16:40 | ||
*/ | ||
|
||
namespace JsLocalization\Facades; | ||
|
||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* Class ConfigCachingService | ||
* @package JsLocalization\Facades | ||
* | ||
* @method static void refreshCache() | ||
* @method static \DateTime getLastRefreshTimestamp() | ||
* @method static string getConfigJson() | ||
* @method static bool isDisabled() | ||
* @method static void public function refreshCache() | ||
*/ | ||
class ConfigCachingService extends Facade { | ||
protected static function getFacadeAccessor() { | ||
return 'JsLocalizationConfigCachingService'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.