/**
  *  set cache
  *
  * @param  Charcoal_String $cache_key      identify cache
  * @param  array $data                     config data
  */
 public function setCache(Charcoal_String $cache_key, array $data)
 {
     $cache_dir = $this->getSandbox()->getProfile()->getString('CACHE_DIR');
     $cache_dir = new Charcoal_File(s($cache_dir));
     $cache_dir_mode = Charcoal_Profile::getString(s('CACHE_DIR_MODE'), s('777'));
     $cache_dir->makeDirectory($cache_dir_mode, b(TRUE));
     if (!$cache_dir->isDir()) {
         return;
     }
     $cache_file = new Charcoal_File(s($cache_key), $cache_dir);
     $contents = serialize($data);
     $fp = fopen($cache_file, 'wb');
     if ($fp) {
         if (flock($fp, LOCK_EX)) {
             fwrite($fp, $contents);
             fflush($fp);
             flock($fp, LOCK_UN);
         }
         $ret = fclose($fp);
     }
 }
 /**
  * Process events
  *
  * @param Charcoal_IEventContext $context   event context
  */
 public function processEvent($context)
 {
     $event = $context->getEvent();
     $response = $context->getResponse();
     $sequence = $context->getSequence();
     // output response headers
     $response->flushHeaders();
     // retrieve layout
     $layout = $event->getLayout();
     //        log_info( "system,renderer", "Rendering by smarty. Layout:" . print_r($layout,true) );
     try {
         $charcoal = array();
         // page redirection
         if ($layout instanceof Charcoal_IRedirectLayout) {
             $url = $layout->makeRedirectURL();
             $response->redirect(s($url));
             //                log_info( "system,renderer", "renderer", "Redirected to: $url" );
         } elseif ($event instanceof Charcoal_URLRedirectEvent) {
             $url = $event->getURL();
             $response->redirect(s($url));
             //                log_info( "system,renderer", "renderer", "Redirected to: $url" );
         } else {
             // Page information
             $page_info = $layout->getAttribute(s('page_info'));
             // Profile information
             $profile_config = Charcoal_Profile::getConfig();
             if ($profile_config && is_array($profile_config)) {
                 foreach ($profile_config as $key => $value) {
                     $charcoal['profile'][$key] = $value;
                 }
             }
             // Cookie information
             $cookies = $response->getCookies();
             if ($cookies && is_array($cookies)) {
                 foreach ($cookies as $key => $value) {
                     $charcoal['cookie'][$key] = $value;
                 }
             }
             // Assign variables
             if ($page_info && is_array($page_info)) {
                 foreach ($page_info as $key => $value) {
                     ${$key} = $value;
                 }
             }
             // Sequence data
             $charcoal['sequence'] = $sequence;
             // Request ID and reauest path
             $charcoal['request']['id'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%');
             $charcoal['request']['path'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%');
             // Assign all
             //$charcoal = $charcoal;
             // Assign all response values
             $keys = $response->getKeys();
             foreach ($keys as $key) {
                 $value = $response->get(s($key));
                 $smarty->assign($key, $value);
             }
             // render template
             $template = $layout->getAttribute(s('layout'));
             //                log_info( "smarty", "template=$template" );
             $html = $smarty->fetch($template);
             //                log_info( "smarty", "html=$html" );
             echo $html;
         }
     } catch (Exception $ex) {
         _catch($ex);
         _throw(new Charcoal_SmartyRendererTaskException("rendering failed", $ex));
     }
     return b(TRUE);
 }