Пример #1
0
 /**
  * The interface method of Opt_Caching_Interface. Finalizes
  * the caching of the view.
  *
  * @param Opt_View $view The cached view.
  */
 public function templateCacheStop(Opt_View $view)
 {
     $header = array('timestamp' => time(), 'expire' => $this->getExpiryTime(), 'dynamic' => $view->hasDynamicContent() ? 'true' : 'false');
     $header = '<' . '?php /* ' . serialize($header) . '*/ ?>' . "\n";
     $tpl = Opl_Registry::get('opt');
     $tpl->setBufferState('cache', false);
     if ($view->hasDynamicContent()) {
         $buffer = $view->getOutputBuffers();
         $dyn = file_get_contents($tpl->compileDir . $view->_convert($view->getTemplate()) . '.dyn');
         if ($dyn !== false) {
             $dynamic = unserialize($dyn);
             unset($dyn);
         } else {
             throw new Opc_View_Cache_InvalidDynamicContent_Exception($view->getTemplate());
             return false;
         }
         $content = '';
         for ($i = 0, $endI = count($buffer); $i < $endI; $i++) {
             $content .= $buffer[$i];
             $content .= $dynamic[$i];
         }
         if (file_put_contents($this->getDirectory() . $this->_getFilename($view), $header . $content . ob_get_flush()) === false) {
             throw new Opc_View_Cache_CannotSaveFile_Exception($this->getDirectory());
             return false;
         }
     } else {
         if (file_put_contents($this->getDirectory() . $this->_getFileName($view), $header . ob_get_contents()) === false) {
             throw new Opc_View_Cache_CannotSaveFile_Exception($this->getDirectory());
             return false;
         }
     }
 }