Changeset 1135

Show
Ignore:
Timestamp:
12/11/07 12:14:44 (8 months ago)
Author:
mikey
Message:

added some methods to be able to create useful mocks from it
makes also the template engine a bit faster because it saves calls with call_user_func_array()

Files:

Legend:

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

    r1119 r1135  
    9292 
    9393    /** 
     94     * open any input and parse for patTemplate tags 
     95     * 
     96     * @param   string  $input      name of the input (filename, shm segment, etc.) 
     97     * @param   string  $reader     optional  driver that is used as reader, you may also pass a Reader object 
     98     * @param   array   $options    optional  additional options that will only be used for this template 
     99     * @param   string  $parseInto  optional  name of the template that should be used as a container 
     100     * @return  bool    true, if the template could be parsed, false otherwise 
     101     */ 
     102    public function readTemplatesFromInput($input, $reader = 'File', array $options = null, $parseInto = null) 
     103    { 
     104        $return = $this->template->readTemplatesFromInput($input, $reader, $options, $parseInto); 
     105        if (patErrorManager::isError($return) === true) { 
     106            throw new stubException($return->getMessage()); 
     107        } 
     108         
     109        return $return; 
     110    } 
     111 
     112    /** 
     113     * add a variable to a template 
     114     * 
     115     * A variable may also be an indexed array, but not an associative array! 
     116     * 
     117     * @param   string  $template  name of the template 
     118     * @param   string  $varname   name of the variable 
     119     * @param   mixed   $value     value of the variable 
     120     * @return  bool 
     121     */ 
     122    public function addVar($template, $varname, $value) 
     123    { 
     124        return $this->template->addVar($template, $varname, $value); 
     125    } 
     126 
     127    /** 
     128     * adds several variables to a template 
     129     * 
     130     * Each Template can have an unlimited amount of its own variables 
     131     * $variables has to be an assotiative array containing variable/value pairs. 
     132     * 
     133     * @param  string  $template   name of the template 
     134     * @param  array   $variables  assotiative array of the variables 
     135     * @param  string  $prefix     optional  prefix for all variable names 
     136     */ 
     137    public function addVars($template, $variables, $prefix = '') 
     138    { 
     139        return $this->template->addVars($template, $variables, $prefix); 
     140    } 
     141 
     142    /** 
     143     * adds a global variable 
     144     * 
     145     * Global variables are valid in all templates of this object. 
     146     * A global variable has to be scalar, it will be converted to a string. 
     147     * 
     148     * @param   string  $varname  name of the global variable 
     149     * @param   string  $value    value of the variable 
     150     * @return  bool 
     151     */ 
     152    public function addGlobalVar($varname, $value) 
     153    { 
     154        return $this->template->addGlobalVar($varname, $value); 
     155    } 
     156 
     157    /** 
     158     * Adds several global variables 
     159     * 
     160     * Global variables are valid in all templates of this object. 
     161     * 
     162     * $variables is an associative array, containing name/value pairs of the variables. 
     163     * 
     164     * @param   array   $variables  array containing the variables 
     165     * @param   string  $prefix     optional  prefix for variable names 
     166     * @return  bool 
     167     */ 
     168    public function addGlobalVars($variables, $prefix = '') 
     169    { 
     170        return $this->template->addGlobalVars($variables, $prefix); 
     171    } 
     172 
     173    /** 
     174     * returns a parsed template 
     175     * 
     176     * If the template already has been parsed, it just returns the parsed template. 
     177     * If the template has not been loaded, it will be loaded. 
     178     * 
     179     * @param   string  $name          optional  name of the template 
     180     * @param   bool    $applyFilters  optional  whether to apply output filters 
     181     * @return  string 
     182     */ 
     183    public function getParsedTemplate($name = null, $applyFilters = false) 
     184    { 
     185        $return = $this->template->getParsedTemplate($name, $applyFilters); 
     186        if (patErrorManager::isError($return) === true) { 
     187            throw new stubException($return->getMessage()); 
     188        } 
     189         
     190        return $return; 
     191    } 
     192 
     193    /** 
    94194     * redirects all calls to the instance of patTemplate 
    95195     * 
     
    102202    public function __call($method, $arguments) 
    103203    { 
    104         if (method_exists($this->template, $method) == true) { 
     204        if (method_exists($this->template, $method) === true) { 
    105205            $return = call_user_func_array(array($this->template, $method), $arguments); 
    106             if (patErrorManager::isError($return) == true) { 
     206            if (patErrorManager::isError($return) === true) { 
    107207                throw new stubException($return->getMessage()); 
    108208            }