X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fpoolcounter%2FPoolCounterWork.php;h=e61b65ad72e5f18cef8b54164929574b0f1fa316;hb=601519ee36462faabacf4547c9aefaf7e8726476;hp=1bc1a8b12226c13da4db4e4517c15e1e8780f892;hpb=3b658a2dd3339dce93ad74984eb0120f6c50ccd9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/poolcounter/PoolCounterWork.php b/includes/poolcounter/PoolCounterWork.php index 1bc1a8b122..e61b65ad72 100644 --- a/includes/poolcounter/PoolCounterWork.php +++ b/includes/poolcounter/PoolCounterWork.php @@ -64,6 +64,9 @@ abstract class PoolCounterWork { /** * Do something with the error, like showing it to the user. + * + * @param Status $status + * * @return bool */ public function error( $status ) { @@ -143,9 +146,9 @@ abstract class PoolCounterWork { /* These two cases should never be hit... */ case PoolCounter::ERROR: default: - $errors = array( + $errors = [ PoolCounter::QUEUE_FULL => 'pool-queuefull', - PoolCounter::TIMEOUT => 'pool-timeout' ); + PoolCounter::TIMEOUT => 'pool-timeout' ]; $status = Status::newFatal( isset( $errors[$status->value] ) ? $errors[$status->value] @@ -155,73 +158,3 @@ abstract class PoolCounterWork { } } } - -/** - * Convenience class for dealing with PoolCounters using callbacks - * @since 1.22 - */ -class PoolCounterWorkViaCallback extends PoolCounterWork { - /** @var callable */ - protected $doWork; - /** @var callable|null */ - protected $doCachedWork; - /** @var callable|null */ - protected $fallback; - /** @var callable|null */ - protected $error; - - /** - * Build a PoolCounterWork class from a type, key, and callback map. - * - * The callback map must at least have a callback for the 'doWork' method. - * Additionally, callbacks can be provided for the 'doCachedWork', 'fallback', - * and 'error' methods. Methods without callbacks will be no-ops that return false. - * If a 'doCachedWork' callback is provided, then execute() may wait for any prior - * process in the pool to finish and reuse its cached result. - * - * @param string $type - * @param string $key - * @param array $callbacks Map of callbacks - * @throws MWException - */ - public function __construct( $type, $key, array $callbacks ) { - parent::__construct( $type, $key ); - foreach ( array( 'doWork', 'doCachedWork', 'fallback', 'error' ) as $name ) { - if ( isset( $callbacks[$name] ) ) { - if ( !is_callable( $callbacks[$name] ) ) { - throw new MWException( "Invalid callback provided for '$name' function." ); - } - $this->$name = $callbacks[$name]; - } - } - if ( !isset( $this->doWork ) ) { - throw new MWException( "No callback provided for 'doWork' function." ); - } - $this->cacheable = isset( $this->doCachedWork ); - } - - public function doWork() { - return call_user_func_array( $this->doWork, array() ); - } - - public function getCachedWork() { - if ( $this->doCachedWork ) { - return call_user_func_array( $this->doCachedWork, array() ); - } - return false; - } - - public function fallback() { - if ( $this->fallback ) { - return call_user_func_array( $this->fallback, array() ); - } - return false; - } - - public function error( $status ) { - if ( $this->error ) { - return call_user_func_array( $this->error, array( $status ) ); - } - return false; - } -}