array(), 'active' => 0, 'activeClass' => null, 'classes' => array(), ); class PintCompiler_Generator { /** * add a function to the stack * * @param object PintCompiler_Generator_function * * @return int id in stack * @access public */ function addFunction($func) { // we copy (not reference here) $id = count($GLOBALS['_PintCompiler_Generator']['functions']); $func->id = $id; $GLOBALS['_PintCompiler_Generator']['functions'][$id] = $func; return $id; } /** * retreive a function from the stack.. * * @param int id in stack * * @return object PintCompiler_Generator_function * @access public */ function &getFunction($id=false) { if ($id === false) { return $GLOBALS['_PintCompiler_Generator']['functions'][ $GLOBALS['_PintCompiler_Generator']['active'] ]; } return $GLOBALS['_PintCompiler_Generator']['functions'][$id]; } /** * retreive a function from using the name * * @param string name of function. * * @return PintCompiler_Generator_function | false * @access public */ function &getFunctionByName($name) { foreach(array_keys($GLOBALS['_PintCompiler_Generator']['functions']) as $i) { if ($GLOBALS['_PintCompiler_Generator']['functions'][$i]->name == $name) { return $GLOBALS['_PintCompiler_Generator']['functions'][$i]; } } $f = false; return $f; } /** * set the active Function * * @param int id in stack * * @access public */ function setActiveFunction($id=0) { $GLOBALS['_PintCompiler_Generator']['active'] = $id; } /** * set the active class * * @param object * @return int id of the class in the stack. * @access public */ function addClass($class) { $id = count($GLOBALS['_PintCompiler_Generator']['classes']); $class->id = $id; $GLOBALS['_PintCompiler_Generator']['classes'][$id] = $class; $GLOBALS['_PintCompiler_Generator']['activeClass'] = $id; return $id; } function &getActiveClass() { $id = $GLOBALS['_PintCompiler_Generator']['activeClass']; return $GLOBALS['_PintCompiler_Generator']['classes'][$id]; } /** * retreive number of functions on stack * * * @return int number in stack.. * @access public */ function countFunctions() { return count($GLOBALS['_PintCompiler_Generator']['functions']); } function nodeFactory($name, $args=array()) { //echo "NODE::$name ".serialize($args)."\n"; $class = 'PintCompiler_Node_' . $name; if (strtolower($name) == 'function' ) { $class = 'PintCompiler_Generator_Function'; } if (!class_exists($class)) { require_once implode('/',explode('_',$class)).'.php'; } if (!class_exists($class)) { trigger_error("Unable to create Class $class",E_USER_ERROR); } $r = new $class(); $vars = array_keys(get_class_vars($class)); foreach($args as $k => $v) { if (!in_array($k,$vars)) { trigger_error("Variable $class::$k does not exist",E_USER_ERROR); } $r->$k = $v; } return $r; } }