XML_RPC_Message::open_tag PHP Method

open_tag() public method

Start Element Handler
public open_tag ( $the_parser, $name ) : void
return void
    public function open_tag($the_parser, $name)
    {
        $the_parser = (string) $the_parser;
        // If invalid nesting, then return
        if ($this->xh[$the_parser]['isf'] > 1) {
            return;
        }
        // Evaluate and check for correct nesting of XML elements
        if (count($this->xh[$the_parser]['stack']) === 0) {
            if ($name !== 'METHODRESPONSE' && $name !== 'METHODCALL') {
                $this->xh[$the_parser]['isf'] = 2;
                $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
                return;
            }
        } elseif (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) {
            $this->xh[$the_parser]['isf'] = 2;
            $this->xh[$the_parser]['isf_reason'] = 'XML-RPC element ' . $name . ' cannot be child of ' . $this->xh[$the_parser]['stack'][0];
            return;
        }
        switch ($name) {
            case 'STRUCT':
            case 'ARRAY':
                // Creates array for child elements
                $cur_val = array('value' => array(), 'type' => $name);
                array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
                break;
            case 'METHODNAME':
            case 'NAME':
                $this->xh[$the_parser]['ac'] = '';
                break;
            case 'FAULT':
                $this->xh[$the_parser]['isf'] = 1;
                break;
            case 'PARAM':
                $this->xh[$the_parser]['value'] = NULL;
                break;
            case 'VALUE':
                $this->xh[$the_parser]['vt'] = 'value';
                $this->xh[$the_parser]['ac'] = '';
                $this->xh[$the_parser]['lv'] = 1;
                break;
            case 'I4':
            case 'INT':
            case 'STRING':
            case 'BOOLEAN':
            case 'DOUBLE':
            case 'DATETIME.ISO8601':
            case 'BASE64':
                if ($this->xh[$the_parser]['vt'] !== 'value') {
                    //two data elements inside a value: an error occurred!
                    $this->xh[$the_parser]['isf'] = 2;
                    $this->xh[$the_parser]['isf_reason'] = 'There is a ' . $name . ' element following a ' . $this->xh[$the_parser]['vt'] . ' element inside a single value';
                    return;
                }
                $this->xh[$the_parser]['ac'] = '';
                break;
            case 'MEMBER':
                // Set name of <member> to nothing to prevent errors later if no <name> is found
                $this->xh[$the_parser]['valuestack'][0]['name'] = '';
                // Set NULL value to check to see if value passed for this param/member
                $this->xh[$the_parser]['value'] = NULL;
                break;
            case 'DATA':
            case 'METHODCALL':
            case 'METHODRESPONSE':
            case 'PARAMS':
                // valid elements that add little to processing
                break;
            default:
                /// An Invalid Element is Found, so we have trouble
                $this->xh[$the_parser]['isf'] = 2;
                $this->xh[$the_parser]['isf_reason'] = 'Invalid XML-RPC element found: ' . $name;
                break;
        }
        // Add current element name to stack, to allow validation of nesting
        array_unshift($this->xh[$the_parser]['stack'], $name);
        $name === 'VALUE' or $this->xh[$the_parser]['lv'] = 0;
    }