Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6001209
NormalizedExceptionTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
NormalizedExceptionTrait.php
View Options
<?php
namespace
Wikimedia\NormalizedException
;
/**
* Trait for creating a normalized exception
*/
trait
NormalizedExceptionTrait
{
/** @var string */
protected
$normalizedMessage
;
/** @var (int|float|string|bool)[] */
protected
$messageContext
;
/**
* Turn a PSR-3 style normalized message and context into a real message,
* by interpolating the context variables into the message string.
*
* Intended for use in exception constructors to construct the message
* that's passed to the parent constructor.
*
* @stable to call
* @param string $normalizedMessage A message string with zero or more
* {}-wrapped tokens in it.
* @param array $context An array mapping tokens (without the braces) to
* values. Fields not used in the message are allowed. Values that are
* used in the message should be scalars or have a __toString() method.
* @return string
*/
public
static
function
getMessageFromNormalizedMessage
(
string
$normalizedMessage
,
array
$context
)
{
$replacements
=
[];
foreach
(
$context
as
$placeholder
=>
$value
)
{
if
(
is_bool
(
$value
)
)
{
$stringValue
=
$value
?
'<true>'
:
'<false>'
;
}
elseif
(
$value
===
null
)
{
$stringValue
=
'<null>'
;
}
else
{
$stringValue
=
(
string
)
$value
;
}
$replacements
[
'{'
.
$placeholder
.
'}'
]
=
$stringValue
;
}
return
strtr
(
$normalizedMessage
,
$replacements
);
}
/** @inheritDoc */
public
function
getNormalizedMessage
():
string
{
return
$this
->
normalizedMessage
;
}
/** @inheritDoc */
public
function
getMessageContext
():
array
{
return
$this
->
messageContext
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 4 2026, 06:17 (5 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a2/59/790c4d54f2a327f63d89186955ca
Default Alt Text
NormalizedExceptionTrait.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment