PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.2
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / WP_CLI / ProgressBar.php

ProgressBar.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.2, at app/Services/Libraries/action-scheduler/classes/WP_CLI/ProgressBar.php

141 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Third-party library (Action Scheduler)
3
4 namespace Action_Scheduler\WP_CLI;
5
6 /**
7 * WP_CLI progress bar for Action Scheduler.
8 */
9
10 /**
11 * Class ProgressBar
12 *
13 * @package Action_Scheduler\WP_CLI
14 *
15 * @since 3.0.0
16 *
17 * @codeCoverageIgnore
18 */
19 class ProgressBar {
20
21 /**
22 * Current number of ticks.
23 *
24 * @var integer
25 */
26 protected $total_ticks;
27
28 /**
29 * Total number of ticks.
30 *
31 * @var integer
32 */
33 protected $count;
34
35 /**
36 * Progress bar update interval.
37 *
38 * @var integer
39 */
40 protected $interval;
41
42 /**
43 * Progress bar message.
44 *
45 * @var string
46 */
47 protected $message;
48
49 /**
50 * Instance.
51 *
52 * @var \cli\progress\Bar
53 */
54 protected $progress_bar;
55
56 /**
57 * ProgressBar constructor.
58 *
59 * @param string $message Text to display before the progress bar.
60 * @param integer $count Total number of ticks to be performed.
61 * @param integer $interval Optional. The interval in milliseconds between updates. Default 100.
62 *
63 * @throws \Exception When this is not run within WP CLI.
64 */
65 public function __construct( $message, $count, $interval = 100 ) {
66 if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
67 /* translators: %s php class name */
68 throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) );
69 }
70
71 $this->total_ticks = 0;
72 $this->message = $message;
73 $this->count = $count;
74 $this->interval = $interval;
75 }
76
77 /**
78 * Increment the progress bar ticks.
79 */
80 public function tick() {
81 if ( null === $this->progress_bar ) {
82 $this->setup_progress_bar();
83 }
84
85 $this->progress_bar->tick();
86 $this->total_ticks++;
87
88 do_action( 'action_scheduler/progress_tick', $this->total_ticks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
89 }
90
91 /**
92 * Get the progress bar tick count.
93 *
94 * @return int
95 */
96 public function current() {
97 return $this->progress_bar ? $this->progress_bar->current() : 0;
98 }
99
100 /**
101 * Finish the current progress bar.
102 */
103 public function finish() {
104 if ( null !== $this->progress_bar ) {
105 $this->progress_bar->finish();
106 }
107
108 $this->progress_bar = null;
109 }
110
111 /**
112 * Set the message used when creating the progress bar.
113 *
114 * @param string $message The message to be used when the next progress bar is created.
115 */
116 public function set_message( $message ) {
117 $this->message = $message;
118 }
119
120 /**
121 * Set the count for a new progress bar.
122 *
123 * @param integer $count The total number of ticks expected to complete.
124 */
125 public function set_count( $count ) {
126 $this->count = $count;
127 $this->finish();
128 }
129
130 /**
131 * Set up the progress bar.
132 */
133 protected function setup_progress_bar() {
134 $this->progress_bar = \WP_CLI\Utils\make_progress_bar(
135 $this->message,
136 $this->count,
137 $this->interval
138 );
139 }
140 }
141