Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F8322049
SharedBag.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
974 B
Referenced Files
None
Subscribers
None
SharedBag.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Collections
;
/**
* A shared bag is a collection of key and values, which implements
* a monostate pattern, i.e. there is only one bag, which can be accessed
* though an arbitrary amount of SharedBag instances.
*
* The SharedBag class can be used as:
* — shared context, to contain the application configuration
* — service locator, to contain application dependencies
* — a migration path to store global variables of a legacy application
* pending the migration to a collection sharing the same interface
*
* Such patterns can be discouraged and as such used with architectural care,
* as they mainly use SharedBag as global variables, or as an antipattern.
*/
class
SharedBag
{
private
static
?
HashMap
$bag
=
null
;
public
function
getBag
()
:
HashMap
{
if
(
self
::
$bag
===
null
)
{
self
::
$bag
=
new
HashMap
;
}
return
self
::
$bag
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 13, 16:58 (12 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2542224
Default Alt Text
SharedBag.php (974 B)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment