/** * A function that checks to see if a given DOMElement/DOMNode has child elements, 'elements' being defined as tag type nodes * * @param $element The parent element to check for children elements * @return bool True if the DOMElement passed to argument has child tag elements, false if not */ protected function XMLhasChildElement($element) { if (get_class($element) != "DOMNode" && get_class($element) != "DOMElement") { die(_err_report($this, "Invalid argument")); } $return = false; if ($element->hasChildNodes()) { $nodeList = $element->childNodes; //run through child node list looking for tag type nodes for ($i = 0; $i < $nodeList->length; $i++) { $NodeNow = $nodeList->item($i); if ($NodeNow->nodeType == 1) { $return = true; break; } } } return $return; }
/** * Makes a connection to the MySQL database and return the connection * * @return mysqli a mysqli connection the database * @throws Exception This happens if the connection fails */ public function get_conn() { global $_SETTINGS; if ($this->connection_limit < $_SETTINGS["CONNECTION_LIMIT"]) { $conn_attempt = new mysqli($this->mysql_host, $this->mysql_user, $this->mysql_user_password); if (!$conn_attempt->connect_errno) { $this->connection_limit++; return $conn_attempt; } else { if ($_SETTINGS["ERR_REPORT"] == "admin_debug") { die(_err_report($this, "connection to database failed")); } else { throw new Exception("Failed to connect to " . $this->MysqlHost); } } } else { if ($_SETTINGS["ERR_REPORT"] == "admin_debug") { die(_err_report($this, "connection limit exceeded")); } else { throw new Exception("Failed to connect to " . $this->MysqlHost); } } }
/** * Registers to scope a function or set of function and associated name(s)/id(s) * * @param $name A string name or indexed array of names to correspond, in order, to function(s) from the $function argument * @param $function A function reference or an indexed array of function referenced that take(s) an two arguments, an array of results and an iteration number * @return Scope The parent instance of the Scope object (allows for function chaining) */ public function result_handler($name, $function) { global $_SETTINGS; //checks to make sure argument one and two are a string and function, respectively, or an array and array, //respectively if (!(is_string($name) || is_array($name)) || !(is_callable($function) || is_array($function))) { if ($_SETTINGS["ERR_REPORT"] == "admin_debug") { die(_err_report($this, "invalid argument(s)")); } else { throw new Exception("scope failure"); } } //if arguments types are String and function if (is_callable($function)) { $this->dm_result_handler[$name] = $function; } else { foreach ($function as $key => $func) { $this->dm_result_handler[$name[$key]] = $func; } } return $this; }
/** * A function designed to pull out the data returned from the background database based on the query, permisssion key, bind types, * bind values, and result handlers valid for the node containing the dm-name value passed in as an argument. * * @param $dm_name The dm-name attribute value of the node from which the extracted MySQL data is taken * @param $iter If the dm-name attribute was turned to a dm-class by the expansion of the model under a dm-repeat this variable specifies the index of the instance of the class of interest * @return String The value from the database associated with the node containing the dm-name value specified in $dm_name argument */ public function extract_result($dm_name, $iter = "default") { $node = null; $Node = null; $num_node = 0; if (!is_string($iter)) { $node = $this->getNodeByAttrValue("dm-class", $dm_name); $num_node = floor(abs($iter)); } else { $node = $this->getNodeByAttrValue("dm-name", $dm_name); } //DEVELOPER NOTE: add code to change error handling as per the ERR_REPORT setting in global $_SETTINGS array if ($num_node >= sizeof($node) || !is_array($node)) { die(_err_report($this, "referencing an XML node which does not exist. Check arguments")); } //DEVELOPER NOTE: could $num_node be out of bounds for $node array? could $node[$num_node] be out of bounds for nodeList $Node = $this->nodeList[$node[$num_node]]; $QP_name = $this->get_attr_val($Node, "dm-query-point"); $FN_name = $this->get_attr_val($Node, "dm-result-handler"); //DEVELOPER NOTE: add code to change error handling as per the ERR_REPORT setting in global $_SETTINGS array if (!array_key_exists($FN_name, $this->_scope->dm_result_handler)) { die(_err_report($this, "result handler from xml markup not registered in the scope")); } if (!array_key_exists($QP_name, $this->mysql_result_registry)) { die(_err_report($this, "no result registered for xml query point used ")); } return $this->_scope->dm_result_handler[$FN_name]($this->mysql_result_registry[$QP_name], $num_node); }
/** * Gets all nodes under and including the parent node specified for which the specified attribute is present * * @param $parent_node_ The parent node where the search starts * @param $search_attr A String representing the attribute name by which to search * @return array A list of DOMNodes with the specified attributes */ protected function find_nodes_by_attribute_presence($parent_node_, $search_attr) { if (get_class($parent_node_) != "DOMNode" || !is_string($search_attr)) { _err_report($this, "invalid arguments"); } $this->temp_node_listing = []; $this->find_child_nodes_by_attribute_presence($parent_node_, $search_attr); return $this->temp_node_listing; }