Public Member Functions | Data Fields

ilBMFParser Class Reference

Inheritance diagram for ilBMFParser:
Collaboration diagram for ilBMFParser:

Public Member Functions

 ilBMFParser ($xml, $encoding=SOAP_DEFAULT_ENCODING, $attachments=NULL)
 ilBMFParser constructor
 domulti ($d, &$ar, &$r, &$v, $ad=0)
 domulti recurse to build a multi-dim array, used by buildResponse
 buildResponse ($pos)
 buildResponse loop through msg, building response structures
 startElement ($parser, $name, $attrs)
 startElement start-element handler used with xml parser
 endElement ($parser, $name)
 endElement end-element handler used with xml parser
 characterData ($parser, $data)
 characterData element content handler used with xml parser
 getResponse ()
 getResponse
 getHeaders ()
 getHeaders
 decodeEntities ($text)
 decodeEntities

Data Fields

 $status = ''
 $position = 0
 $pos_stat = 0
 $depth = 0
 $default_namespace = ''
 $message = array()
 $depth_array = array()
 $previous_element = ''
 $soapresponse = NULL
 $soapheaders = NULL
 $parent = 0
 $root_struct_name = array()
 $header_struct_name = array()
 $curent_root_struct_name = ''
 $entities = array ( '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', "'" => '&apos;', '"' => '&quot;' )
 $xml = ''
 $xml_encoding = ''
 $root_struct = array()
 $header_struct = array()
 $curent_root_struct = 0
 $references = array()
 $need_references = array()
 $XMLSchemaVersion
 $bodyDepth

Detailed Description

Definition at line 38 of file class.ilBMFParser.php.


Member Function Documentation

ilBMFParser::buildResponse ( pos  ) 

buildResponse loop through msg, building response structures

Parameters:
int position
Returns:
ilBMFValue private

Definition at line 140 of file class.ilBMFParser.php.

References $pos, and domulti().

Referenced by ilBMFParser().

    {
        $response = NULL;

        if (isset($this->message[$pos]['children'])) {
            $children = explode('|',$this->message[$pos]['children']);

            foreach ($children as $c => $child_pos) {
                if ($this->message[$child_pos]['type'] != NULL) {
                    $response[] = $this->buildResponse($child_pos);
                }
            }
            if (array_key_exists('arraySize',$this->message[$pos])) {
                $ardepth = count($this->message[$pos]['arraySize']);
                if ($ardepth > 1) {
                    $ar = array_pad(array(), $ardepth, 0);
                    if (array_key_exists('arrayOffset',$this->message[$pos])) {
                        for ($i = 0; $i < $ardepth; $i++) {
                            $ar[$i] += $this->message[$pos]['arrayOffset'][$i];
                        }
                    }
                    $elc = count($response);
                    for ($i = 0; $i < $elc; $i++) {
                        // recurse to build a multi-dim array
                        $this->domulti($ardepth, $ar, $newresp, $response[$i]);
                        
                        # increment our array pointers
                        $ad = $ardepth - 1;
                        $ar[$ad]++;
                        while ($ad > 0 && $ar[$ad] >= $this->message[$pos]['arraySize'][$ad]) {
                            $ar[$ad] = 0;
                            $ad--;
                            $ar[$ad]++;
                        }
                    }
                    $response = $newresp;
                } else if (isset($this->message[$pos]['arrayOffset']) &&
                           $this->message[$pos]['arrayOffset'][0] > 0) {
                    # check for padding
                    $pad = $this->message[$pos]['arrayOffset'][0]+count($response)*-1;
                    $response = array_pad($response,$pad,NULL);
                }
            }
        }
        // build attributes
        $attrs = array();
        foreach ($this->message[$pos]['attrs'] as $atn => $atv) {
            if (!strstr($atn, 'xmlns') &&
                !strpos($atn, ':')) $attrs[$atn]=$atv;
        }
        // add current node's value
        if ($response) {
            $nqn = new Qname($this->message[$pos]['name'],$this->message[$pos]['namespace']);
            $tqn = new Qname($this->message[$pos]['type'],$this->message[$pos]['type_namespace']);
            $response = new ilBMFValue($nqn->fqn(), $tqn->fqn(), $response, $attrs);
            if (isset($this->message[$pos]['arrayType'])) $response->arrayType = $this->message[$pos]['arrayType'];
        } else {
            $nqn = new Qname($this->message[$pos]['name'],$this->message[$pos]['namespace']);
            $tqn = new Qname($this->message[$pos]['type'],$this->message[$pos]['type_namespace']);
            $response = new ilBMFValue($nqn->fqn(), $tqn->fqn(), $this->message[$pos]['cdata'], $attrs);
        }
        // handle header attribute that we need
        if (array_key_exists('actor',$this->message[$pos])) {
            $response->actor = $this->message[$pos]['actor'];
        }
        if (array_key_exists('mustUnderstand',$this->message[$pos])) {
            $response->mustunderstand = $this->message[$pos]['mustUnderstand'];
        }
        return $response;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

ilBMFParser::characterData ( parser,
data 
)

characterData element content handler used with xml parser

private

Definition at line 454 of file class.ilBMFParser.php.

References $data, and $pos.

    {
        $pos = $this->depth_array[$this->depth];
        if (isset($this->message[$pos]['cdata']))
            $this->message[$pos]['cdata'] .= $data;
        else
            $this->message[$pos]['cdata'] = $data;
    }

ilBMFParser::decodeEntities ( text  ) 

decodeEntities

removes entities from text

Parameters:
string 
Returns:
string private

Definition at line 508 of file class.ilBMFParser.php.

    {
        $trans_tbl = array_flip($this->entities);
        return strtr($text, $trans_tbl);
    }

ilBMFParser::domulti ( d,
&$  ar,
&$  r,
&$  v,
ad = 0 
)

domulti recurse to build a multi-dim array, used by buildResponse

private

Definition at line 123 of file class.ilBMFParser.php.

References $d.

Referenced by buildResponse().

    {
        if ($d) {
            $this->domulti($d-1, $ar, $r[$ar[$ad]], $v, $ad+1);
        } else {
            $r = $v;
        }
    }

Here is the caller graph for this function:

ilBMFParser::endElement ( parser,
name 
)

endElement end-element handler used with xml parser

private

Definition at line 389 of file class.ilBMFParser.php.

References $parent, and $pos.

    {
        // position of current element is equal to the last value left in depth_array for my depth
        $pos = $this->depth_array[$this->depth];
        // bring depth down a notch
        $this->depth--;
        $qname = new QName($name);
        
        // get type if not explicitly declared in an xsi:type attribute
        // XXX check on integrating wsdl validation here
        if ($this->message[$pos]['type'] == '') {
            if (isset($this->message[$pos]['children'])) {
                /* this is slow, need to look at some faster method
                $children = explode('|',$this->message[$pos]['children']);
                if (count($children) > 2 &&
                    $this->message[$children[1]]['name'] == $this->message[$children[2]]['name']) {
                    $this->message[$pos]['type'] = 'Array';
                } else { 
                    $this->message[$pos]['type'] = 'Struct';
                }*/
                $this->message[$pos]['type'] = 'Struct';
            } else {
                $parent = $this->message[$pos]['parent'];
                if ($this->message[$parent]['type'] == 'Array' &&
                  array_key_exists('arrayType', $this->message[$parent])) {
                    $this->message[$pos]['type'] = $this->message[$parent]['arrayType'];
                } else {
                    $this->message[$pos]['type'] = 'string';
                }
            }
        }
        
        // if tag we are currently closing is the method wrapper
        if ($pos == $this->curent_root_struct) {
            $this->status = 'body';
        } elseif ($qname->name == 'Body' || $qname->name == 'Header') {
            $this->status = 'envelope';
        }

        // set parent back to my parent
        $this->parent = $this->message[$pos]['parent'];
        
        # handle any reverse references now
        $idref = $this->message[$pos]['id'];

        if ($idref != '' && array_key_exists($idref,$this->need_references)) {
            foreach ($this->need_references[$idref] as $ref_pos) {
                #XXX is this stuff there already?
                $this->message[$ref_pos]['children'] = &$this->message[$pos]['children'];
                $this->message[$ref_pos]['cdata'] = &$this->message[$pos]['cdata'];
                $this->message[$ref_pos]['type'] = &$this->message[$pos]['type'];
                $this->message[$ref_pos]['arraySize'] = &$this->message[$pos]['arraySize'];
                $this->message[$ref_pos]['arrayType'] = &$this->message[$pos]['arrayType'];
            }
            # wipe out our waiting list
            # $this->need_references[$idref] = array();
        }
    }

ilBMFParser::getHeaders (  ) 

getHeaders

returns an array of header responses after parsing a soap message, use this to get the response

Returns:
array public

Definition at line 489 of file class.ilBMFParser.php.

    {
        if ($this->soapheaders) {
            return $this->soapheaders;
        }
        // we don't fault if there are no headers
        // that can be handled by the app if necessary
        return NULL;
    }

ilBMFParser::getResponse (  ) 

getResponse

returns an array of responses after parsing a soap message, use this to get the response

Returns:
array public

Definition at line 472 of file class.ilBMFParser.php.

References ilBMFBase::_raiseSoapFault().

    {
        if ($this->soapresponse) {
            return $this->soapresponse;
        }
        return $this->_raiseSoapFault("couldn't build response");
    }

Here is the call graph for this function:

ilBMFParser::ilBMFParser ( xml,
encoding = SOAP_DEFAULT_ENCODING,
attachments = NULL 
)

ilBMFParser constructor

Parameters:
string xml content
string xml character encoding, defaults to 'UTF-8'

Definition at line 71 of file class.ilBMFParser.php.

References $xml, ilBMFBase::_raiseSoapFault(), ilBMFBase::_setSchemaVersion(), buildResponse(), and ilBMFBase::ilBMFBase().

    {
        parent::ilBMFBase('Parser');
        $this->_setSchemaVersion(SOAP_XML_SCHEMA_VERSION);
        
        $this->xml = $xml;
        $this->xml_encoding = $encoding;
        $this->attachments = $attachments;
        
        // check the xml tag for encoding
        if (preg_match('/<\?xml[^>]+encoding\s*?=\s*?(\'([^\']*)\'|"([^"]*)")[^>]*?[\?]>/',$xml,$m)) {
            $this->xml_encoding = strtoupper($m[2]?$m[2]:$m[3]);
        }
        
        # XXX need to do this better, remove newlines after > or before <
        $this->xml = preg_replace("/>[\r\n]+/", '>', $this->xml);
        $this->xml = preg_replace("/[\r\n]+</", '<', $this->xml);
        
        // determines where in the message we are (envelope,header,body,method)
        // Check whether content has been read.
        if (!empty($this->xml)) {
            // prepare the xml parser
            $parser = xml_parser_create($this->xml_encoding);
            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
            xml_set_object($parser, $this);
            xml_set_element_handler($parser, 'startElement','endElement');
            xml_set_character_data_handler($parser,'characterData');

            // Parse the XML file.
            if (!xml_parse($parser,$this->xml,true)) {
                $err = sprintf('XML error on line %d: %s',
                    xml_get_current_line_number($parser),
                    xml_error_string(xml_get_error_code($parser)));
                $this->_raiseSoapFault($err,htmlspecialchars($this->xml));
            } else {
                // build the response
                if (count($this->root_struct))
                    $this->soapresponse = $this->buildResponse($this->root_struct[0]);
                if (count($this->header_struct))
                    $this->soapheaders = $this->buildResponse($this->header_struct[0]);
            }
            xml_parser_free($parser);
        }
    }

Here is the call graph for this function:

ilBMFParser::startElement ( parser,
name,
attrs 
)

startElement start-element handler used with xml parser

private

Definition at line 217 of file class.ilBMFParser.php.

References $key, $namespace, $pos, ilBMFBase::_getNamespaceForPrefix(), ilBMFBase::_getNamespacePrefix(), and ilBMFBase::_setSchemaVersion().

    {
        // position in a total number of elements, starting from 0
        // update class level pos
        $pos = $this->position++;

        // and set mine
        $this->message[$pos] = array();
        $this->message[$pos]['type'] = '';
        $this->message[$pos]['type_namespace'] = '';
        $this->message[$pos]['cdata'] = '';
        $this->message[$pos]['pos'] = $pos;
        $this->message[$pos]['id'] = '';
        
        // parent/child/depth determinations
        
        // depth = how many levels removed from root?
        // set mine as current global depth and increment global depth value
        $this->message[$pos]['depth'] = $this->depth++;
        
        // else add self as child to whoever the current parent is
        if ($pos != 0) {
            if (isset($this->message[$this->parent]['children']))
                $this->message[$this->parent]['children'] .= "|$pos";
            else
                $this->message[$this->parent]['children'] = $pos;
        }

        // set my parent
        $this->message[$pos]['parent'] = $this->parent;

        // set self as current value for this depth
        $this->depth_array[$this->depth] = $pos;
        // set self as current parent
        $this->parent = $pos;
        $qname = new QName($name);
        // set status
        if (strcasecmp('envelope',$qname->name)==0) {
            $this->status = 'envelope';
        } elseif (strcasecmp('header',$qname->name)==0) {
            $this->status = 'header';
            $this->header_struct_name[] = $this->curent_root_struct_name = $qname->name;
            $this->header_struct[] = $this->curent_root_struct = $pos;
            $this->message[$pos]['type'] = 'Struct';
        } elseif (strcasecmp('body',$qname->name)==0) {
            $this->status = 'body';
            $this->bodyDepth = $this->depth;
        // set method
        } elseif ($this->status == 'body') {
            // is this element allowed to be a root?
            // XXX this needs to be optimized, we loop through attrs twice now
            $can_root = $this->depth == $this->bodyDepth + 1;
            if ($can_root) {
                foreach ($attrs as $key => $value) {
                    if (stristr($key, ':root') && !$value) {
                        $can_root = FALSE;
                    }
                }
            }

            if ($can_root) {
                $this->status = 'method';
                $this->root_struct_name[] = $this->curent_root_struct_name = $qname->name;
                $this->root_struct[] = $this->curent_root_struct = $pos;
                $this->message[$pos]['type'] = 'Struct';
            }
        }

        // set my status
        $this->message[$pos]['status'] = $this->status;
        
        // set name
        $this->message[$pos]['name'] = htmlspecialchars($qname->name);

        // set attrs
        $this->message[$pos]['attrs'] = $attrs;

        // loop through atts, logging ns and type declarations
        foreach ($attrs as $key => $value) {
            // if ns declarations, add to class level array of valid namespaces
            $kqn = new QName($key);
            if ($kqn->ns == 'xmlns') {
                $prefix = $kqn->name;

                if (in_array($value, $this->_XMLSchema)) {
                    $this->_setSchemaVersion($value);
                }
                
                $this->_namespaces[$value] = $prefix;

                // set method namespace
                # XXX unused???
                #if ($name == $this->curent_root_struct_name) {
                #    $this->methodNamespace = $value;
                #}
            } elseif ($key == 'xmlns') {
                $qname->ns = $this->_getNamespacePrefix($value);
                $qname->namespace = $value;
            } elseif ($kqn->name == 'actor') {
                $this->message[$pos]['actor'] = $value;
            } elseif ($kqn->name == 'mustUnderstand') {
                $this->message[$pos]['mustUnderstand'] = $value;
                
            // if it's a type declaration, set type
            } elseif ($kqn->name == 'type') {
                $vqn = new QName($value);
                $this->message[$pos]['type'] = $vqn->name;
                $this->message[$pos]['type_namespace'] = $this->_getNamespaceForPrefix($vqn->ns);
                #print "set type for {$this->message[$pos]['name']} to {$this->message[$pos]['type']}\n";
                // should do something here with the namespace of specified type?
                
            } elseif ($kqn->name == 'arrayType') {
                $vqn = new QName($value);
                $this->message[$pos]['type'] = 'Array';
                #$type = $vqn->name;
                if (isset($vqn->arraySize))
                    $this->message[$pos]['arraySize'] = $vqn->arraySize;
                #$sa = strpos($type,'[');
                #if ($sa > 0) {
                #    $this->message[$pos]['arraySize'] = split(',',substr($type,$sa+1, strlen($type)-$sa-2));
                #    $type = substr($type, 0, $sa);
                #}
                $this->message[$pos]['arrayType'] = $vqn->name;
                
            } elseif ($kqn->name == 'offset') {
                $this->message[$pos]['arrayOffset'] = split(',',substr($value, 1, strlen($value)-2));
                
            } elseif ($kqn->name == 'id') {
                # save id to reference array
                $this->references[$value] = $pos;
                $this->message[$pos]['id'] = $value;
                
            } elseif ($kqn->name == 'href') {
                if ($value[0] == '#') {
                    $ref = substr($value, 1);
                    if (array_key_exists($ref,$this->references)) {
                        # cdata, type, inval
                        $ref_pos = $this->references[$ref];
                        $this->message[$pos]['children'] = &$this->message[$ref_pos]['children'];
                        $this->message[$pos]['cdata'] = &$this->message[$ref_pos]['cdata'];
                        $this->message[$pos]['type'] = &$this->message[$ref_pos]['type'];
                        $this->message[$pos]['arraySize'] = &$this->message[$ref_pos]['arraySize'];
                        $this->message[$pos]['arrayType'] = &$this->message[$ref_pos]['arrayType'];
                    } else {
                        # reverse reference, store in 'need reference'
                        if (!isset($this->need_references[$ref])) $this->need_references[$ref] = array();
                        $this->need_references[$ref][] = $pos;
                    }
                } else if (isset($this->attachments[$value])) {
                    $this->message[$pos]['cdata'] = $this->attachments[$value];
                }
            }
        }
        // see if namespace is defined in tag
        if (array_key_exists('xmlns:'.$qname->ns,$attrs)) {
            $namespace = $attrs['xmlns:'.$qname->ns];
        } else if ($qname->ns && !$qname->namespace) {
            $namespace = $this->_getNamespaceForPrefix($qname->ns);
        } else {
        // get namespace
            $namespace = $qname->namespace?$qname->namespace:$this->default_namespace;
        }
        $this->message[$pos]['namespace'] = $namespace;
        $this->default_namespace = $namespace;
    }

Here is the call graph for this function:


Field Documentation

ilBMFParser::$bodyDepth

Definition at line 63 of file class.ilBMFParser.php.

ilBMFParser::$curent_root_struct = 0

Definition at line 59 of file class.ilBMFParser.php.

ilBMFParser::$curent_root_struct_name = ''

Definition at line 53 of file class.ilBMFParser.php.

ilBMFParser::$default_namespace = ''

Definition at line 44 of file class.ilBMFParser.php.

ilBMFParser::$depth = 0

Definition at line 43 of file class.ilBMFParser.php.

ilBMFParser::$depth_array = array()

Definition at line 46 of file class.ilBMFParser.php.

ilBMFParser::$entities = array ( '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', "'" => '&apos;', '"' => '&quot;' )

Definition at line 54 of file class.ilBMFParser.php.

ilBMFParser::$header_struct = array()

Definition at line 58 of file class.ilBMFParser.php.

ilBMFParser::$header_struct_name = array()

Definition at line 52 of file class.ilBMFParser.php.

ilBMFParser::$message = array()

Definition at line 45 of file class.ilBMFParser.php.

ilBMFParser::$need_references = array()

Definition at line 61 of file class.ilBMFParser.php.

ilBMFParser::$parent = 0

Definition at line 50 of file class.ilBMFParser.php.

Referenced by endElement().

ilBMFParser::$pos_stat = 0

Definition at line 42 of file class.ilBMFParser.php.

ilBMFParser::$position = 0

Definition at line 41 of file class.ilBMFParser.php.

ilBMFParser::$previous_element = ''

Definition at line 47 of file class.ilBMFParser.php.

ilBMFParser::$references = array()

Definition at line 60 of file class.ilBMFParser.php.

ilBMFParser::$root_struct = array()

Definition at line 57 of file class.ilBMFParser.php.

ilBMFParser::$root_struct_name = array()

Definition at line 51 of file class.ilBMFParser.php.

ilBMFParser::$soapheaders = NULL

Definition at line 49 of file class.ilBMFParser.php.

ilBMFParser::$soapresponse = NULL

Definition at line 48 of file class.ilBMFParser.php.

ilBMFParser::$status = ''

Definition at line 40 of file class.ilBMFParser.php.

ilBMFParser::$xml = ''

Definition at line 55 of file class.ilBMFParser.php.

Referenced by ilBMFParser().

ilBMFParser::$xml_encoding = ''

Definition at line 56 of file class.ilBMFParser.php.

ilBMFParser::$XMLSchemaVersion

Definition at line 62 of file class.ilBMFParser.php.


The documentation for this class was generated from the following file: