|
| static | jsonEncode ( $o) |
| | FIXME: Core has FormatJson::encode that does a more comprehensive job.
|
| |
| static | jsonDecode (string $str, bool $assoc=true) |
| | FIXME: Core has FormatJson::parse that does a more comprehensive job json_decode wrapper function.
|
| |
| static | makeSet (array $a) |
| | Convert array to associative array usable as a read-only Set.
|
| |
| static | lastItem (array $a) |
| | Helper to get last item of the array.
|
| |
| static | pushArray (array &$dest, array ... $sources) |
| | Append an array to an accumulator using the most efficient method available.
|
| |
| static | safeSubstr (string $s, int $start, ?int $length=null, bool $checkEntireString=false) |
| | Return a substring, asserting that it is valid UTF-8.
|
| |
| static | assertValidUTF8 (string $s) |
| | Helper for verifying a valid UTF-8 encoding.
|
| |
| static | reStrip (string $re, ?string $newDelimiter=null) |
| | Helper for joining pieces of regular expressions together.
|
| |
| static | encodeURIComponent (string $str) |
| | JS-compatible encodeURIComponent function FIXME: See T221147 (for a post-port update)
|
| |
| static | sortArray (&$array) |
| | Sort keys in an array, recursively, for better reproducibility.
|
| |
| static | arrayEquals (?array $arrA, ?array $arrB, callable $elementEquals) |
| | Compare the contents of two arrays for equality, given a equality comparison function for elements of the array.
|
| |
| static | iterable_to_array (iterable $iterable) |
| | Convert an iterable to an array.
|
| |
| static | stripPrefix ( $subject, $prefix) |
| | If a string starts with a given prefix, remove the prefix.
|
| |
| static | stripSuffix ( $subject, $suffix) |
| | If a string ends with a given suffix, remove the suffix.
|
| |
| static | deprecated (string $function, string $version, int $callerOffset=2) |
| | Logs a warning that a deprecated feature was used.
|
| |
| static | filterDeprecationForTest (string $regex) |
| | Deprecation messages matching the supplied regex will be suppressed.
|
| |
|
static | clearDeprecationFilters () |
| | Clear all deprecation filters.
|
| |
This file contains Parsoid-independent PHP helper functions.
Over time, more functions can be migrated out of various other files here.
| static Wikimedia\Parsoid\Utils\PHPUtils::arrayEquals |
( |
?array | $arrA, |
|
|
?array | $arrB, |
|
|
callable | $elementEquals ) |
|
static |
Compare the contents of two arrays for equality, given a equality comparison function for elements of the array.
Arrays are equal if they have the same size and element values for equal keys are equal.
For convenience, null can be passed in as well, and the function only returns true if the other argument is also null. This avoids null checks in the caller in many cases.
- Parameters
-
| ?array | $arrA | |
| ?array | $arrB | |
| callable(mixed,mixed):bool | $elementEquals A function to compare non-null elements of $arrA and $arrB for equality. |
- Returns
- bool True if $arrA and $arrB are equal.
| static Wikimedia\Parsoid\Utils\PHPUtils::safeSubstr |
( |
string | $s, |
|
|
int | $start, |
|
|
?int | $length = null, |
|
|
bool | $checkEntireString = false ) |
|
static |
Return a substring, asserting that it is valid UTF-8.
By default we assume the full string was valid UTF-8, which allows us to look at the first and last bytes to make this check. You can check the entire string if you are feeling paranoid; it will take O(N) time (where N is the length of the substring) but so does the substring operation.
If the substring would start beyond the end of the string or end before the start of the string, then this function will return the empty string (as would JavaScript); note that the native substr would return false in this case.
Using this helper instead of native substr is useful during the PHP port to verify that we don't break up Unicode codepoints by the switch from JavaScript UCS-2 offsets to PHP UTF-8 byte offsets.
- Parameters
-
| string | $s | The (sub)string to check |
| int | $start | The starting offset (in bytes). If negative, the offset is counted from the end of the string. |
| ?int | $length | (optional) The maximum length of the returned string. If negative, the end position is counted from the end of the string. |
| bool | $checkEntireString | Whether to do a slower verification of the entire string, not just the edges. Defaults to false. |
- Returns
- string The checked substring
| static Wikimedia\Parsoid\Utils\PHPUtils::stripPrefix |
( |
| $subject, |
|
|
| $prefix ) |
|
static |
If a string starts with a given prefix, remove the prefix.
Otherwise, return the original string. Like preg_replace( "/^$prefix/", '', $subject ) except about 1.14x faster in the replacement case and 2x faster in the no-op case.
Note: adding type declarations to the parameters adds an overhead of 3%. The benchmark above was without type declarations.
- Parameters
-
| string | $subject | |
| string | $prefix | |
- Returns
- string