Exemplo n.º 1
0
 /**
  * リソーステンプレートをRoにセット
  *
  * リクエストにテンプレートオプションが指定されているとHTML等文字列化してRoに保持します。
  *
  * @return void
  * @todo リソースボディのキャッシュはUA共通に
  */
 protected function _setHtml($isLinked)
 {
     // キャッシュ?
     $isLinkCache = isset($this->_config['request']['options']['cache']['link']) && $this->_config['request']['options']['cache']['link'];
     if ($isLinked && $isLinkCache === true) {
         $life = $this->_config['request']['options']['cache']['life'];
     } elseif (!$isLinked && isset($this->_config['request']['options']['cache']['life']) && isset($this->_config['request']['options']['template'])) {
         $life = $this->_config['request']['options']['cache']['life'];
     } else {
         $life = false;
     }
     if ($life !== false) {
         // キャッシュ読み込み
         $cache = BEAR::dependency('BEAR_Cache')->setLife($life);
         $pagerKey = isset($_GET['_start']) ? $_GET['_start'] : '';
         $ua = BEAR::get('page')->getConfig('ua');
         $cacheKey = $ua . md5(serialize($this->_config['request']) . "-{$pagerKey}");
         $saved = $cache->get($cacheKey);
         if ($saved) {
             $this->_ro = $saved;
             return;
         } else {
             $useCache = true;
         }
     }
     //実リクエスト
     $body = $isLinked !== true ? $this->_ro->getBody() : $this->getLinkedBody();
     $this->_ro->setBody($body);
     if ($isLinked === true) {
         $this->_ro->setHeader('_linked', $this->_chainLink);
     }
     // テンプレート適用
     $html = isset($this->_config['request']['options']['template']) ? $this->_getHtml($body) : false;
     if ($html !== false) {
         $this->_ro->setHtml($html);
     }
     // キャッシュ書き込み
     if (isset($useCache)) {
         $roContainer = new BEAR_Ro_Container($this->_ro);
         $cache->set($cacheKey, $roContainer);
     }
 }