/**
  * This function allows the easy conversion of a string in the form:
  * string1[string2][string3]...
  * into an array:
  * array('string1','string2','string3');
  * So far it's only used once (in form.class.inc) to split up the name
  * of a form element, but I thought I'd chuck it in here just in case...
  */
 function arrayFromString($string, $return_array = true)
 {
     $arr1 = '';
     if ($string) {
         /*check that it's the type of string we are looking for*/
         if (preg_match('/.*\\[.+\\]*/', $string)) {
             /*start by splitting the bulk of the string up*/
             $arr1 = explode('][', $string);
             //StringUtility::split($string,'][');
             /*check that this was a valid string*/
             if (is_array($arr1)) {
                 /*then catch the first ']'*/
                 $first = $arr1[0];
                 unset($arr1[0]);
                 $arr2 = explode('[', $first);
                 /*and put the arrays together*/
                 $arr1 = ArrayUtility::merge($arr2, $arr1);
                 /*now get rid of a trailing ']'*/
                 if (ArrayUtility::lastElement($arr1) == ']') {
                     unset($arr1[(int) (count($arr1) - 1)]);
                 }
                 /*and a trailing ']' if there is one*/
                 $arr1[count($arr1) - 1] = str_replace(']', '', ArrayUtility::lastElement($arr1));
             }
         } else {
             if ($return_array) {
                 $arr1 = array($string);
             }
         }
     }
     return $arr1;
 }
 /**
  * Create a value string from the fields and values
  *
  * This is the heart of the InsertQuery and is the function 
  * that allows the user to have created 'jagged' value arrays,
  * that is, it is this function that eliminates the need for the 
  * user to add a value for each field simultaneously when building
  * the query.
  *
  * The value string is created by looping through the number of 
  * times corresponding to the field with the most values. If 
  * a field does not have a value for a particular element, then
  * @access private
  */
 function createValueString()
 {
     $value_array_counts = array_map('count', $this->values);
     sort($value_array_counts, SORT_NUMERIC);
     $max = ArrayUtility::lastElement($value_array_counts);
     $ret = array();
     for ($i = 0; $i < $max; $i++) {
         $vals = array();
         foreach ($this->fields as $name) {
             /*add the value for this field if it exists*/
             if ($new_value = ArrayUtility::getArrayValueMulti($this->values, array($name, $i))) {
                 $vals[] = $new_value;
             } else {
                 if ($this->mode == InsertQuery::EMPTY_VALUE_MODE) {
                     $vals[] = '\'\'';
                 } else {
                     if ($new_value = ArrayUtility::getArrayValueMulti($this->values, array($name, 0))) {
                         $vals[] = $new_value;
                     } else {
                         $vals[] = '\'\'';
                     }
                 }
             }
         }
         $ret[] = '(' . implode(',', $vals) . ')';
     }
     return implode(',', $ret);
 }
Пример #3
0
 protected function stopPatternNode($util)
 {
     $this->stop();
     array_pop($this->pattern_name_stack);
     $this->current_pattern_name = ArrayUtility::lastElement($this->pattern_name_stack);
 }
 /**
  * Callback function to be used for the Excpat parser when an element finishes
  * @param parser - the parser being used
  * @param name   - the name of the element being ended
  */
 function elementStop($parser, $name)
 {
     if (!$this->cease) {
         if ($this->cur_name == $name) {
             $this->stopped_name = array_pop($this->element_stack);
             $this->cur_name = ArrayUtility::lastElement($this->element_stack);
             $this->event = XmlUtility::STOP_ELEMENT;
             $this->cur_attributes = '';
             $this->event_handler->elementStopped($this);
             $this->decrementElementCount($name);
         } else {
             $this->xmlErrorMessage('Element mismatch. Current name: ' . $this->cur_name . ', finished: ' . $name);
         }
     }
 }