Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4106424
ManagedObjectFactory.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
ManagedObjectFactory.php
View Options
<?php
namespace
MediaWiki\Tests\Json
;
use
Wikimedia\JsonCodec\JsonClassCodec
;
/**
* Managed object factory which also handles serialization/deserialization
* of the objects it manages.
*
* @implements JsonClassCodec<ManagedObject>
*/
class
ManagedObjectFactory
implements
JsonClassCodec
{
/** @var array<string,ManagedObject> Fake database */
private
$storage
=
[];
/**
* Create and store an object with $name and $value in the database.
* @param string $name
* @param int $value
* @return ManagedObject
*/
public
function
create
(
string
$name
,
int
$value
)
{
if
(
isset
(
$this
->
storage
[
$name
]
)
)
{
throw
new
\Error
(
"duplicate name"
);
}
$this
->
storage
[
$name
]
=
$o
=
new
ManagedObject
(
$name
,
$value
);
return
$o
;
}
/**
* Lookup $name in the database.
* @param string $name
* @return ManagedObject
*/
public
function
lookup
(
string
$name
):
ManagedObject
{
if
(
!
isset
(
$this
->
storage
[
$name
]
)
)
{
throw
new
\Error
(
"not found"
);
}
return
$this
->
storage
[
$name
];
}
/** @inheritDoc */
public
function
toJsonArray
(
$obj
):
array
{
'@phan-var ManagedObject $obj'
;
// Not necessary to serialize all the properties, since they
// will be reloaded from the "database" during deserialization
return
[
'name'
=>
$obj
->
name
];
}
/** @inheritDoc */
public
function
newFromJsonArray
(
string
$className
,
array
$json
):
ManagedObject
{
// @phan-suppress-next-line PhanTypeMismatchReturn template limitations
return
$this
->
lookup
(
$json
[
'name'
]
);
}
/** @inheritDoc */
public
function
jsonClassHintFor
(
string
$className
,
string
$key
):
?
string
{
// no hints
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:32 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2e/08/e8ab8094e46c55eee93dc45baece
Default Alt Text
ManagedObjectFactory.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment