PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / crontab / runner / aware.php

aware.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/crontab/runner/aware.php

80 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Cron runner basic implementation.
16 *
17 * @since 1.7
18 */
19 class VBOCrontabRunnerAware implements VBOCrontabRunner
20 {
21 /** @var string */
22 protected $id;
23
24 /** @var int */
25 protected $interval;
26
27 /** @var callback */
28 protected $callback;
29
30 /**
31 * Class constructor.
32 *
33 * @param string $id The cron unique identifier.
34 * @param int $interval The execution interval in seconds (eg. 3600 to execute every hour).
35 * @param callable $callback The callback that will be invoked.
36 */
37 public function __construct(string $id, int $interval, $callback)
38 {
39 $this->id = $id;
40 $this->interval = abs($interval);
41 $this->callback = $callback;
42 }
43
44 /**
45 * @inheritDoc
46 */
47 final public function getID()
48 {
49 return $this->id;
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function canRun()
56 {
57 // always runnable
58 return true;
59 }
60
61 /**
62 * @inheritDoc
63 */
64 public function getNextExecution(DateTime $lastExecution)
65 {
66 $nextExecution = clone $lastExecution;
67 $nextExecution->modify('+' . $this->interval . ' seconds');
68 return $nextExecution;
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function execute(VBOCrontabLogger $logger)
75 {
76 // invoke the callback
77 call_user_func_array($this->callback, [$logger]);
78 }
79 }
80