Data Handler

Called by xml_set_character_data_handler()

@access private
@param resource $parser
@param string $data
355235
function _data_handler($parser, $data)
    {
        if (!isset($this->current) || is_object($this->current)) {
            return;
        }
        $this->current.= trim($data);
    }
1048389
public function parse(Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);

        $this->maskField = $parser->ArithmeticPrimary();
        $this->deleteDeferredPath($parser, $this->maskField);

        $parser->match(Lexer::T_COMMA);
        $this->findValue = $parser->ArithmeticPrimary();

        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
        $this->parserResult = $parser->getParserResult();
    }
825810
public function setCharset($charset)
    {
        parent::setCharset($charset);
        if (isset($this->paramEncoder)) {
            $this->paramEncoder->charsetChanged($charset);
        }
    }
1182761
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentTypeUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct();

        if (array_key_exists('identifier', $data)) {
            $contentTypeUpdateStruct->identifier = $data['identifier'];
        }

        if (array_key_exists('mainLanguageCode', $data)) {
            $contentTypeUpdateStruct->mainLanguageCode = $data['mainLanguageCode'];
        }

        if (array_key_exists('remoteId', $data)) {
            $contentTypeUpdateStruct->remoteId = $data['remoteId'];
        }

        if (array_key_exists('urlAliasSchema', $data)) {
            $contentTypeUpdateStruct->urlAliasSchema = $data['urlAliasSchema'];
        }

        if (array_key_exists('nameSchema', $data)) {
            $contentTypeUpdateStruct->nameSchema = $data['nameSchema'];
        }

        if (array_key_exists('isContainer', $data)) {
            $contentTypeUpdateStruct->isContainer = $this->parserTools->parseBooleanValue($data['isContainer']);
        }

        if (array_key_exists('defaultSortField', $data)) {
            $contentTypeUpdateStruct->defaultSortField = $this->parserTools->parseDefaultSortField($data['defaultSortField']);
        }

        if (array_key_exists('defaultSortOrder', $data)) {
            $contentTypeUpdateStruct->defaultSortOrder = $this->parserTools->parseDefaultSortOrder($data['defaultSortOrder']);
        }

        if (array_key_exists('defaultAlwaysAvailable', $data)) {
            $contentTypeUpdateStruct->defaultAlwaysAvailable = $this->parserTools->parseBooleanValue($data['defaultAlwaysAvailable']);
        }

        if (array_key_exists('names', $data)) {
            if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
                throw new Exceptions\Parser("Invalid 'names' element for ContentTypeUpdate.");
            }

            $contentTypeUpdateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
        }

        if (array_key_exists('descriptions', $data)) {
            if (!is_array($data['descriptions']) || !array_key_exists('value', $data['descriptions']) || !is_array($data['descriptions']['value'])) {
                throw new Exceptions\Parser("Invalid 'descriptions' element for ContentTypeUpdate.");
            }

            $contentTypeUpdateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
        }

        if (array_key_exists('modificationDate', $data)) {
            $contentTypeUpdateStruct->modificationDate = new DateTime($data['modificationDate']);
        }

        if (array_key_exists('User', $data)) {
            if (!array_key_exists('_href', $data['User'])) {
                throw new Exceptions\Parser("Missing '_href' attribute for User element in ContentTypeUpdate.");
            }

            $contentTypeUpdateStruct->modifierId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
        }

        return $contentTypeUpdateStruct;
    }
35868
public function character_data($parser, $data)
    {
        $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
        if (isset($this->message[$pos]['cdata'])) {
            $this->message[$pos]['cdata'] .= $data;
        }
        if ($this->documentation) {
            $this->documentation .= $data;
        }
    }
237830
protected function parseView(ExpressViewRenderer $renderer, $data, $resource = '')
	{
		try
		{
			// This ugly pre-processing is neccessary due to DOM XML forgetting about self-closing elements.
			$reader = new XmlStreamReader();
			$reader->XML($data);
			
			$buffer = '<?xml version="1.0"?>' . "\n";
			
			while($reader->read())
			{
				switch($reader->nodeType)
				{
					case XmlStreamReader::ELEMENT:
						$buffer .= '<' . $reader->name;
						
						$namespaces = [];
						
						while($reader->moveToNextAttribute())
						{
							if($reader->namespaceURI == self::NS_XML)
							{
								switch($reader->localName)
								{
									case 'nsdec':
									case 'empty':
										continue 2;
								}
							}
							
							if($reader->namespaceURI == self::NS_XMLNS)
							{
								$namespaces[$reader->name] = $reader->value;
							}
						
							$buffer .= ' ' . $reader->name . '="' . htmlspecialchars($reader->value, ENT_COMPAT | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8') . '"';
						}
						
						$reader->moveToElement();
						
						if(!empty($namespaces))
						{
							$encoded = base64_encode(json_encode($namespaces, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
							$buffer .= ' xml:nsdec="' . htmlspecialchars($encoded, ENT_QUOTES | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8') . '"';
						}
						
						if($reader->isEmptyElement)
						{
							$buffer .= ' xml:empty="" />';
						}
						else
						{
							$buffer .= '>';
						}
						break;
					case XmlStreamReader::END_ELEMENT:
						$buffer .= '</' . $reader->name . '>';
						break;
					case XmlStreamReader::SIGNIFICANT_WHITESPACE:
					case XmlStreamReader::TEXT:
					case XmlStreamReader::WHITESPACE:
						$buffer .= htmlspecialchars($reader->value, ENT_QUOTES | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8');
						break;
				}
			}
			
			// Parse XML buffer into a DOM document.
			$builder = new XmlDocumentBuilder();
			$xml = $builder->buildFromSource($buffer);
	
			$compiler = new ExpressCompiler($renderer);
			$compiler->setResource($resource);
			
			$parser = new ExpressViewParser();
			
			$view = $parser->parseSource($xml);
			$view->compile($compiler);
			
			return $compiler;
		}
		catch(\Exception $e)
		{
			$ex = $e;
			
			do
			{
				if($ex instanceof ExpressViewException)
				{
					if($ex->getErrorFile() === NULL)
					{
						$ex->setErrorFile($resource);
					}
				}
			}
			while($ex = $ex->getPrevious());
			
			throw $e;
		}
	}
1319296
public function onData(string $data)
    {
        $data = trim($data);
        $this->log('->' . $data);
        $chunks = explode(' ', $data);
        $command = $chunks[0];
        unset($chunks[0]);
        $input = '';
        if (count($chunks) > 0) {
            $input = implode(' ', $chunks);
        }
        $input = trim($input);
        if ($this->node->getCommands()->has($command)) {
            $this
                ->node
                ->getCommands()
                ->get($command)
                ->handle($this, $input)
                ->then(function (array $lines) {
                    foreach ($lines as $line) {
                        $this->write($line);
                    }
                });
            return;
        }

        $list = implode(', ', $this->node->getCommands()->keys());
        $this->write(
            '# Unknown command. Try ' . substr_replace($list, ' or ', strrpos($list, ', '), 2)
        );
    }
991117
function xmlDefaultHandler($parser,$data)
		{
			//strip '<!--' and '-->' off comments
			$data = repl(array("&lt;!--", "--&gt;"), "", htmlspecialchars($data));
			$count = $this->xmlCount - 1;
			if(!empty($this->xmlDData[$count])) $this->xmlDData[$count] .= $data;
			else $this->xmlDData[$count] = $data;
		}
1153222
public function characters($data)
    {
        $s = trim($data);
        if (strlen($s) > 0) {
            throw new ExpatParseException("Unexpected text '$s'", $this->parser->getLocation());
        }
    }
1338860
public function setValue($value, $data = null)
    {
        $value = $this->preventHtmlParserError($value);
        return parent::setValue($value, $data);
    }
773620
public function openHandler(&$parser, $name, $attrs, $closed) {
        // entities are not resolved in attrs
        foreach ($attrs as $key => $attr) {
            $attrs[$key] = $this->parseData($attr);
        }
        if ($closed) {
            $this->tokens[] = new HTMLPurifier_Token_Empty($name, $attrs);
        } else {
            $this->tokens[] = new HTMLPurifier_Token_Start($name, $attrs);
        }
        return true;
    }
628923
public function handleData($data)
    {
        $this->incomingBuffer .= $data;

        if ($this->connection && $this->isHeaderEnd($this->incomingBuffer)) {
            $remoteAddress = (string) $this->incoming->getRemoteAddress();
            $headersToReplace = [
                'X-PHP-PM-Remote-IP' => trim(parse_url($remoteAddress, PHP_URL_HOST), '[]'),
                'X-PHP-PM-Remote-Port' => trim(parse_url($remoteAddress, PHP_URL_PORT), '[]')
            ];

            $buffer = $this->replaceHeader($this->incomingBuffer, $headersToReplace);
            $this->connection->write($buffer);

            $this->incoming->removeListener('data', [$this, 'handleData']);
            $this->incoming->pipe($this->connection);
        }
    }
378381
public function write($data): void
    {
        $rand = \random_int(0, 28);
        $frame = [
            'fin' => 1,
            'rsv1' => 0,
            'rsv2' => 0,
            'rsv3' => 0,
            'opcode' => 1, // We always send text
            'mask' => 1,
            'len' => \strlen($data),
            'mask_key' => \substr(\md5(\uniqid()), $rand, 4),
            'data' => $data,
        ];

        if (1 === $frame['mask']) {
            for ($i = 0; $i < $frame['len']; ++$i) {
                $frame['data'][$i]
                    = \chr(\ord($frame['data'][$i]) ^ \ord($frame['mask_key'][$i % 4]));
            }
        }

        if ($frame['len'] > 2 ** 16) {
            $len = 127;
        } elseif ($frame['len'] > 125) {
            $len = 126;
        } else {
            $len = $frame['len'];
        }

        $firstByte = ($frame['fin'] << 7) | (($frame['rsv1'] << 7) >> 1) | (($frame['rsv2'] << 7) >> 2) | (($frame['rsv3'] << 7) >> 3) | (($frame['opcode'] << 4) >> 4);
        $secondByte = ($frame['mask'] << 7) | (($len << 1) >> 1);

        $this->socketWrite(\chr($firstByte));
        $this->socketWrite(\chr($secondByte));

        if (126 === $len) {
            $this->socketWrite(\pack('n', $frame['len']));
        } elseif (127 === $len) {
            $higher = $frame['len'] >> 32;
            $lower = ($frame['len'] << 32) >> 32;
            $this->socketWrite(\pack('N', $higher));
            $this->socketWrite(\pack('N', $lower));
        }

        if (1 === $frame['mask']) {
            $this->socketWrite($frame['mask_key']);
        }

        $this->socketWrite($frame['data']);
    }
454614
private function cdataHandler($xmlParser, $cdata) {
		//Last element in stack = parent element of the CDATA.
		$currentElement = $this->stack[count($this->stack)-1];
		$currentElement->appendCDataChild($cdata);

		// hhvm invokes several cdata chunks if they contain \n
        $this->previousCData .= $cdata;
	}
1095378
public function startXML($parser, $name, $attr) {
			if($this->xml_depth == 0) {
				$this->session_id = $attr['ID'];
				$this->authenticate();
			}
			parent::startXML($parser, $name, $attr);
		}
1263298
function parseRequest($headers, $data)
    {
        $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
        $this->appendDebug($this->varDump($headers));
        if (!isset($headers['content-type'])) {
            $this->setError('Request not of type text/xml (no content-type header)');

            return FALSE;
        }
        if (!strstr($headers['content-type'], 'text/xml')) {
            $this->setError('Request not of type text/xml');

            return FALSE;
        }
        if (strpos($headers['content-type'], '=')) {
            $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
            $this->debug('Got response encoding: ' . $enc);
            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
                $this->xml_encoding = strtoupper($enc);
            } else {
                $this->xml_encoding = 'US-ASCII';
            }
        } else {
            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
            $this->xml_encoding = 'ISO-8859-1';
        }
        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
        // parse response, get soap parser obj
        $parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8);
        // parser debug
        $this->debug("parser debug: \n" . $parser->getDebug());
        // if fault occurred during message parsing
        if ($err = $parser->getError()) {
            $this->result = 'fault: error in msg parsing: ' . $err;
            $this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err);
            // else successfully parsed request into soapval object
        } else {
            // get/set methodname
            $this->methodURI  = $parser->root_struct_namespace;
            $this->methodname = $parser->root_struct_name;
            $this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
            $this->debug('calling parser->get_soapbody()');
            $this->methodparams = $parser->get_soapbody();
            // get SOAP headers
            $this->requestHeaders = $parser->getHeaders();
            // get SOAP Header
            $this->requestHeader = $parser->get_soapheader();
            // add document for doclit support
            $this->document = $parser->document;
        }
    }
729138
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $policyUpdate = $this->roleService->newPolicyUpdateStruct();

        // @todo XSD says that limitations field is mandatory, but
        // it needs to be possible to remove limitations from policy
        if (array_key_exists('limitations', $data)) {
            if (!is_array($data['limitations'])) {
                throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyUpdate.");
            }

            if (!isset($data['limitations']['limitation']) || !is_array($data['limitations']['limitation'])) {
                throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyUpdate.");
            }

            foreach ($data['limitations']['limitation'] as $limitationData) {
                $policyUpdate->addLimitation(
                    $this->parserTools->parseLimitation($limitationData)
                );
            }
        }

        return $policyUpdate;
    }