/**
  * @param Conjoon_Text_Template_Resource $resource
  * @param array $vars
  *
  * @throws Conjoon_Text_Template_Exception
  */
 public function parse(Conjoon_Text_Template_Resource $resource, array $vars)
 {
     $text = $resource->getContent();
     $keys = array_keys($vars);
     $values = array_values($vars);
     for ($i = 0, $len = count($keys); $i < $len; $i++) {
         $keys[$i] = '{' . strtoupper($keys[$i]) . '}';
     }
     return str_replace($keys, $values, $text);
 }
Exemplo n.º 2
0
 /**
  * @param Conjoon_Text_Template_Resource $resource
  * @param array $vars
  *
  * @throws Conjoon_Text_Template_Exception
  */
 public function parse(Conjoon_Text_Template_Resource $resource, array $vars)
 {
     $old = array();
     foreach ($vars as $key => $value) {
         if (isset($resource->{$key})) {
             $old[$key] = $resource->{$key};
         }
         $resource->{$key} = $value;
     }
     ob_start();
     $resource->getContent();
     $result = ob_get_clean();
     foreach ($vars as $key => $value) {
         if (isset($old[$key])) {
             $resource->{$key} = $old[$key];
         } else {
             unset($resource->{$key});
         }
     }
     return $result;
 }