Location: PHPKode > scripts > SelectaPix Image Gallery > classes/class_object_builder.php
<?php
class ObjectBuilder {
	var $ClassIndex;        	// An array containing name/value pairs mapping labels to class names
   	var $ControlStrings;		// An array containing strings to be written in controls when they are rendered

	function ObjectBuilder() {
      	$this->ClassIndex = array();
		$this->ControlStrings = array();
   	}
   
   	/*  Adds a string to the control strings collection
   		If the option ControlRenderCode parameter is used, it will write the string to the control when that code is used as a reference
   		by the control (allowing you to write strings to particular places in the control's render method) */
	function AddControlString($ControlClassName, $ControlRenderCode = "", $String) {
		if($ControlRenderCode != "") {
			$ControlClassName = $ControlClassName.".".$ControlRenderCode;
		}
		if(!array_key_exists($ControlClassName, $this->ControlStrings)) {
			$this->ControlStrings[$ControlClassName] = array();
		}
		$this->ControlStrings[$ControlClassName][] = $String;		
	}
	
	// Private (used internally - should use NewObject or NewfObject externally)
	function CreateObject(&$f, $ClassLabel, $IsfObject, $Param1 = "", $Param2 = "", $Param3 = "", $Param4 = "", $Param5 = "", $Param6 = "", $Param7 = "", $Param8 = "", $Param9 = "", $Param10 = "") {
      	if(!array_key_exists($ClassLabel, $this->ClassIndex)) {
        	// If the class has not yet been defined, assume the class label is the class name
        	$ClassName = $ClassLabel;
    	} 
    	else {
    		$ClassName = $this->ClassIndex[$ClassLabel];
    	}
    	if(!class_exists($ClassName)) {
			$f->error->add('', '', "Error in ObjectBuilder->NewObject. The \"".$ClassName."\" class referenced by \"".$ClassLabel."\" does not appear to exist.");
    	}
		if ($IsfObject) {
			return new $ClassName($f, $Param1, $Param2, $Param3, $Param4, $Param5, $Param6, $Param7, $Param8, $Param9, $Param10);
		} 
		else {
			return new $ClassName($Param1, $Param2, $Param3, $Param4, $Param5, $Param6, $Param7, $Param8, $Param9, $Param10);
		}
	}
	
	// Almost identical to NewObject, but passes the f by reference as the first variable in the constructor of the object
	function NewFrameworkObject(&$f, $ClassLabel, $Param1 = "", $Param2 = "", $Param3 = "", $Param4 = "", $Param5 = "", $Param6 = "", $Param7 = "", $Param8 = "", $Param9 = "", $Param10 = "") {
		return $this->CreateObject($f, $ClassLabel, 1, $Param1, $Param2, $Param3, $Param4, $Param5, $Param6, $Param7, $Param8, $Param9, $Param10);
	}
	
	// Create a new object based on a class name. Will gracefully error out if the class does not exist
	function NewObject(&$f, $ClassLabel, $Param1 = "", $Param2 = "", $Param3 = "", $Param4 = "", $Param5 = "", $Param6 = "", $Param7 = "", $Param8 = "", $Param9 = "", $Param10 = "") {
		return $this->CreateObject($f, $ClassLabel, 0, $Param1, $Param2, $Param3, $Param4, $Param5, $Param6, $Param7, $Param8, $Param9, $Param10);
	}
   
   	// For debugging, allow the current references to be written
   	function PrintReferences() {
      	while(list($Label, $Name) = each($this->ClassIndex)) {
         	echo("<div>".$Label.": ".$Name."</div>");
      	}      
   	}
	
	// Takes a string from the control string collection and returns it based on the supplied controlclassname and control render code
	function RenderControlStrings($ControlClassName, $ControlRenderCode = "") {
		$sReturn = "";
		if($ControlRenderCode != "") {
			$ControlClassName = $ControlClassName.".".$ControlRenderCode;
		}
		if(array_key_exists($ControlClassName, $this->ControlStrings)) {
			for($i=0; $i<count($this->ControlStrings[$ControlClassName]); $i++) {
				$sReturn .= $this->ControlStrings[$ControlClassName][$i];
			}
		}
		return $sReturn;
	}
   
	function SetReference($ClassLabel, $ClassName = "") {
      	if($ClassName == "") {
      		$ClassName = $ClassLabel;
      	}
      	$this->ClassIndex[$ClassLabel] = $ClassName;
	}	
}
?>
Return current item: SelectaPix Image Gallery