Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4087250
TranslatableBundleState.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
TranslatableBundleState.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageGroupProcessing
;
use
InvalidArgumentException
;
use
JsonSerializable
;
/**
* Stores and validates possible translation states for translatable bundles
* @author Abijeet Patro
* @since 2024.07
* @license GPL-2.0-or-later
*/
final
class
TranslatableBundleState
implements
JsonSerializable
{
public
const
UNSTABLE
=
0
;
public
const
PROPOSE
=
1
;
public
const
IGNORE
=
2
;
private
const
STATE_MAP
=
[
'unstable'
=>
self
::
UNSTABLE
,
'proposed'
=>
self
::
PROPOSE
,
'ignored'
=>
self
::
IGNORE
,
];
private
int
$state
;
public
function
__construct
(
int
$state
)
{
if
(
!
in_array
(
$state
,
self
::
STATE_MAP
)
)
{
throw
new
InvalidArgumentException
(
"Invalid translatable bundle state: $state"
);
}
$this
->
state
=
$state
;
}
public
static
function
newFromText
(
string
$stateName
):
self
{
$state
=
self
::
STATE_MAP
[
$stateName
]
??
null
;
if
(
$state
===
null
)
{
throw
new
InvalidArgumentException
(
"Invalid translatable bundle state: $stateName"
);
}
return
new
TranslatableBundleState
(
$state
);
}
public
function
getStateId
():
int
{
return
$this
->
state
;
}
public
function
getStateText
():
string
{
return
array_flip
(
self
::
STATE_MAP
)[
$this
->
state
];
}
public
function
jsonSerialize
():
array
{
return
[
'stateId'
=>
$this
->
state
];
}
public
static
function
fromJson
(
string
$json
):
self
{
$parsedJson
=
json_decode
(
$json
,
true
);
if
(
!
is_array
(
$parsedJson
)
)
{
throw
new
InvalidArgumentException
(
"Unexpected JSON value '$json'"
);
}
$stateId
=
$parsedJson
[
'stateId'
]
??
null
;
if
(
$stateId
===
null
)
{
throw
new
InvalidArgumentException
(
'Provided JSON is missing required field stateId'
);
}
return
new
TranslatableBundleState
(
(
int
)
$stateId
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 09:28 (6 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
33/f4/eb89b9ac07311fab0249d089a70f
Default Alt Text
TranslatableBundleState.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment