Source for file Factory.php
Documentation is available at Factory.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: Factory.php,v 1.6 2003/11/25 06:35:43 alan_k Exp $
// Factory tools for managing groups of HTML_Elements
require_once 'HTML/Template/Flexy/Element.php';
class HTML_Template_Flexy_Factory {
* fromArray - builds a set of elements from a key=>value array (eg. DO->toArray())
* the second parameter is an optional HTML_Element array to merge it into.
* @param array key(tag name) => value
* @param optional array key(tag name) => HTML_Element
* @return array Array of HTML_Elements
function fromArray ($ar,$ret=array ())
$ret = HTML_Template_Flexy_Factory ::fromArrayPrefixed ($k,$v,$ret);
$ret[$k] = new HTML_Template_Flexy_Element ();
* fromArrayPrefixed - takes a multi dimensional array, and builds the 'xxx[sss][xx]' => value
* @param array key(tag name) => value
* @param array key(tag name) => value
* @param optional array key(tag name) => HTML_Element
* @return array Array of HTML_Elements
function fromArrayPrefixed ($prefix, $ar,$ret=array ())
$ret = HTML_Template_Flexy_Factory ::fromArrayPrefixed ($prefix. '['. $k. ']',$v,$ret);
if (!isset ($ret[$prefix. '['. $k. '][]'])) {
$ret[$prefix. '['. $k. '][]'] = new HTML_Template_Flexy_Element ();
$ret[$prefix. '['. $k. '][]']->setValue ($v);
if (!isset ($ret[$prefix. '['. $k. ']'])) {
$ret[$prefix. '['. $k. ']'] = new HTML_Template_Flexy_Element ();
$ret[$prefix. '['. $k. ']']->setValue ($v);
* setErrors - sets the suffix of an element to a value..
* HTML_Element_Factory::setErrors($elements,array('name','not long enough'));
* @param array (return by referncekey(tag name) => HTML_Element
* @param array key(tag name) => error
* @param string sprintf error format..
* @return array Array of HTML_Elements
function setErrors ($ret,$set,$format= '<span class="error">%s</span>') {
// check what you send this.. !!!
'invalid arguments "$set" (should be an array) sent to HTML_Template_Flexy_Factory::setErrors',
foreach($set as $k=> $v) {
$ret[$k] = new HTML_Template_Flexy_Element;
$ret[$k]->suffix .= sprintf($format,$v);
* setRequired - sets the prefix of an element to a value..
* HTML_Element_Factory::setRequired($elements,array('name',true));
* @param array (return by referncekey(tag name) => HTML_Element
* @param array key(tag name) => error
* @param string sprintf error format..
* @return array Array of HTML_Elements
function setRequired ($ret,$set,$format= '<span class="required">*</span>') {
foreach($set as $k=> $v) {
$ret[$k] = new HTML_Template_Flexy_Element ();
$ret[$k]->prefix .= sprintf($format,$v);
* freeze - freeze's an element. - just copies the value to the override.
* this probably needs more thought.. - it would probably need to merge
* the full tag info with types, to be usefull..
* $ar = HTML_Element_Factory::freeze($ar);
* @param array (return by referncekey(tag name) => HTML_Element
* @return array Array of HTML_Elements
function freeze ($array) {
foreach($array as $k=> $v) {
$array[$k]->override = $array[$k]->value;
Documentation generated on Mon, 11 Mar 2019 10:15:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|