Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4138392
AbstractMapper.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
AbstractMapper.php
View Options
<?php
namespace
MediaWiki\Extension\Notifications\Mapper
;
use
InvalidArgumentException
;
use
MediaWiki\Extension\Notifications\DbFactory
;
/**
* Abstract mapper for model
*/
abstract
class
AbstractMapper
{
/**
* Echo database factory
* @var DbFactory
*/
protected
$dbFactory
;
/**
* Event listeners for method like insert/delete
* @var array[]
*/
protected
$listeners
;
public
function
__construct
(
?
DbFactory
$dbFactory
=
null
)
{
$this
->
dbFactory
=
$dbFactory
??
DbFactory
::
newFromDefault
();
}
/**
* Attach a listener
*
* @param string $method Method name
* @param string $key Identification of the callable
* @param callable $callable
*/
public
function
attachListener
(
$method
,
$key
,
$callable
)
{
if
(
!
method_exists
(
$this
,
$method
)
)
{
throw
new
InvalidArgumentException
(
$method
.
' does not exist in '
.
get_class
(
$this
)
);
}
if
(
!
isset
(
$this
->
listeners
[
$method
]
)
)
{
$this
->
listeners
[
$method
]
=
[];
}
$this
->
listeners
[
$method
][
$key
]
=
$callable
;
}
/**
* Detach a listener
*
* @param string $method Method name
* @param string $key identification of the callable
*/
public
function
detachListener
(
$method
,
$key
)
{
if
(
isset
(
$this
->
listeners
[
$method
]
)
)
{
unset
(
$this
->
listeners
[
$method
][
$key
]
);
}
}
/**
* Get the listener for a method
*
* @param string $method
* @return callable[]
*/
public
function
getMethodListeners
(
$method
)
{
if
(
!
method_exists
(
$this
,
$method
)
)
{
throw
new
InvalidArgumentException
(
$method
.
' does not exist in '
.
get_class
(
$this
)
);
}
return
$this
->
listeners
[
$method
]
??
[];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 14:38 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9b/86/0296bf7b2fd63cc1ed8f0855c04c
Default Alt Text
AbstractMapper.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment