Deferred::prime()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Deferred
5
 *
6
 * Run callback when script execution is stopped.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2016 - http://caffeina.com
11
 */
12
13
class Deferred {
14
15
	protected $callback,
16
            $enabled = true;
17
18
	public function __construct( callable $callback ) {
19
		$this->callback = $callback;
20
	}
21
22
  public function disarm() {
23
    $this->enabled = false;
24
  }
25
26
  public function prime() {
27
    $this->enabled = true;
28
  }
29
30
	public function __destruct() {
31
		if ( $this->enabled ) call_user_func( $this->callback );
32
	}
33
34
}