mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 09:40:41 +00:00
c1c3c7b672
There are about 200 of such generic "array" type hints in this code base, the majority in @param tags. I started with what I found most relevant: @var and @return tags. I might continue working on this later, but wanted to stop for now to keep this patch moderately small. Change-Id: Iff0d9590a794ae0f885466ef6bb336b0b42a6cd3
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Abstract mapper for model
|
|
*/
|
|
abstract class EchoAbstractMapper {
|
|
|
|
/**
|
|
* Echo database factory
|
|
* @var MWEchoDbFactory
|
|
*/
|
|
protected $dbFactory;
|
|
|
|
/**
|
|
* Event listeners for method like insert/delete
|
|
* @var array[]
|
|
*/
|
|
protected $listeners;
|
|
|
|
/**
|
|
* @param MWEchoDbFactory|null $dbFactory
|
|
*/
|
|
public function __construct( MWEchoDbFactory $dbFactory = null ) {
|
|
if ( $dbFactory === null ) {
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
|
}
|
|
$this->dbFactory = $dbFactory;
|
|
}
|
|
|
|
/**
|
|
* Attach a listener
|
|
*
|
|
* @param string $method Method name
|
|
* @param string $key Identification of the callable
|
|
* @param callable $callable
|
|
* @throws MWException
|
|
*/
|
|
public function attachListener( $method, $key, $callable ) {
|
|
if ( !method_exists( $this, $method ) ) {
|
|
throw new MWException( $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[]
|
|
* @throws MWException
|
|
*/
|
|
public function getMethodListeners( $method ) {
|
|
if ( !method_exists( $this, $method ) ) {
|
|
throw new MWException( $method . ' does not exist in ' . get_class( $this ) );
|
|
}
|
|
if ( isset( $this->listeners[$method] ) ) {
|
|
return $this->listeners[$method];
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
}
|