Show
Ignore:
Timestamp:
04/06/08 17:10:05 (5 months ago)
Author:
mikey
Message:

fixed problems with stubMemphisTemplate in unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisTemplate.php

    r1466 r1511  
    11<?php 
    22/** 
    3  * Proxy for patTemplate
     3 * Interface for template implementations
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  websites_memphis 
    88 */ 
    9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalAccessException', 
    10                       'net::stubbles::util::stubRegistry' 
    11 ); 
    129/** 
    13  * Proxy for patTemplate
     10 * Interface for template implementations
    1411 * 
    1512 * @author      Frank Kleine <mikey@stubbles.net> 
     
    1714 * @subpackage  websites_memphis 
    1815 */ 
    19 // @codeCoverageIgnoreStart 
    20 class stubMemphisTemplate extends stubBaseObject 
     16interface stubMemphisTemplate extends stubObject 
    2117{ 
    2218    /** 
    2319     * registry key for template dir setting 
    2420     */ 
    25     const REGISTRY_KEY_DIR        = 'net.stubbles.websites.memphis.templateDir'; 
    26     /** 
    27      * the patTemplate instance 
    28      * 
    29      * @var  patTemplate 
    30      */ 
    31     protected $template; 
    32     /** 
    33      * switch whether template classes are already initialized or not 
    34      * 
    35      * @var  bool 
    36      */ 
    37     protected static $initialized = false; 
     21    const REGISTRY_KEY_DIR = 'net.stubbles.websites.memphis.templateDir'; 
    3822 
    3923    /** 
     
    4428     * @param  array   $options     optional  configuration options for patTemplate 
    4529     */ 
    46     public function __construct($baseDir, array $namespaces = array(), array $options = array()) 
    47     { 
    48         if (false === self::$initialized) { 
    49             // do not use __static() because we want to load the code only when 
    50             // it is really required 
    51             stubClassLoader::load('net::stubbles::util::ext::stubPhpToolsClassLoader'); 
    52             $patClassLoader = new stubPhpToolsClassLoader(stubRegistry::getConfig('net.php-tools.path', stubConfig::getLibPath() . '/pat')); 
    53             stubClassLoader::registerForeignClassLoader($patClassLoader); 
    54             stubClassLoader::load('net::php-tools::patErrorManager'); 
    55             stubClassLoader::load('net::php-tools::patTemplate'); 
    56             self::$initialized = true; 
    57         } 
    58          
    59         if (count($namespaces) === 0) { 
    60             $namespaces = array('patTemplate'); 
    61         } 
    62          
    63         if (isset($options['componentExtension']) === false) { 
    64             $options['componentExtension'] = '.tmpl'; 
    65         } 
    66          
    67         $this->template = new patTemplate(); 
    68         $this->template->setBasedir($baseDir); 
    69         $this->template->setNamespace($namespaces); 
    70         foreach ($options as $optionName => $optionValue) { 
    71             $this->template->setOption($optionName, $optionValue); 
    72         } 
    73     } 
     30    #public function __construct($baseDir, array $namespaces = array(), array $options = array()); 
    7431 
    7532    /** 
     
    8441     * @param  string  $type      optional  patTemplate cache driver 
    8542     */ 
    86     public function enableCache($cacheDir = null, $prefix = 'tmpl_', $type = 'File') 
    87     { 
    88         if (null == $cacheDir) { 
    89             $cacheDir = stubConfig::getCachePath() . '/patTemplate'; 
    90         } 
    91          
    92         $this->template->useTemplateCache($type, array('cacheFolder' => $cacheDir, 
    93                                                        'prefix'      => $prefix 
    94                                                  ) 
    95         ); 
    96     } 
     43    public function enableCache($cacheDir = null, $prefix = 'tmpl_', $type = 'File'); 
    9744 
    9845    /** 
     
    10653     * @throws  stubException 
    10754     */ 
    108     public function readTemplatesFromInput($input, $reader = 'File', array $options = null, $parseInto = null) 
    109     { 
    110         $return = $this->template->readTemplatesFromInput($input, $reader, $options, $parseInto); 
    111         if (patErrorManager::isError($return) === true) { 
    112             throw new stubException($return->getMessage()); 
    113         } 
    114          
    115         return $return; 
    116     } 
     55    public function readTemplatesFromInput($input, $reader = 'File', array $options = null, $parseInto = null); 
    11756 
    11857    /** 
     
    12665     * @return  bool 
    12766     */ 
    128     public function addVar($template, $varname, $value) 
    129     { 
    130         return $this->template->addVar($template, $varname, $value); 
    131     } 
    132  
     67    public function addVar($template, $varname, $value); 
    13368    /** 
    13469     * adds several variables to a template 
     
    14277     * @return  bool 
    14378     */ 
    144     public function addVars($template, $variables, $prefix = '') 
    145     { 
    146         return $this->template->addVars($template, $variables, $prefix); 
    147     } 
     79    public function addVars($template, $variables, $prefix = ''); 
    14880 
    14981    /** 
     
    15789     * @return  bool 
    15890     */ 
    159     public function addGlobalVar($varname, $value) 
    160     { 
    161         return $this->template->addGlobalVar($varname, $value); 
    162     } 
     91    public function addGlobalVar($varname, $value); 
    16392 
    16493    /** 
     
    173102     * @return  bool 
    174103     */ 
    175     public function addGlobalVars($variables, $prefix = '') 
    176     { 
    177         return $this->template->addGlobalVars($variables, $prefix); 
    178     } 
     104    public function addGlobalVars($variables, $prefix = ''); 
    179105 
    180106    /** 
     
    189115     * @throws  stubException 
    190116     */ 
    191     public function getParsedTemplate($name = null, $applyFilters = false) 
    192     { 
    193         $return = $this->template->getParsedTemplate($name, $applyFilters); 
    194         if (patErrorManager::isError($return) === true) { 
    195             throw new stubException($return->getMessage()); 
    196         } 
    197          
    198         return $return; 
    199     } 
    200  
    201     /** 
    202      * redirects all calls to the instance of patTemplate 
    203      * 
    204      * @param   string  $method     name of method to call 
    205      * @param   array   $arguments  arguments to call method with 
    206      * @return  mixed 
    207      * @throws  stubIllegalAccessException 
    208      * @throws  stubException 
    209      */ 
    210     public function __call($method, $arguments) 
    211     { 
    212         if (method_exists($this->template, $method) === true) { 
    213             $return = call_user_func_array(array($this->template, $method), $arguments); 
    214             if (patErrorManager::isError($return) === true) { 
    215                 throw new stubException($return->getMessage()); 
    216             } 
    217              
    218             return $return; 
    219         } 
    220          
    221         $backtrace = debug_backtrace(); 
    222         throw new stubIllegalAccessException('Method patTemplate::' . $method . ' called in ' . $backtrace[2]['class'] . '::' . $backtrace[2]['function'] . '() on line ' . $backtrace[2]['line'] . ' does not exist.'); 
    223     } 
     117    public function getParsedTemplate($name = null, $applyFilters = false); 
    224118} 
    225 // @codeCoverageIgnoreEnd 
    226119?>