summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-04-22 15:59:31 +0200
committeremkael <emkael@tlen.pl>2016-04-22 15:59:31 +0200
commitee96b029b7e5edc4ed6ddbfccf9df44b4c9e45e8 (patch)
tree50a297cee00dc5609421bdc8e40bcd84aa227986 /app/php
parent244dbdf5cd0e24709eb70fc7dfa3269b44df1388 (diff)
* moving rendered scripts from session to cache and distinguishing among various page views for single session
Diffstat (limited to 'app/php')
-rw-r--r--app/php/components/ClientScriptManager.php32
-rw-r--r--app/php/layouts/Layout.php11
-rw-r--r--app/php/layouts/MainLayout.php4
-rw-r--r--app/php/layouts/MainLayout.tpl3
4 files changed, 46 insertions, 4 deletions
diff --git a/app/php/components/ClientScriptManager.php b/app/php/components/ClientScriptManager.php
index ce3446c..cd948a6 100644
--- a/app/php/components/ClientScriptManager.php
+++ b/app/php/components/ClientScriptManager.php
@@ -1,5 +1,7 @@
<?php
+Prado::using('Application.layouts.Layout');
+
class ClientScriptManager extends TClientScriptManager {
private $_page;
@@ -57,11 +59,32 @@ class ClientScriptManager extends TClientScriptManager {
private $_renderedScriptsInitialized = FALSE;
+ private function _getRenderedScriptsStoreKey() {
+ $template = $this->_page->Master;
+ if (!$template instanceof Layout) {
+ throw new TNotSupportedException(
+ 'Compiled assets may only be used within Layout master class controls'
+ );
+ }
+ return 'RenderedScripts.' . $template->generateViewID();
+ }
+
+ private function _getCache() {
+ $cache = $this->Application->Cache;
+ if (!$cache) {
+ throw new TNotSupportedException(
+ 'Compiled assets require cache to be configured'
+ );
+ }
+ return $cache;
+ }
+
private function _getRenderedScripts() {
+ $sessionKey = $this->_getRenderedScriptsStoreKey();
if ($this->_page->IsCallBack || $this->_renderedScriptsInitialized) {
- return $this->Session->itemAt('RenderedScripts') ?: [];
+ return $this->_getCache()->get($sessionKey) ?: [];
} else {
- $this->Session->remove('RenderedScripts');
+ $this->_getCache()->delete($sessionKey);
$this->_renderedScriptsInitialized = TRUE;
return [];
}
@@ -78,7 +101,10 @@ class ClientScriptManager extends TClientScriptManager {
$newScripts
)
);
- $this->Session->add('RenderedScripts', $scripts);
+ $this->_getCache()->set(
+ $this->_getRenderedScriptsStoreKey(),
+ $scripts
+ );
}
private function _compileFiles($files) {
diff --git a/app/php/layouts/Layout.php b/app/php/layouts/Layout.php
new file mode 100644
index 0000000..324c69f
--- /dev/null
+++ b/app/php/layouts/Layout.php
@@ -0,0 +1,11 @@
+<?php
+
+class Layout extends TTemplateControl {
+
+ public function generateViewID() {
+ return $this->ViewID->Value ?: md5(mt_rand());
+ }
+
+}
+
+?>
diff --git a/app/php/layouts/MainLayout.php b/app/php/layouts/MainLayout.php
index c0e7e0b..5843952 100644
--- a/app/php/layouts/MainLayout.php
+++ b/app/php/layouts/MainLayout.php
@@ -1,6 +1,8 @@
<?php
-class MainLayout extends TTemplateControl {
+Prado::using('Application.layouts.Layout');
+
+class MainLayout extends Layout {
}
diff --git a/app/php/layouts/MainLayout.tpl b/app/php/layouts/MainLayout.tpl
index f8c5f50..0deb816 100644
--- a/app/php/layouts/MainLayout.tpl
+++ b/app/php/layouts/MainLayout.tpl
@@ -14,6 +14,9 @@
</main>
<footer role="contentinfo">
</footer>
+ <com:THiddenField ID="ViewID">
+ <prop:Value><%= $this->generateViewID() %></prop:Value>
+ </com:THiddenField>
</com:TForm>
</body>
</html>