gallery: Fix phan annotation for ImageGalleryBase::getImages
[mediawiki.git] / includes / deferred / MWCallableUpdate.php
blob8239d4f1eb4d718f4041e3af25f81f617c9dec45
1 <?php
3 namespace MediaWiki\Deferred;
5 use Closure;
6 use Wikimedia\Rdbms\IDatabase;
7 use Wikimedia\Rdbms\Platform\ISQLPlatform;
9 /**
10 * DeferrableUpdate for closure/callable
12 * @internal Use DeferredUpdates::addCallableUpdate instead
14 class MWCallableUpdate
15 implements DeferrableUpdate, DeferrableCallback, TransactionRoundAwareUpdate
17 /** @var callable|null Callback, or null if it was cancelled */
18 private $callback;
19 /** @var string Calling method name */
20 private $fname;
21 /** @var int One of the class TRX_ROUND_* constants */
22 private $trxRoundRequirement = self::TRX_ROUND_PRESENT;
24 /**
25 * @param callable $callback One of the following:
26 * - A Closure callback that takes the caller name as its argument
27 * - A non-Closure callback that takes no arguments
28 * @param string $fname Calling method @phan-mandatory-param
29 * @param IDatabase|IDatabase[] $dependeeDbws DB handles which might have pending writes
30 * upon which this update depends. If any of the handles already has an open transaction,
31 * a rollback thereof will cause this update to be cancelled (if it has not already run).
32 * [optional]
34 public function __construct(
35 callable $callback,
36 $fname = ISQLPlatform::CALLER_UNKNOWN,
37 $dependeeDbws = []
38 ) {
39 $this->callback = $callback;
40 $this->fname = $fname;
42 $dependeeDbws = is_array( $dependeeDbws ) ? $dependeeDbws : [ $dependeeDbws ];
43 foreach ( $dependeeDbws as $dbw ) {
44 if ( $dbw->trxLevel() ) {
45 $dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
50 public function doUpdate() {
51 if ( $this->callback instanceof Closure ) {
52 ( $this->callback )( $this->fname );
53 } elseif ( $this->callback ) {
54 // For backwards-compatibility with [$classOrObject, 'func'] style callbacks
55 // where the function happened to already take an optional parameter.
56 ( $this->callback )();
60 /**
61 * @internal This method is public so that it works with onTransactionResolution()
62 * @param int $trigger
64 public function cancelOnRollback( $trigger ) {
65 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
66 $this->callback = null;
70 public function getOrigin() {
71 return $this->fname;
74 /**
75 * @param int $mode One of the class TRX_ROUND_* constants
77 public function setTransactionRoundRequirement( $mode ) {
78 $this->trxRoundRequirement = $mode;
81 public function getTransactionRoundRequirement() {
82 return $this->trxRoundRequirement;
86 /** @deprecated class alias since 1.42 */
87 class_alias( MWCallableUpdate::class, 'MWCallableUpdate' );