MediaWiki
master
Toggle main menu visibility
PoolCounterWorkViaCallback.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\PoolCounter;
8
9
use InvalidArgumentException;
10
18
class
PoolCounterWorkViaCallback
extends
PoolCounterWork
{
20
protected
$doWork
;
22
protected
$doCachedWork
;
24
protected
$fallback
;
26
protected
$error
;
27
42
public
function
__construct
( $pool,
string
$key, array $callbacks ) {
43
if
( is_string( $pool ) ) {
44
$type
= $pool;
45
$pool =
null
;
46
}
else
{
47
$type
= $pool->getType();
48
}
49
50
parent::__construct(
$type
, $key, $pool );
51
52
foreach
( [
'doWork'
,
'doCachedWork'
,
'fallback'
,
'error'
] as $name ) {
53
if
( isset( $callbacks[$name] ) ) {
54
if
( !is_callable( $callbacks[$name] ) ) {
55
throw
new
InvalidArgumentException(
"Invalid callback provided for '$name' function."
);
56
}
57
$this->$name = $callbacks[$name];
58
}
59
}
60
if
( !$this->
doWork
) {
61
throw
new
InvalidArgumentException(
"No callback provided for 'doWork' function."
);
62
}
63
$this->cacheable = (bool)$this->doCachedWork;
64
}
65
67
public
function
doWork
() {
68
return
( $this->
doWork
)();
69
}
70
72
public
function
getCachedWork
() {
73
if
( $this->doCachedWork ) {
74
return
( $this->doCachedWork )();
75
}
76
return
false
;
77
}
78
80
public
function
fallback
( $fast ) {
81
if
( $this->
fallback
) {
82
return
( $this->
fallback
)( $fast );
83
}
84
return
false
;
85
}
86
88
public
function
error
( $status ) {
89
if
( $this->
error
) {
90
return
( $this->
error
)( $status );
91
}
92
return
false
;
93
}
94
}
95
97
class_alias( PoolCounterWorkViaCallback::class,
'PoolCounterWorkViaCallback'
);
MediaWiki\PoolCounter\PoolCounterWorkViaCallback
Convenience class for dealing with PoolCounter using callbacks.
Definition
PoolCounterWorkViaCallback.php:18
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\$fallback
callable null $fallback
Definition
PoolCounterWorkViaCallback.php:24
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\doWork
doWork()
Actually perform the work, caching it if needed.mixed|false Work result or false
Definition
PoolCounterWorkViaCallback.php:67
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\$doWork
callable null $doWork
Definition
PoolCounterWorkViaCallback.php:20
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\error
error( $status)
Do something with the error, like showing it to the user.mixed|false
Definition
PoolCounterWorkViaCallback.php:88
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\getCachedWork
getCachedWork()
Retrieve the work from cache.mixed|false Work result or false
Definition
PoolCounterWorkViaCallback.php:72
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\$error
callable null $error
Definition
PoolCounterWorkViaCallback.php:26
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\fallback
fallback( $fast)
A work not so good (eg.expired one) but better than an error message.mixed|false Work result or false
Definition
PoolCounterWorkViaCallback.php:80
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\__construct
__construct( $pool, string $key, array $callbacks)
Build a PoolCounterWork class from a type, key, and callback map.
Definition
PoolCounterWorkViaCallback.php:42
MediaWiki\PoolCounter\PoolCounterWorkViaCallback\$doCachedWork
callable null $doCachedWork
Definition
PoolCounterWorkViaCallback.php:22
MediaWiki\PoolCounter\PoolCounterWork
Class for dealing with PoolCounters using class members.
Definition
PoolCounterWork.php:16
MediaWiki\PoolCounter\PoolCounterWork\$type
string $type
Definition
PoolCounterWork.php:18
includes
PoolCounter
PoolCounterWorkViaCallback.php
Generated on
for MediaWiki by
1.18.0