$srcParts Template parts
* @return string
*/
public function serializeFromParts(
SerializerState $state, Element $node, array $srcParts
): string {
$useTplData = WTUtils::isNewElt( $node ) || DiffUtils::hasDiffMarkers( $node );
$buf = '';
foreach ( $srcParts as $i => $part ) {
if ( is_string( $part ) ) {
$buf .= $part;
continue;
}
$prevPart = $srcParts[$i - 1] ?? null;
$nextPart = $srcParts[$i + 1] ?? null;
if ( !isset( $part->targetWt ) ) {
// Maybe we should just raise a ClientError
$this->env->log( 'error', 'data-mw.parts array is malformed: ',
DOMCompat::getOuterHTML( $node ), PHPUtils::jsonEncode( $srcParts ) );
continue;
}
// Account for clients leaving off the params array, presumably when empty.
// See T291741
$part->paramInfos ??= [];
if ( $part->type === 'templatearg' ) {
$buf = $this->serializePart(
$state, $buf, $node, $part, null, $prevPart,
$nextPart
);
continue;
}
// transclusion: tpl or parser function?
// templates have $part->href
// parser functions have $part->func
// While the API supports fetching multiple template data objects in one call,
// we will fetch one at a time to benefit from cached responses.
//
// Fetch template data for the template
$tplData = null;
$apiResp = null;
if ( isset( $part->href ) && $useTplData ) {
// Not a parser function
try {
$title = Title::newFromText(
PHPUtils::stripPrefix( Utils::decodeURIComponent( $part->href ), './' ),
$this->env->getSiteConfig()
);
$tplData = $this->env->getDataAccess()->fetchTemplateData( $this->env->getPageConfig(), $title );
} catch ( Exception $err ) {
// Log the error, and use default serialization mode.
// Better to misformat a transclusion than to lose an edit.
$this->env->log( 'error/html2wt/tpldata', $err );
}
}
// If the template doesn't exist, or does but has no TemplateData, ignore it
if ( !empty( $tplData['missing'] ) || !empty( $tplData['notemplatedata'] ) ) {
$tplData = null;
}
$buf = $this->serializePart( $state, $buf, $node, $part, $tplData, $prevPart, $nextPart );
}
return $buf;
}
public function serializeExtensionStartTag( Element $node, SerializerState $state ): string {
$dataMw = DOMDataUtils::getDataMw( $node );
$extTagName = $dataMw->name;
// Serialize extension attributes in normalized form as:
// key='value'
// FIXME: with no dataParsoid, shadow info will mark it as new
$attrs = (array)( $dataMw->attrs ?? [] );
$extTok = new TagTk( $extTagName, array_map( static function ( $key ) use ( $attrs ) {
return new KV( $key, $attrs[$key] );
}, array_keys( $attrs ) ) );
$about = DOMCompat::getAttribute( $node, 'about' );
if ( $about !== null ) {
$extTok->addAttribute( 'about', $about );
}
$typeof = DOMCompat::getAttribute( $node, 'typeof' );
if ( $typeof !== null ) {
$extTok->addAttribute( 'typeof', $typeof );
}
$attrStr = $this->serializeAttributes( $node, $extTok );
$src = '<' . $extTagName;
if ( $attrStr ) {
$src .= ' ' . $attrStr;
}
return $src . ( !empty( $dataMw->body ) ? '>' : ' />' );
}
public function defaultExtensionHandler( Element $node, SerializerState $state ): string {
$dp = DOMDataUtils::getDataParsoid( $node );
$dataMw = DOMDataUtils::getDataMw( $node );
$src = $this->serializeExtensionStartTag( $node, $state );
if ( !isset( $dataMw->body ) ) {
return $src; // We self-closed this already.
} elseif ( is_string( $dataMw->body->extsrc ?? null ) ) {
$src .= $dataMw->body->extsrc;
} elseif ( isset( $dp->src ) ) {
$this->env->log(
'error/html2wt/ext',
'Extension data-mw missing for: ' . DOMCompat::getOuterHTML( $node )
);
return $dp->src;
} else {
$this->env->log(
'error/html2wt/ext',
'Extension src unavailable for: ' . DOMCompat::getOuterHTML( $node )
);
}
return $src . '' . $dataMw->name . '>';
}
/**
* Consolidate separator handling when emitting text.
* @param string $res
* @param Node $node
*/
private function serializeText( string $res, Node $node ): void {
$state = $this->state;
// Deal with trailing separator-like text (at least 1 newline and other whitespace)
preg_match( self::$separatorREs['sepSuffixWithNlsRE'], $res, $newSepMatch );
$res = preg_replace( self::$separatorREs['sepSuffixWithNlsRE'], '', $res, 1 );
if ( !$state->inIndentPre ) {
// Strip leading newlines and other whitespace
if ( preg_match( self::$separatorREs['sepPrefixWithNlsRE'], $res, $match ) ) {
$state->appendSep( $match[0] );
$res = substr( $res, strlen( $match[0] ) );
}
}
if ( $state->needsEscaping ) {
$res = Utils::escapeWtEntities( $res );
}
$state->emitChunk( $res, $node );
// Move trailing newlines into the next separator
if ( $newSepMatch ) {
if ( !$state->sep->src ) {
$state->appendSep( $newSepMatch[0] );
} else {
/* SSS FIXME: what are we doing with the stripped NLs?? */
}
}
}
/**
* Serialize the content of a text node
* @param Node $node
* @return Node|null
*/
private function serializeTextNode( Node $node ): ?Node {
$this->state->needsEscaping = true;
$this->serializeText( $node->nodeValue, $node );
$this->state->needsEscaping = false;
return $node->nextSibling;
}
/**
* Emit non-separator wikitext that does not need to be escaped.
* @param string $res
* @param Node $node
*/
public function emitWikitext( string $res, Node $node ): void {
$this->serializeText( $res, $node );
}
/**
* DOM-based serialization
* @param Element $node
* @param DOMHandler $domHandler
* @return Node|null
*/
private function serializeNodeInternal( Element $node, DOMHandler $domHandler ) {
// To serialize a node from source, the node should satisfy these
// conditions:
//
// 1. It should not have a diff marker or be in a modified subtree
// WTS should not be in a subtree with a modification flag that
// applies to every node of a subtree (rather than an indication
// that some node in the subtree is modified).
//
// 2. It should continue to be valid in any surrounding edited context
// For some nodes, modification of surrounding context
// can change serialized output of this node
// (ex: | s and whether you emit | or || for them)
//
// 3. It should have valid, usable DSR
//
// 4. Either it has non-zero positive DSR width, or meets one of the
// following:
//
// 4a. It is content like
or an automatically-inserted
// wikitext (HTML ) (will have dsr-width 0)
// 4b. it is fostered content (will have dsr-width 0)
// 4c. it is misnested content (will have dsr-width 0)
//
// SSS FIXME: Additionally, we can guard against buggy DSR with
// some validity checks. We can test that non-sep src content
// leading wikitext markup corresponds to the node type.
//
// Ex: If node.nodeName is 'UL', then src[0] should be '*'
//
// TO BE DONE
$state = $this->state;
$wrapperUnmodified = false;
$dp = DOMDataUtils::getDataParsoid( $node );
if ( $state->selserMode
&& !$state->inInsertedContent
&& WTSUtils::origSrcValidInEditedContext( $state, $node )
&& Utils::isValidDSR( $dp->dsr ?? null )
&& ( $dp->dsr->end > $dp->dsr->start
// FIXME:
// nodes that have dsr width 0 because currently,
// we emit newlines outside the p-nodes. So, this check
// tries to handle that scenario.
|| (
$dp->dsr->end === $dp->dsr->start && (
in_array( DOMCompat::nodeName( $node ), [ 'p', 'br' ], true )
|| !empty( DOMDataUtils::getDataMw( $node )->autoGenerated )
// FIXME: This is only necessary while outputContentVersion
// 2.1.2 - 2.2.0 are still valid
|| DOMUtils::hasTypeOf( $node, 'mw:Placeholder/StrippedTag' )
)
)
|| !empty( $dp->fostered )
|| !empty( $dp->misnested )
)
) {
if ( !DiffUtils::hasDiffMarkers( $node ) ) {
// If this HTML node will disappear in wikitext because of
// zero width, then the separator constraints will carry over
// to the node's children.
//
// Since we dont recurse into 'node' in selser mode, we update the
// separator constraintInfo to apply to 'node' and its first child.
//
// We could clear constraintInfo altogether which would be
// correct (but could normalize separators and introduce dirty
// diffs unnecessarily).
$state->currNodeUnmodified = true;
if ( WTUtils::isZeroWidthWikitextElt( $node )
&& $node->hasChildNodes()
&& ( $state->sep->constraints['constraintInfo']['sepType'] ?? null ) === 'sibling'
) {
$state->sep->constraints['constraintInfo']['onSOL'] = $state->onSOL;
$state->sep->constraints['constraintInfo']['sepType'] = 'parent-child';
$state->sep->constraints['constraintInfo']['nodeA'] = $node;
$state->sep->constraints['constraintInfo']['nodeB'] = $node->firstChild;
}
$out = $state->getOrigSrc( $dp->dsr ) ?? '';
$this->trace( 'ORIG-src with DSR', static function () use ( $dp, $out ) {
return '[' . $dp->dsr->start . ',' . $dp->dsr->end . '] = '
. PHPUtils::jsonEncode( $out );
} );
// When reusing source, we should only suppress serializing
// to a single line for the cases we've allowed in normal serialization.
// tags might look surprising here, but, here is the rationale.
// If some link syntax (wikilink, extlink, etc.) accepted a newline
// originally, we can safely let it through here. There is no need to have
// specific checks for wikilnks / extlinks / ... etc. The only concern is
// if the surrounding context in which this link-syntax is embedded also
// breaks the link syntax. There is no such syntax right now.
// FIXME: Note the limitation here, that if these nodes are nested
// in something as trivial as an i / b, the suppression won't happen
// and we'll dirty the text.
$suppressSLC = WTUtils::isFirstEncapsulationWrapperNode( $node )
|| DOMUtils::hasTypeOf( $node, 'mw:Nowiki' )
|| in_array( DOMCompat::nodeName( $node ), [ 'dl', 'ul', 'ol', 'a' ], true )
|| ( DOMCompat::nodeName( $node ) === 'table'
&& DOMCompat::nodeName( $node->parentNode ) === 'dd'
&& DiffDOMUtils::previousNonSepSibling( $node ) === null );
// Use selser to serialize this text! The original
// wikitext is `out`. But first allow
// `ConstrainedText.fromSelSer` to figure out the right
// type of ConstrainedText chunk(s) to use to represent
// `out`, based on the node type. Since we might actually
// have to break this wikitext into multiple chunks,
// `fromSelSer` returns an array.
if ( $suppressSLC ) {
$state->singleLineContext->disable();
}
foreach ( ConstrainedText::fromSelSer( $out, $node, $dp, $this->env ) as $ct ) {
$state->emitChunk( $ct, $ct->node );
}
if ( $suppressSLC ) {
$state->singleLineContext->pop();
}
// Skip over encapsulated content since it has already been
// serialized.
if ( WTUtils::isFirstEncapsulationWrapperNode( $node ) ) {
return WTUtils::skipOverEncapsulatedContent( $node );
} else {
return $node->nextSibling;
}
}
$wrapperUnmodified = DiffUtils::onlySubtreeChanged( $node ) &&
WTSUtils::hasValidTagWidths( $dp->dsr ?? null );
}
$state->currNodeUnmodified = false;
$currentInsertedState = $state->inInsertedContent;
$inInsertedContent = $state->selserMode && DiffUtils::hasInsertedDiffMark( $node );
if ( $inInsertedContent ) {
$state->inInsertedContent = true;
}
$next = $domHandler->handle( $node, $state, $wrapperUnmodified );
if ( $inInsertedContent ) {
$state->inInsertedContent = $currentInsertedState;
}
return $next;
}
/**
* Internal worker. Recursively serialize a DOM subtree.
* @private
* @param Node $node
* @return ?Node
*/
public function serializeNode( Node $node ): ?Node {
$nodeName = DOMCompat::nodeName( $node );
$domHandler = $method = null;
$domHandlerFactory = new DOMHandlerFactory();
$state = $this->state;
$state->currNode = $node;
if ( $state->selserMode ) {
$this->trace(
static function () use ( $node ) {
return WTSUtils::traceNodeName( $node );
},
'; prev-unmodified: ', $state->prevNodeUnmodified,
'; SOL: ', $state->onSOL );
} else {
$this->trace(
static function () use ( $node ) {
return WTSUtils::traceNodeName( $node );
},
'; SOL: ', $state->onSOL );
}
switch ( $node->nodeType ) {
case XML_ELEMENT_NODE:
'@phan-var Element $node';/** @var Element $node */
// Ignore DiffMarker metas, but clear unmodified node state
if ( DiffUtils::isDiffMarker( $node ) ) {
$state->updateModificationFlags( $node );
// `state.sep.lastSourceNode` is cleared here so that removed
// separators between otherwise unmodified nodes don't get
// restored.
$state->updateSep( $node );
return $node->nextSibling;
}
$domHandler = $domHandlerFactory->getDOMHandler( $node );
$method = [ $this, 'serializeNodeInternal' ];
break;
case XML_TEXT_NODE:
// This code assumes that the DOM is in normalized form with no
// run of text nodes.
// Accumulate whitespace from the text node into state.sep.src
$text = $node->nodeValue;
if ( !$state->inIndentPre
// PORT-FIXME: original uses this->state->serializer->separatorREs
// but that does not seem useful
&& preg_match( self::$separatorREs['pureSepRE'], $text )
) {
$state->appendSep( $text );
return $node->nextSibling;
}
if ( $state->selserMode ) {
$prev = $node->previousSibling;
if ( !$state->inInsertedContent && (
( !$prev && DOMUtils::atTheTop( $node->parentNode ) ) ||
( $prev && !DiffUtils::isDiffMarker( $prev ) )
) ) {
$state->currNodeUnmodified = true;
} else {
$state->currNodeUnmodified = false;
}
}
$domHandler = new DOMHandler( false );
$method = [ $this, 'serializeTextNode' ];
break;
case XML_COMMENT_NODE:
// Merge this into separators
$state->appendSep( WTSUtils::commentWT( $node->nodeValue ) );
return $node->nextSibling;
default:
throw new InternalException( 'Unhandled node type: ' . $node->nodeType );
}
$prev = DiffDOMUtils::previousNonSepSibling( $node ) ?: $node->parentNode;
$this->env->log( 'debug/wts', 'Before constraints for ' . $nodeName );
$state->separators->updateSeparatorConstraints(
$prev, $domHandlerFactory->getDOMHandler( $prev ),
$node, $domHandler
);
$this->env->log( 'debug/wts', 'Calling serialization handler for ' . $nodeName );
$nextNode = call_user_func( $method, $node, $domHandler );
$next = DiffDOMUtils::nextNonSepSibling( $node ) ?: $node->parentNode;
$this->env->log( 'debug/wts', 'After constraints for ' . $nodeName );
$state->separators->updateSeparatorConstraints(
$node, $domHandler,
$next, $domHandlerFactory->getDOMHandler( $next )
);
// Update modification flags
$state->updateModificationFlags( $node );
return $nextNode;
}
private function stripUnnecessaryHeadingNowikis( string $line ): string {
$state = $this->state;
if ( !$state->hasHeadingEscapes ) {
return $line;
}
$escaper = static function ( string $wt ) use ( $state ) {
$ret = $state->serializer->wteHandlers->escapedText( $state, false, $wt, false, true );
return $ret;
};
preg_match( self::HEADING_NOWIKI_REGEXP, $line, $match );
if ( $match && !preg_match( self::COMMENT_OR_WS_REGEXP, $match[2] ) ) {
// The nowikiing was spurious since the trailing = is not in EOL position
return $escaper( $match[1] ) . $match[2];
} else {
// All is good.
return $line;
}
}
private function stripUnnecessaryIndentPreNowikis(): void {
// FIXME: The solTransparentWikitextRegexp includes redirects, which really
// only belong at the SOF and should be unique. See the "New redirect" test.
$noWikiRegexp = '@^'
. PHPUtils::reStrip( $this->env->getSiteConfig()->solTransparentWikitextNoWsRegexp(), '@' )
. '((?i:\s+))([^\n]*(?:\n|$))' . '@Dm';
$pieces = preg_split( $noWikiRegexp, $this->state->out, -1, PREG_SPLIT_DELIM_CAPTURE );
$out = $pieces[0];
for ( $i = 1; $i < count( $pieces ); $i += 4 ) {
$out .= $pieces[$i];
$nowiki = $pieces[$i + 1];
$rest = $pieces[$i + 2];
// Ignore comments
preg_match_all( '/<[^!][^<>]*>/', $rest, $htmlTags );
// Not required if just sol transparent wt.
$reqd = !preg_match( $this->env->getSiteConfig()->solTransparentWikitextRegexp(), $rest );
if ( $reqd ) {
foreach ( $htmlTags[0] as $j => $rawTagName ) {
// Strip , attributes, and > to get the tagname
$tagName = preg_replace( '/<\/?|\s.*|>/', '', $rawTagName );
if ( !isset( Consts::$HTML['HTML5Tags'][$tagName] ) ) {
// If we encounter any tag that is not a html5 tag,
// it could be an extension tag. We could do a more complex
// regexp or tokenize the string to determine if any block tags
// show up outside the extension tag. But, for now, we just
// conservatively bail and leave the nowiki as is.
$reqd = true;
break;
} elseif ( TokenUtils::isWikitextBlockTag( $tagName ) ) {
// FIXME: Extension tags shadowing html5 tags might not
// have block semantics.
// Block tags on a line suppress nowikis
$reqd = false;
}
}
}
if ( !$reqd ) {
$nowiki = preg_replace( '#^(\s+)#', '$1', $nowiki, 1 );
} else {
$solTransparentWikitextNoWsRegexpFragment = PHPUtils::reStrip(
$this->env->getSiteConfig()->solTransparentWikitextNoWsRegexp(), '/' );
$wsReplacementRE = '/^(' . $solTransparentWikitextNoWsRegexpFragment . ')\s+/';
// Replace all leading whitespace
do {
$oldRest = $rest;
$rest = preg_replace( $wsReplacementRE, '$1', $rest );
} while ( $rest !== $oldRest );
// Protect against sol-sensitive wikitext characters
$solCharsTest = '/^' . $solTransparentWikitextNoWsRegexpFragment . '[=*#:;]/';
$nowiki = preg_replace( '#^(\s+)#',
preg_match( $solCharsTest, $rest ) ? '' : '', $nowiki, 1 );
}
$out = $out . $nowiki . $rest . $pieces[$i + 3];
}
$this->state->out = $out;
}
/**
* This implements a heuristic to strip two common sources of s.
* When and tags are matched up properly,
* - any single ' char before or does not need protection.
* - any single ' char before or does not need protection.
* @param string $line
* @return string
*/
private function stripUnnecessaryQuoteNowikis( string $line ): string {
if ( !$this->state->hasQuoteNowikis ) {
return $line;
}
// Optimization: We are interested in s before quote chars.
// So, skip this if we don't have both.
if ( !( preg_match( '##', $line ) && preg_match( "/'/", $line ) ) ) {
return $line;
}
// * Split out all the [[ ]] {{ }} '' ''' ''''' <..>
// parens in the regexp mean that the split segments will
// be spliced into the result array as the odd elements.
// * If we match up the tags properly and we see opening
// / / tags preceded by a ', we
// can remove all those nowikis.
// Ex: '''foo'' bar ''''baz'''
// * If we match up the tags properly and we see closing
// / / tags preceded by a ', we
// can remove all those nowikis.
// Ex: ''foo''' bar '''baz''''
// phpcs:ignore Generic.Files.LineLength.TooLong
$p = preg_split( "#('''''|'''|''|\[\[|\]\]|\{\{|\}\}|<\w+(?:\s+[^>]*?|\s*?)/?>|\w+\s*>)#", $line, -1, PREG_SPLIT_DELIM_CAPTURE );
// Which nowiki do we strip out?
$nowikiIndex = -1;
// Verify that everything else is properly paired up.
$stack = [];
$quotesOnStack = 0;
$n = count( $p );
$nonHtmlTag = null;
for ( $j = 1; $j < $n; $j += 2 ) {
// For HTML tags, pull out just the tag name for clearer code below.
preg_match( '#^<(/?\w+)#', $p[$j], $matches );
$tag = mb_strtolower( $matches[1] ?? $p[$j] );
$tagLen = strlen( $tag );
$selfClose = false;
if ( str_ends_with( $p[$j], '/>' ) ) {
$tag .= '/';
$selfClose = true;
}
// Ignore non-html-tag ( OR extension tag) blocks
if ( !$nonHtmlTag ) {
if ( isset( $this->env->getSiteConfig()->getExtensionTagNameMap()[$tag] ) ) {
$nonHtmlTag = $tag;
continue;
}
} else {
if ( $tagLen > 0 && $tag[0] === '/' && substr( $tag, 1 ) === $nonHtmlTag ) {
$nonHtmlTag = null;
}
continue;
}
if ( $tag === ']]' ) {
if ( array_pop( $stack ) !== '[[' ) {
return $line;
}
} elseif ( $tag === '}}' ) {
if ( array_pop( $stack ) !== '{{' ) {
return $line;
}
} elseif ( $tagLen > 0 && $tag[0] === '/' ) { // closing html tag
// match html/ext tags
$openTag = array_pop( $stack );
if ( $tag !== ( '/' . $openTag ) ) {
return $line;
}
} elseif ( $tag === 'nowiki/' ) {
// We only want to process:
// - trailing single quotes (bar')
// - or single quotes by themselves without a preceding '' sequence
if ( substr( $p[$j - 1], -1 ) === "'"
&& !( $p[$j - 1] === "'" && $j > 1 && substr( $p[$j - 2], -2 ) === "''" )
// Consider foobar'baz or foo'bar'baz.
// The before the or cannot be stripped
// if the is embedded inside another quote.
&& ( $quotesOnStack === 0
// The only strippable scenario with a single quote elt on stack
// is: ''bar'''
// -> ["", "''", "bar'", "", "", "''"]
|| ( $quotesOnStack === 1
&& $j + 2 < $n
&& $p[$j + 1] === ''
&& $p[$j + 2][0] === "'"
&& $p[$j + 2] === PHPUtils::lastItem( $stack ) ) )
) {
$nowikiIndex = $j;
}
continue;
} elseif ( $selfClose || $tag === 'br' ) {
// Skip over self-closing tags or what should have been self-closed.
// ( While we could do this for all void tags defined in
// mediawiki.wikitext.constants.js, is the most common
// culprit. )
continue;
} elseif ( $tagLen > 0 && $tag[0] === "'" && PHPUtils::lastItem( $stack ) === $tag ) {
array_pop( $stack );
$quotesOnStack--;
} else {
$stack[] = $tag;
if ( $tagLen > 0 && $tag[0] === "'" ) {
$quotesOnStack++;
}
}
}
if ( count( $stack ) ) {
return $line;
}
if ( $nowikiIndex !== -1 ) {
// We can only remove the final trailing nowiki.
//
// HTML : 'foo'
// line : '''foo'''
$p[$nowikiIndex] = '';
return implode( '', $p );
} else {
return $line;
}
}
/**
* Serialize an HTML DOM.
*
* WARNING: You probably want to use WikitextContentModelHandler::fromDOM instead.
*
* @param Document|DocumentFragment $node
* @param bool $selserMode
* @return string
*/
public function serializeDOM(
Node $node, bool $selserMode = false
): string {
Assert::parameterType(
Document::class . '|' . DocumentFragment::class,
$node, '$node' );
if ( $node instanceof Document ) {
$node = DOMCompat::getBody( $node );
}
$this->logType = $selserMode ? 'trace/selser' : 'trace/wts';
$state = $this->state;
$state->initMode( $selserMode );
$domNormalizer = new DOMNormalizer( $state );
$domNormalizer->normalize( $node );
if ( $this->env->hasDumpFlag( 'dom:post-normal' ) ) {
$options = [ 'storeDiffMark' => true ];
$this->env->writeDump( ContentUtils::dumpDOM( $node, 'DOM: post-normal', $options ) );
}
$state->kickOffSerialize( $node );
if ( $state->hasIndentPreNowikis ) {
// FIXME: Perhaps this can be done on a per-line basis
// rather than do one post-pass on the entire document.
$this->stripUnnecessaryIndentPreNowikis();
}
$splitLines = $state->selserMode
|| $state->hasQuoteNowikis
|| $state->hasSelfClosingNowikis
|| $state->hasHeadingEscapes;
if ( $splitLines ) {
$state->out = implode( "\n", array_map( function ( $line ) {
// FIXME: Perhaps this can be done on a per-line basis
// rather than do one post-pass on the entire document.
$line = $this->stripUnnecessaryQuoteNowikis( $line );
return $this->stripUnnecessaryHeadingNowikis( $line );
}, explode( "\n", $state->out ) ) );
}
if ( $state->redirectText && $state->redirectText !== 'unbuffered' ) {
$firstLine = explode( "\n", $state->out, 1 )[0];
$nl = preg_match( '/^(\s|$)/D', $firstLine ) ? '' : "\n";
$state->out = $state->redirectText . $nl . $state->out;
}
return $state->out;
}
/**
* @note Porting note: this replaces the pattern $serializer->env->log( $serializer->logType, ... )
* @param mixed ...$args
*/
public function trace( ...$args ) {
$this->env->log( $this->logType, ...$args );
}
}
|