diff options
Diffstat (limited to 'app/php/components/ClientScriptManager.php')
-rw-r--r-- | app/php/components/ClientScriptManager.php | 32 |
1 files changed, 29 insertions, 3 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) { |