/**
  * Creates a template object
  *
  * Subclasses should override this if they're not okay with using templates
  * of the class specified in the template_class option to PHPSTL
  *
  * @param resource string the string resource to pass to the template constructor
  * @param data mixed the value to set as $template->providerData
  * @param identified string identifier string override as in PHPSTLTemplate::__construct
  */
 protected function createTemplate($resource, $data, $identifier = null)
 {
     $class = $this->pstl->getOption('template_class', 'PHPSTLTemplate');
     $template = new $class($this, $resource, $identifier);
     $template->providerData = $data;
     return $template;
 }
Example #2
0
 /**
  * Compiles a template
  *
  * @param template PHPSTLTemplate template to compile
  * @return array containing two paths:
  * array($metaCache, $contentCache)
  * - $metaCache: path to a serialized associative array containing meta data
  * - $contentCache: path to the compiled php
  */
 public function compile(PHPSTLTemplate &$template)
 {
     $cache = $this->pstl->getCache();
     try {
         $this->template = $template;
         if ($cache->isCached($template) && !$this->pstl->getOption('always_compile', false)) {
             $ret = $cache->fetch($template);
         } else {
             $content = $this->template->getContent();
             list($meta, $content) = $this->parse($content);
             $meta['cacheName'] = $cache->cacheName($template);
             $ret = $cache->store($template, $meta, $content);
         }
         assert(is_array($ret));
         assert(count($ret) == 2);
         $this->template = null;
         return $ret;
     } catch (Exception $ex) {
         $this->template = null;
         throw $ex;
     }
 }