2019-11-22 17:28:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite;
|
|
|
|
|
2019-12-16 16:11:42 +00:00
|
|
|
use LogicException;
|
2019-12-11 15:05:19 +00:00
|
|
|
use Parser;
|
2019-11-22 17:28:51 +00:00
|
|
|
use StripState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encapsulates most of Cite state during parsing. This includes metadata about each ref tag,
|
|
|
|
* and a rollback stack to correct confusion caused by lost context when `{{#tag` is used.
|
2019-11-29 14:00:39 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
|
|
|
class ReferenceStack {
|
|
|
|
|
|
|
|
/**
|
2020-02-03 11:24:28 +00:00
|
|
|
* Data structure representing all <ref> tags parsed so far, indexed by group name (an empty
|
|
|
|
* string for the default group) and reference name.
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
2020-02-03 11:24:28 +00:00
|
|
|
* References without a name get a numeric index, starting from 0. Conflicts are avoided by
|
|
|
|
* disallowing numeric names (e.g. <ref name="1">) in {@see Cite::validateRef}.
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
2020-02-03 11:24:28 +00:00
|
|
|
* Elements (almost all are optional):
|
|
|
|
* - 'name': The original name="…" of a reference (also used as the array key), or null for
|
|
|
|
* anonymous references.
|
|
|
|
* - 'key': Sequence number for all references, no matter which group, starting from 1. Used to
|
|
|
|
* generate IDs and anchors.
|
|
|
|
* - 'number': Sequence number per group, starting from 1. To be used in the [1] footnote
|
|
|
|
* marker.
|
|
|
|
* - 'extendsIndex': Sequence number for sub-references with the same extends="…", starting
|
|
|
|
* from 1. Used in addition to the 'number' in [1.1] footnote markers.
|
|
|
|
* - 'count': How often a reference is reused. 0 means not reused, i.e. the reference appears
|
|
|
|
* only one time. -1 for anonymous references that cannot be reused.
|
|
|
|
* - 'extends': Marks a sub-reference. Points to the parent reference by name.
|
2020-02-05 15:28:45 +00:00
|
|
|
* - 'follow': Marks an incomplete follow="…". This is valid e.g. in the Page:… namespace on
|
|
|
|
* Wikisource.
|
2020-02-03 11:24:28 +00:00
|
|
|
* - '__placeholder__': Temporarily marks an incomplete parent reference that was referenced via
|
|
|
|
* extends="…" before it exists.
|
|
|
|
* - 'text': The content inside the <ref>…</ref> tag. Null for <ref /> without content. Also
|
|
|
|
* null for <ref></ref> without any non-whitespace content.
|
|
|
|
* - 'dir': Direction of the text. Should either be "ltr" or "rtl".
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
|
|
|
* @var array[][]
|
|
|
|
*/
|
|
|
|
private $refs = [];
|
|
|
|
|
|
|
|
/**
|
2020-02-03 11:24:28 +00:00
|
|
|
* Auto-incrementing sequence number for all <ref>, no matter which group
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $refSequence = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counter for the number of refs in each group.
|
|
|
|
* @var int[]
|
|
|
|
*/
|
|
|
|
private $groupRefSequence = [];
|
|
|
|
|
2019-11-27 23:29:47 +00:00
|
|
|
/**
|
|
|
|
* @var int[][]
|
|
|
|
*/
|
|
|
|
private $extendsCount = [];
|
|
|
|
|
2019-11-22 17:28:51 +00:00
|
|
|
/**
|
|
|
|
* <ref> call stack
|
|
|
|
* Used to cleanup out of sequence ref calls created by #tag
|
|
|
|
* See description of function rollbackRef.
|
|
|
|
*
|
|
|
|
* @var (array|false)[]
|
|
|
|
*/
|
|
|
|
private $refCallStack = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated We should be able to push this responsibility to calling code.
|
2019-12-09 16:08:57 +00:00
|
|
|
* @var ErrorReporter
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
|
|
|
private $errorReporter;
|
|
|
|
|
|
|
|
/**
|
2019-12-09 16:08:57 +00:00
|
|
|
* @param ErrorReporter $errorReporter
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-12-09 16:08:57 +00:00
|
|
|
public function __construct( ErrorReporter $errorReporter ) {
|
2019-11-22 17:28:51 +00:00
|
|
|
$this->errorReporter = $errorReporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Leave a mark in the stack which matches an invalid ref tag.
|
|
|
|
*/
|
|
|
|
public function pushInvalidRef() {
|
|
|
|
$this->refCallStack[] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate $this->refs and $this->refCallStack based on input and arguments to <ref>
|
|
|
|
*
|
2019-12-11 15:05:19 +00:00
|
|
|
* @param Parser $parser
|
2019-12-19 09:16:14 +00:00
|
|
|
* @param StripState $stripState
|
2019-11-27 15:31:17 +00:00
|
|
|
* @param ?string $text Content from the <ref> tag
|
2019-12-19 09:16:14 +00:00
|
|
|
* @param string[] $argv
|
2019-11-22 17:28:51 +00:00
|
|
|
* @param string $group
|
2019-12-19 09:16:14 +00:00
|
|
|
* @param ?string $name
|
2019-11-27 23:27:11 +00:00
|
|
|
* @param ?string $extends
|
2019-11-27 15:31:17 +00:00
|
|
|
* @param ?string $follow Guaranteed to not be a numeric string
|
|
|
|
* @param ?string $dir ref direction
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
2020-02-05 16:52:21 +00:00
|
|
|
* @return ?array ref structure, or null if no footnote marker should be rendered
|
2020-01-29 01:50:22 +00:00
|
|
|
* @suppress PhanTypePossiblyInvalidDimOffset To many complaints about array indizes
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
|
|
|
public function pushRef(
|
2019-12-11 15:05:19 +00:00
|
|
|
Parser $parser,
|
2019-12-19 09:16:14 +00:00
|
|
|
StripState $stripState,
|
2019-11-27 15:31:17 +00:00
|
|
|
?string $text,
|
2019-12-19 09:16:14 +00:00
|
|
|
array $argv,
|
2019-11-27 15:31:17 +00:00
|
|
|
string $group,
|
2019-12-19 09:16:14 +00:00
|
|
|
?string $name,
|
2019-11-27 23:27:11 +00:00
|
|
|
?string $extends,
|
2019-11-27 15:31:17 +00:00
|
|
|
?string $follow,
|
2019-12-19 09:16:14 +00:00
|
|
|
?string $dir
|
2019-11-27 15:31:17 +00:00
|
|
|
) : ?array {
|
2019-11-22 17:28:51 +00:00
|
|
|
if ( !isset( $this->refs[$group] ) ) {
|
|
|
|
$this->refs[$group] = [];
|
|
|
|
$this->groupRefSequence[$group] = 0;
|
|
|
|
}
|
|
|
|
|
2019-11-26 14:08:18 +00:00
|
|
|
$ref = [
|
|
|
|
'count' => $name ? 0 : -1,
|
|
|
|
'dir' => $dir,
|
2019-11-27 15:31:17 +00:00
|
|
|
// This assumes we are going to register a new reference, instead of reusing one
|
2019-11-26 14:08:18 +00:00
|
|
|
'key' => ++$this->refSequence,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => $name,
|
2019-11-26 14:08:18 +00:00
|
|
|
'text' => $text,
|
|
|
|
];
|
2019-11-22 17:28:51 +00:00
|
|
|
|
2020-02-05 10:39:49 +00:00
|
|
|
if ( $follow ) {
|
2020-02-17 14:29:33 +00:00
|
|
|
if ( !isset( $this->refs[$group][$follow] ) ) {
|
|
|
|
// Mark an incomplete follow="…" as such. This is valid e.g. in the Page:… namespace
|
|
|
|
// on Wikisource.
|
|
|
|
$this->refs[$group][] = $ref + [ 'follow' => $follow ];
|
|
|
|
$this->refCallStack[] = [ 'new', $this->refSequence, $group, $name, $extends, $text,
|
|
|
|
$argv ];
|
|
|
|
} elseif ( $text !== null ) {
|
|
|
|
// We know the parent already, so just perform the follow="…" and bail out
|
|
|
|
$this->appendText( $group, $follow, ' ' . $text );
|
|
|
|
$this->refSequence--;
|
|
|
|
}
|
2020-02-05 16:52:21 +00:00
|
|
|
// A follow="…" never gets its own footnote marker
|
2020-02-05 10:39:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-11-26 14:08:18 +00:00
|
|
|
if ( !$name ) {
|
2019-11-25 15:10:05 +00:00
|
|
|
// This is an anonymous reference, which will be given a numeric index.
|
2019-12-02 15:36:49 +00:00
|
|
|
$this->refs[$group][] = &$ref;
|
2019-11-26 14:08:18 +00:00
|
|
|
$action = 'new';
|
2019-11-29 11:50:07 +00:00
|
|
|
} elseif ( isset( $this->refs[$group][$name]['__placeholder__'] ) ) {
|
|
|
|
// Populate a placeholder.
|
|
|
|
unset( $this->refs[$group][$name]['__placeholder__'] );
|
|
|
|
unset( $ref['number'] );
|
|
|
|
$ref = array_merge( $ref, $this->refs[$group][$name] );
|
|
|
|
$this->refs[$group][$name] =& $ref;
|
2020-01-08 15:50:25 +00:00
|
|
|
$action = 'new-from-placeholder';
|
2019-11-26 14:08:18 +00:00
|
|
|
} elseif ( !isset( $this->refs[$group][$name] ) ) {
|
|
|
|
// Valid key with first occurrence
|
2019-12-02 15:36:49 +00:00
|
|
|
$this->refs[$group][$name] = &$ref;
|
2019-11-22 17:28:51 +00:00
|
|
|
$action = 'new';
|
|
|
|
} else {
|
2019-11-29 18:48:21 +00:00
|
|
|
// Change an existing entry.
|
2019-12-02 15:36:49 +00:00
|
|
|
$ref = &$this->refs[$group][$name];
|
2019-11-26 14:08:18 +00:00
|
|
|
$ref['count']++;
|
2019-11-29 22:24:51 +00:00
|
|
|
// Rollback the global counter since we won't create a new ref.
|
|
|
|
$this->refSequence--;
|
2019-11-26 09:31:41 +00:00
|
|
|
if ( $ref['text'] === null && $text !== null ) {
|
2019-11-26 14:08:18 +00:00
|
|
|
// If no text was set before, use this text
|
|
|
|
$ref['text'] = $text;
|
|
|
|
// Use the dir parameter only from the full definition of a named ref tag
|
|
|
|
$ref['dir'] = $dir;
|
|
|
|
$action = 'assign';
|
|
|
|
} else {
|
2019-11-26 09:31:41 +00:00
|
|
|
if ( $text !== null
|
2019-11-26 14:08:18 +00:00
|
|
|
// T205803 different strip markers might hide the same text
|
|
|
|
&& $stripState->unstripBoth( $text )
|
|
|
|
!== $stripState->unstripBoth( $ref['text'] )
|
|
|
|
) {
|
|
|
|
// two refs with same name and different text
|
|
|
|
// add error message to the original ref
|
|
|
|
// TODO: standardize error display and move to `validateRef`.
|
|
|
|
$ref['text'] .= ' ' . $this->errorReporter->plain(
|
2019-12-11 15:05:19 +00:00
|
|
|
$parser, 'cite_error_references_duplicate_key', $name
|
2019-11-26 14:08:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$action = 'increment';
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 23:10:11 +00:00
|
|
|
|
|
|
|
$ref['number'] = $ref['number'] ?? ++$this->groupRefSequence[$group];
|
|
|
|
|
2020-01-07 14:52:59 +00:00
|
|
|
// Do not mess with a known parent a second time
|
|
|
|
if ( $extends && !isset( $ref['extendsIndex'] ) ) {
|
2019-11-29 11:50:07 +00:00
|
|
|
$this->extendsCount[$group][$extends] =
|
|
|
|
( $this->extendsCount[$group][$extends] ?? 0 ) + 1;
|
2019-11-29 23:10:11 +00:00
|
|
|
|
2019-11-29 11:50:07 +00:00
|
|
|
$ref['extends'] = $extends;
|
|
|
|
$ref['extendsIndex'] = $this->extendsCount[$group][$extends];
|
2019-12-02 15:36:49 +00:00
|
|
|
|
2019-11-29 11:50:07 +00:00
|
|
|
if ( isset( $this->refs[$group][$extends]['number'] ) ) {
|
|
|
|
// Adopt the parent's number.
|
2019-11-29 23:10:11 +00:00
|
|
|
$ref['number'] = $this->refs[$group][$extends]['number'];
|
2019-12-09 09:19:55 +00:00
|
|
|
// Roll back the group sequence number.
|
|
|
|
--$this->groupRefSequence[$group];
|
2019-11-29 23:10:11 +00:00
|
|
|
} else {
|
2019-11-29 11:50:07 +00:00
|
|
|
// Transfer my number to parent ref.
|
|
|
|
$this->refs[$group][$extends] = [
|
|
|
|
'number' => $ref['number'],
|
|
|
|
'__placeholder__' => true,
|
|
|
|
];
|
2019-11-29 23:10:11 +00:00
|
|
|
}
|
2020-01-07 15:46:21 +00:00
|
|
|
} elseif ( $extends && $ref['extends'] !== $extends ) {
|
|
|
|
// TODO: Change the error message to talk about "conflicting content or parent"?
|
2020-01-30 13:20:14 +00:00
|
|
|
$error = $this->errorReporter->plain( $parser, 'cite_error_references_duplicate_key',
|
|
|
|
$name );
|
|
|
|
if ( isset( $ref['text'] ) ) {
|
|
|
|
$ref['text'] .= ' ' . $error;
|
|
|
|
} else {
|
|
|
|
$ref['text'] = $error;
|
|
|
|
}
|
2019-11-29 23:10:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 09:16:14 +00:00
|
|
|
$this->refCallStack[] = [ $action, $ref['key'], $group, $name, $extends, $text, $argv ];
|
2019-11-29 23:26:58 +00:00
|
|
|
return $ref;
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undo the changes made by the last $count ref tags. This is used when we discover that the
|
|
|
|
* last few tags were actually inside of a references tag.
|
|
|
|
*
|
|
|
|
* @param int $count
|
2020-01-08 15:55:49 +00:00
|
|
|
*
|
2019-12-19 09:16:14 +00:00
|
|
|
* @return array[] Refs to restore under the correct context, as a list of [ $text, $argv ]
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-11-28 10:15:19 +00:00
|
|
|
public function rollbackRefs( int $count ) : array {
|
2019-11-22 17:28:51 +00:00
|
|
|
$redoStack = [];
|
2020-01-08 15:55:49 +00:00
|
|
|
while ( $count-- && $this->refCallStack ) {
|
2019-11-22 17:28:51 +00:00
|
|
|
$call = array_pop( $this->refCallStack );
|
2019-12-19 08:23:16 +00:00
|
|
|
if ( $call ) {
|
2019-12-19 10:32:01 +00:00
|
|
|
$redoStack[] = $this->rollbackRef( ...$call );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-08 15:55:49 +00:00
|
|
|
|
2019-11-29 18:48:21 +00:00
|
|
|
// Drop unused rollbacks, this group is finished.
|
2019-11-22 17:28:51 +00:00
|
|
|
$this->refCallStack = [];
|
|
|
|
|
|
|
|
return array_reverse( $redoStack );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Partially undoes the effect of calls to stack()
|
|
|
|
*
|
|
|
|
* Called by guardedReferences()
|
|
|
|
*
|
|
|
|
* The option to define <ref> within <references> makes the
|
|
|
|
* behavior of <ref> context dependent. This is normally fine
|
|
|
|
* but certain operations (especially #tag) lead to out-of-order
|
|
|
|
* parser evaluation with the <ref> tags being processed before
|
|
|
|
* their containing <reference> element is read. This leads to
|
|
|
|
* stack corruption that this function works to fix.
|
|
|
|
*
|
|
|
|
* This function is not a total rollback since some internal
|
|
|
|
* counters remain incremented. Doing so prevents accidentally
|
|
|
|
* corrupting certain links.
|
|
|
|
*
|
2019-12-10 15:04:59 +00:00
|
|
|
* @param string $action
|
2019-12-09 12:26:22 +00:00
|
|
|
* @param int $key Autoincrement counter for this ref.
|
2019-12-19 08:23:16 +00:00
|
|
|
* @param string $group
|
|
|
|
* @param ?string $name The name attribute passed in the ref tag.
|
|
|
|
* @param ?string $extends
|
2019-12-19 10:32:01 +00:00
|
|
|
* @param ?string $text
|
|
|
|
* @param array $argv
|
|
|
|
*
|
|
|
|
* @return array [ $text, $argv ] Ref redo item.
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-11-28 10:15:19 +00:00
|
|
|
private function rollbackRef(
|
2019-12-10 15:04:59 +00:00
|
|
|
string $action,
|
2019-12-19 08:23:16 +00:00
|
|
|
int $key,
|
2019-11-28 10:15:19 +00:00
|
|
|
string $group,
|
2019-12-19 08:23:16 +00:00
|
|
|
?string $name,
|
2019-12-19 10:32:01 +00:00
|
|
|
?string $extends,
|
|
|
|
?string $text,
|
|
|
|
array $argv
|
|
|
|
) : array {
|
2019-11-22 17:28:51 +00:00
|
|
|
if ( !$this->hasGroup( $group ) ) {
|
2019-12-19 10:27:00 +00:00
|
|
|
throw new LogicException( "Cannot roll back ref with unknown group \"$group\"." );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:40:12 +00:00
|
|
|
$lookup = $name ?: null;
|
|
|
|
if ( $lookup === null ) {
|
2019-11-29 18:48:21 +00:00
|
|
|
// Find anonymous ref by key.
|
2019-11-22 17:28:51 +00:00
|
|
|
foreach ( $this->refs[$group] as $k => $v ) {
|
2019-12-02 09:14:49 +00:00
|
|
|
if ( isset( $this->refs[$group][$k]['key'] ) &&
|
2019-12-09 12:26:22 +00:00
|
|
|
$this->refs[$group][$k]['key'] === $key
|
2019-12-02 09:14:49 +00:00
|
|
|
) {
|
2019-12-09 12:18:35 +00:00
|
|
|
$lookup = $k;
|
2019-11-22 17:28:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 10:27:00 +00:00
|
|
|
// Obsessive sanity checks that the specified element exists.
|
|
|
|
if ( $lookup === null ) {
|
|
|
|
throw new LogicException( "Cannot roll back unknown ref by key $key." );
|
|
|
|
} elseif ( !isset( $this->refs[$group][$lookup] ) ) {
|
|
|
|
throw new LogicException( "Cannot roll back missing named ref \"$lookup\"." );
|
|
|
|
} elseif ( $this->refs[$group][$lookup]['key'] !== $key ) {
|
|
|
|
throw new LogicException(
|
|
|
|
"Cannot roll back corrupt named ref \"$lookup\" which should have had key $key." );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 23:29:47 +00:00
|
|
|
if ( $extends ) {
|
|
|
|
$this->extendsCount[$group][$extends]--;
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:04:59 +00:00
|
|
|
switch ( $action ) {
|
2019-11-22 17:28:51 +00:00
|
|
|
case 'new':
|
2020-01-09 10:53:43 +00:00
|
|
|
// Rollback the addition of new elements to the stack
|
2019-12-09 12:18:35 +00:00
|
|
|
unset( $this->refs[$group][$lookup] );
|
2020-01-20 20:11:54 +00:00
|
|
|
if ( !$this->refs[$group] ) {
|
2019-12-09 14:07:37 +00:00
|
|
|
$this->popGroup( $group );
|
2020-01-24 12:02:53 +00:00
|
|
|
} elseif ( isset( $this->groupRefSequence[$group] ) ) {
|
|
|
|
$this->groupRefSequence[$group]--;
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
2020-01-24 12:02:53 +00:00
|
|
|
// TODO: Don't we need to rollback extendsCount as well?
|
2019-11-22 17:28:51 +00:00
|
|
|
break;
|
2020-01-08 15:50:25 +00:00
|
|
|
case 'new-from-placeholder':
|
|
|
|
$this->refs[$group][$lookup]['__placeholder__'] = true;
|
|
|
|
unset( $this->refs[$group][$lookup]['count'] );
|
|
|
|
break;
|
2019-11-22 17:28:51 +00:00
|
|
|
case 'assign':
|
2020-01-09 10:53:43 +00:00
|
|
|
// Rollback assignment of text to pre-existing elements
|
2019-12-09 12:18:35 +00:00
|
|
|
$this->refs[$group][$lookup]['text'] = null;
|
|
|
|
$this->refs[$group][$lookup]['count']--;
|
2019-11-29 22:24:51 +00:00
|
|
|
break;
|
2019-11-22 17:28:51 +00:00
|
|
|
case 'increment':
|
2020-01-09 10:53:43 +00:00
|
|
|
// Rollback increase in named ref occurrences
|
2019-12-09 12:18:35 +00:00
|
|
|
$this->refs[$group][$lookup]['count']--;
|
2019-11-22 17:28:51 +00:00
|
|
|
break;
|
2019-12-06 13:29:32 +00:00
|
|
|
default:
|
2019-12-19 10:27:00 +00:00
|
|
|
throw new LogicException( "Unknown call stack action \"$action\"" );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
2019-12-19 10:32:01 +00:00
|
|
|
return [ $text, $argv ];
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear state for a single group.
|
|
|
|
*
|
|
|
|
* @param string $group
|
2019-12-09 14:07:37 +00:00
|
|
|
*
|
|
|
|
* @return array[] The references from the removed group
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-12-19 13:20:10 +00:00
|
|
|
public function popGroup( string $group ) : array {
|
2019-12-09 14:07:37 +00:00
|
|
|
$refs = $this->getGroupRefs( $group );
|
2019-11-22 17:28:51 +00:00
|
|
|
unset( $this->refs[$group] );
|
|
|
|
unset( $this->groupRefSequence[$group] );
|
2019-11-29 22:24:51 +00:00
|
|
|
unset( $this->extendsCount[$group] );
|
2019-12-09 14:07:37 +00:00
|
|
|
return $refs;
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-27 10:08:00 +00:00
|
|
|
* Retruns true if the group exists and contains references.
|
2019-11-22 17:28:51 +00:00
|
|
|
*
|
|
|
|
* @param string $group
|
2020-01-09 10:50:32 +00:00
|
|
|
*
|
2019-11-22 17:28:51 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasGroup( string $group ) : bool {
|
2019-11-27 10:08:00 +00:00
|
|
|
return isset( $this->refs[$group] ) && $this->refs[$group];
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of all groups with references.
|
|
|
|
*
|
2019-11-27 15:31:17 +00:00
|
|
|
* @return string[]
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
|
|
|
public function getGroups() : array {
|
|
|
|
$groups = [];
|
|
|
|
foreach ( $this->refs as $group => $refs ) {
|
|
|
|
if ( $refs ) {
|
|
|
|
$groups[] = $group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all references for a group.
|
|
|
|
*
|
2019-12-21 01:25:58 +00:00
|
|
|
* @param string $group
|
2020-01-09 10:50:32 +00:00
|
|
|
*
|
2019-11-22 17:28:51 +00:00
|
|
|
* @return array[]
|
|
|
|
*/
|
2019-12-21 01:25:58 +00:00
|
|
|
public function getGroupRefs( string $group ) : array {
|
|
|
|
return $this->refs[$group] ?? [];
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $group
|
|
|
|
* @param string $name
|
2019-12-16 16:11:42 +00:00
|
|
|
* @param string $text
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-12-16 16:11:42 +00:00
|
|
|
public function appendText( string $group, string $name, string $text ) {
|
|
|
|
if ( isset( $this->refs[$group][$name]['text'] ) ) {
|
|
|
|
$this->refs[$group][$name]['text'] .= $text;
|
|
|
|
} else {
|
|
|
|
$this->refs[$group][$name]['text'] = $text;
|
|
|
|
}
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|