Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace React\EventLoop\Timer;
4
 
5
use React\EventLoop\TimerInterface;
6
 
7
/**
8
 * The actual connection implementation for TimerInterface
9
 *
10
 * This class should only be used internally, see TimerInterface instead.
11
 *
12
 * @see TimerInterface
13
 * @internal
14
 */
15
final class Timer implements TimerInterface
16
{
17
    const MIN_INTERVAL = 0.000001;
18
 
19
    private $interval;
20
    private $callback;
21
    private $periodic;
22
 
23
    /**
24
     * Constructor initializes the fields of the Timer
25
     *
26
     * @param float         $interval The interval after which this timer will execute, in seconds
27
     * @param callable      $callback The callback that will be executed when this timer elapses
28
     * @param bool          $periodic Whether the time is periodic
29
     */
30
    public function __construct($interval, $callback, $periodic = false)
31
    {
32
        if ($interval < self::MIN_INTERVAL) {
33
            $interval = self::MIN_INTERVAL;
34
        }
35
 
36
        $this->interval = (float) $interval;
37
        $this->callback = $callback;
38
        $this->periodic = (bool) $periodic;
39
    }
40
 
41
    public function getInterval()
42
    {
43
        return $this->interval;
44
    }
45
 
46
    public function getCallback()
47
    {
48
        return $this->callback;
49
    }
50
 
51
    public function isPeriodic()
52
    {
53
        return $this->periodic;
54
    }
55
}