Source for file Assign.php
Documentation is available at Assign.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: nobody <nobody@localhost> |
// +----------------------------------------------------------------------+
// $Id: Assign.php 334846 2014-09-12 04:50:56Z alan_k $
// Provider for Assign API ( Eg. $flexy->assign(...) )
define('HTML_TEMPLATE_FLEXY_ASSIGN_ERROR_INVALIDARGS', -100 );
class HTML_Template_Flexy_Assign {
* The variables stored in the Assigner
var $variables = array ();
* The references stored in the Assigner
var $references = array ();
* Assigns a token-name and value to $this->_token_vars for use in a
* There are three valid ways to assign values to a template.
* Form 1: $args[0] is a string and $args[1] is mixed. This means
* $args[0] is a token name and $args[1] is the token value (which
* allows objects, arrays, strings, numbers, or anything else).
* $args[1] can be null, which means the corresponding token value in
* the template will also be null.
* Form 2: $args[0] is an array and $args[1] is not set. Assign a
* series of tokens where the key is the token name, and the value is
* Form 3: $args[0] is an object and $args[1] is not set. Assigns
* copies of all object variables (properties) to tokens; the token
* name and value is a copy of each object property and value.
* @param string|array|object $args[0] This param can be a string, an
* array, or an object. If $args[0] is a string, it is the name of a
* variable in the template. If $args[0] is an array, it must be an
* associative array of key-value pairs where the key is a variable
* name in the template and the value is the value for that variable
* in the template. If $args[0] is an object, copies of its
* properties will be assigned to the template.
* @param mixed $args[1] If $args[0] is an array or object, $args[1]
* should not be set. Otherwise, a copy of $args[1] is assigned to a
* template variable named after $args[0].
* @return bool|PEAR_ErrorBoolean true if all assignments were
* committed, or a PEAR_Error object if there was an error.
* @throws SAVANT_ERROR_ASSIGN Unknown reason for error, probably
* because you passed $args[1] when $args[0] is an array or object.
* @author Paul M. Jones <pmjones@ciaweb.net>
// in Form 1, $args[0] is a string name and $args[1] is mixed.
// in Form 2, $args[0] is an associative array.
// in Form 3, $args[0] is an object.
// -------------------------------------------------------------
// Now we assign variable copies.
// form 1 (string name and mixed value)
// don't check isset() on $args[1] becuase a 'null' is not set,
// and we might want to pass a null.
if (isset ($this->references[$args[0 ]])) {
unset ($this->references[$args[0 ]]);
// keep a copy in the token vars array
$this->variables[$args[0 ]] = $args[1 ];
if (is_array($args[0 ]) && $count == 1 ) {
foreach ($args[0 ] as $key=> $val) {
$this->assign (array ($key, $val));
// get the object properties
foreach ($data as $key=> $val) {
$this->assign (array ($key, $val));
// -------------------------------------------------------------
// Final error catch. We should not have gotten to this point.
return HTML_Template_Flexy ::staticRaiseError (
"invalid type sent to assign, ". print_r($args,true ),
* Assign a token by reference. This allows you change variable
* values within the template and have those changes reflected back
* at the calling logic script. Works as with form 2 of assign().
* @param string $name The template token-name for the reference.
* @param mixed &$ref The variable passed by-reference.
* @return bool|PEAR_ErrorBoolean true on success, or a PEAR_Error
* @throws SAVANT_ERROR_ASSIGN_REF Unknown reason for error.
* @author Paul M. Jones <pmjones@ciaweb.net>
function assignRef ($name, &$ref)
// look for the proper case: name and variable
if (isset ($this->variables[$name])) {
unset ($this->variables[$name]);
// assign the token as a reference
$this->references[$name] = & $ref;
return HTML_Template_Flexy ::staticRaiseError (
"invalid type sent to assignRef, ". print_r($name,true ),
Documentation generated on Mon, 11 Mar 2019 15:59:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|