FindReplaceWidget
in package
implements
FindReplaceInterface
A base class for widget doomtools.
Widgets behave the same and use the same boiler code. Override these bits:
- getWidgetType()
- getWidgetText()
- setWidgetText()
Tags
Table of Contents
Interfaces
- FindReplaceInterface
- This is a base class for find-replace behaviours, aka. the doomtool.
Methods
- find() : iterable<string|int, array<string|int, mixed>>
- Find all occurrences of the the given string patterns.
- getName() : string
- The friendly name for this doomtool shown in the dbtools.
- getWidgetType() : string
- Get the widget type this replacer is for.
- key() : string
- The unique key for this doomtool.
- replace() : int
- Find and replace all occurrences of the given string patterns.
- findInWidget() : null|array<string|int, mixed>
- Find the text in a widget.
- getWidgetText() : string
- Get the widget text for replacing.
- replaceInWidget() : bool
- Replace the text in a widget.
- setWidgetText() : void
- Set the widget text after replacing.
Methods
find()
Find all occurrences of the the given string patterns.
public
find(array<string|int, mixed> $finds, array<string|int, mixed> $settings) : iterable<string|int, array<string|int, mixed>>
Parameters
- $finds : array<string|int, mixed>
-
regex patterns
- $settings : array<string|int, mixed>
-
[ ignore_case ]
Tags
Return values
iterable<string|int, array<string|int, mixed>> —[ id, key, text, url, indexes, count ]
getName()
The friendly name for this doomtool shown in the dbtools.
public
getName() : string
Tags
Return values
stringgetWidgetType()
Get the widget type this replacer is for.
public
abstract static getWidgetType() : string
This should match the 'type' field in the page_widgets table.
Tags
Return values
stringkey()
The unique key for this doomtool.
public
key() : string
Tags
Return values
stringreplace()
Find and replace all occurrences of the given string patterns.
public
replace(array<string|int, mixed> $replaces, array<string|int, mixed> $settings) : int
Parameters
- $replaces : array<string|int, mixed>
-
[ find => replace ] regex + replacements
- $settings : array<string|int, mixed>
-
[ ignore_case ]
Tags
Return values
int —number of replacements
findInWidget()
Find the text in a widget.
protected
findInWidget(array<string|int, mixed> $row, array<string|int, string> $finds, array<string|int, mixed> $settings) : null|array<string|int, mixed>
Null results are not included in by find().
Parameters
- $row : array<string|int, mixed>
-
page_widgets db row + page id, revision id, status
- $finds : array<string|int, string>
- $settings : array<string|int, mixed>
Return values
null|array<string|int, mixed> —result set, see find() - or null if not found
getWidgetText()
Get the widget text for replacing.
protected
abstract getWidgetText(array<string|int, mixed> $row) : string
Often this is a field within the 'settings' JSON blob.
Parameters
- $row : array<string|int, mixed>
Return values
stringreplaceInWidget()
Replace the text in a widget.
protected
replaceInWidget(int $id, string $text) : bool
Parameters
- $id : int
- $text : string
Return values
boolsetWidgetText()
Set the widget text after replacing.
protected
abstract setWidgetText(array<string|int, mixed> &$row, string $text) : void
This should match the behaviour from getWidgetText().
Parameters
- $row : array<string|int, mixed>
-
db row
page_widgets - $text : string