WrappedString
Automatically compact sequentially-outputted strings that share a common prefix / suffix pair.
Loading...
Searching...
No Matches
Wikimedia\WrappedString Class Reference

Public Member Functions

 __construct ( $value, $prefix=null, $suffix=null)
 
 __toString ()
 

Static Public Member Functions

static compact (array $wraps)
 Merge consecutive WrappedString objects with the same prefix and suffix.
 
static join ( $sep, array $wraps)
 Join several wrapped strings with a separator between each.
 

Protected Member Functions

 extend ( $value)
 

Protected Attributes

 $value
 
 $prefix
 
 $suffix
 

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\WrappedString::__construct ( $value,
$prefix = null,
$suffix = null )
Parameters
string$value
string | null$prefix
string | null$suffix

Member Function Documentation

◆ __toString()

Wikimedia\WrappedString::__toString ( )
Returns
string

◆ compact()

static Wikimedia\WrappedString::compact ( array $wraps)
static

Merge consecutive WrappedString objects with the same prefix and suffix.

Does not modify the array or the WrappedString objects.

NOTE: This is an internal method. Use join() or WrappedStringList instead.

Parameters
array<string|WrappedString|WrappedStringList>$wraps
Returns
array<string|WrappedString|WrappedStringList> Compacted list to be treated as strings

◆ extend()

Wikimedia\WrappedString::extend ( $value)
protected
Parameters
string$valueValue of a WrappedString with the same prefix and suffix
Returns
WrappedString Newly wrapped string

◆ join()

static Wikimedia\WrappedString::join ( $sep,
array $wraps )
static

Join several wrapped strings with a separator between each.

This method is compatible with native PHP implode(). The actual join operation is deferred to WrappedStringList::__toString(). This allows callers to collect multiple lists and compact them together.

Parameters
string$sep
(string|WrappedString|WrappedStringList)[]$wraps
Returns
WrappedStringList

The documentation for this class was generated from the following file: