9use InvalidArgumentException;
42 public function __construct( $pool,
string $key, array $callbacks ) {
43 if ( is_string( $pool ) ) {
47 $type = $pool->getType();
50 parent::__construct(
$type, $key, $pool );
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." );
57 $this->$name = $callbacks[$name];
61 throw new InvalidArgumentException(
"No callback provided for 'doWork' function." );
63 $this->cacheable = (bool)$this->doCachedWork;
68 return ( $this->
doWork )();
73 if ( $this->doCachedWork ) {
74 return ( $this->doCachedWork )();
88 public function error( $status ) {
90 return ( $this->
error )( $status );
97class_alias( PoolCounterWorkViaCallback::class,
'PoolCounterWorkViaCallback' );