← All changes
|
vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler.php
+79
-21
1.0.2
→
trunk
View file →
| @@ -4,40 +4,75 @@ | ||
| 4 | 4 | use Action_Scheduler\Migration\Controller; |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Class ActionScheduler |
| 8 | + * | |
| 8 | 9 | * @codeCoverageIgnore |
| 9 | 10 | */ |
| 10 | 11 | abstract class ActionScheduler { |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Plugin file path. | |
| 15 | + * | |
| 16 | + * @var string | |
| 17 | + */ | |
| 11 | 18 | private static $plugin_file = ''; |
| 12 | - /** @var ActionScheduler_ActionFactory */ | |
| 13 | - private static $factory = NULL; | |
| 14 | - /** @var bool */ | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * ActionScheduler_ActionFactory instance. | |
| 22 | + * | |
| 23 | + * @var ActionScheduler_ActionFactory | |
| 24 | + */ | |
| 25 | + private static $factory = null; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Data store is initialized. | |
| 29 | + * | |
| 30 | + * @var bool | |
| 31 | + */ | |
| 15 | 32 | private static $data_store_initialized = false; |
| 16 | 33 | |
| 34 | + /** | |
| 35 | + * Factory. | |
| 36 | + */ | |
| 17 | 37 | public static function factory() { |
| 18 | - if ( !isset(self::$factory) ) { | |
| 38 | + if ( ! isset( self::$factory ) ) { | |
| 19 | 39 | self::$factory = new ActionScheduler_ActionFactory(); |
| 20 | 40 | } |
| 21 | 41 | return self::$factory; |
| 22 | 42 | } |
| 23 | 43 | |
| 44 | + /** | |
| 45 | + * Get Store instance. | |
| 46 | + */ | |
| 24 | 47 | public static function store() { |
| 25 | 48 | return ActionScheduler_Store::instance(); |
| 26 | 49 | } |
| 27 | 50 | |
| 51 | + /** | |
| 52 | + * Get Lock instance. | |
| 53 | + */ | |
| 28 | 54 | public static function lock() { |
| 29 | 55 | return ActionScheduler_Lock::instance(); |
| 30 | 56 | } |
| 31 | 57 | |
| 58 | + /** | |
| 59 | + * Get Logger instance. | |
| 60 | + */ | |
| 32 | 61 | public static function logger() { |
| 33 | 62 | return ActionScheduler_Logger::instance(); |
| 34 | 63 | } |
| 35 | 64 | |
| 65 | + /** | |
| 66 | + * Get QueueRunner instance. | |
| 67 | + */ | |
| 36 | 68 | public static function runner() { |
| 37 | 69 | return ActionScheduler_QueueRunner::instance(); |
| 38 | 70 | } |
| 39 | 71 | |
| 72 | + /** | |
| 73 | + * Get AdminView instance. | |
| 74 | + */ | |
| 40 | 75 | public static function admin_view() { |
| 41 | 76 | return ActionScheduler_AdminView::instance(); |
| 42 | 77 | } |
| 43 | 78 | |
| @@ -42,31 +77,38 @@ | ||
| 42 | 77 | } |
| 43 | 78 | |
| 44 | 79 | /** |
| 45 | 80 | * Get the absolute system path to the plugin directory, or a file therein |
| 81 | + * | |
| 46 | 82 | * @static |
| 47 | - * @param string $path | |
| 83 | + * @param string $path Path relative to plugin directory. | |
| 48 | 84 | * @return string |
| 49 | 85 | */ |
| 50 | 86 | public static function plugin_path( $path ) { |
| 51 | - $base = dirname(self::$plugin_file); | |
| 87 | + $base = dirname( self::$plugin_file ); | |
| 52 | 88 | if ( $path ) { |
| 53 | - return trailingslashit($base).$path; | |
| 89 | + return trailingslashit( $base ) . $path; | |
| 54 | 90 | } else { |
| 55 | - return untrailingslashit($base); | |
| 91 | + return untrailingslashit( $base ); | |
| 56 | 92 | } |
| 57 | 93 | } |
| 58 | 94 | |
| 59 | 95 | /** |
| 60 | 96 | * Get the absolute URL to the plugin directory, or a file therein |
| 97 | + * | |
| 61 | 98 | * @static |
| 62 | - * @param string $path | |
| 99 | + * @param string $path Path relative to plugin directory. | |
| 63 | 100 | * @return string |
| 64 | 101 | */ |
| 65 | 102 | public static function plugin_url( $path ) { |
| 66 | - return plugins_url($path, self::$plugin_file); | |
| 103 | + return plugins_url( $path, self::$plugin_file ); | |
| 67 | 104 | } |
| 68 | 105 | |
| 106 | + /** | |
| 107 | + * Autoload. | |
| 108 | + * | |
| 109 | + * @param string $class Class name. | |
| 110 | + */ | |
| 69 | 111 | public static function autoload( $class ) { |
| 70 | 112 | $d = DIRECTORY_SEPARATOR; |
| 71 | 113 | $classes_dir = self::plugin_path( 'classes' . $d ); |
| 72 | 114 | $separator = strrpos( $class, '\\' ); |
| @@ -90,9 +132,9 @@ | ||
| 90 | 132 | } elseif ( 'Schema' === substr( $class, -6 ) ) { |
| 91 | 133 | $dir = $classes_dir . 'schema' . $d; |
| 92 | 134 | } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) { |
| 93 | 135 | $segments = explode( '_', $class ); |
| 94 | - $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : ''; | |
| 136 | + $type = isset( $segments[1] ) ? $segments[1] : ''; | |
| 95 | 137 | |
| 96 | 138 | switch ( $type ) { |
| 97 | 139 | case 'WPCLI': |
| 98 | 140 | $dir = $classes_dir . 'WP_CLI' . $d; |
| @@ -118,9 +160,9 @@ | ||
| 118 | 160 | return; |
| 119 | 161 | } |
| 120 | 162 | |
| 121 | 163 | if ( file_exists( $dir . "{$class}.php" ) ) { |
| 122 | - include( $dir . "{$class}.php" ); | |
| 164 | + include $dir . "{$class}.php"; | |
| 123 | 165 | return; |
| 124 | 166 | } |
| 125 | 167 | } |
| 126 | 168 | |
| @@ -127,9 +169,9 @@ | ||
| 127 | 169 | /** |
| 128 | 170 | * Initialize the plugin |
| 129 | 171 | * |
| 130 | 172 | * @static |
| 131 | - * @param string $plugin_file | |
| 173 | + * @param string $plugin_file Plugin file path. | |
| 132 | 174 | */ |
| 133 | 175 | public static function init( $plugin_file ) { |
| 134 | 176 | self::$plugin_file = $plugin_file; |
| 135 | 177 | spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| @@ -138,9 +180,9 @@ | ||
| 138 | 180 | * Fires in the early stages of Action Scheduler init hook. |
| 139 | 181 | */ |
| 140 | 182 | do_action( 'action_scheduler_pre_init' ); |
| 141 | 183 | |
| 142 | - require_once( self::plugin_path( 'functions.php' ) ); | |
| 184 | + require_once self::plugin_path( 'functions.php' ); | |
| 143 | 185 | ActionScheduler_DataController::init(); |
| 144 | 186 | |
| 145 | 187 | $store = self::store(); |
| 146 | 188 | $logger = self::logger(); |
| @@ -148,9 +190,10 @@ | ||
| 148 | 190 | $admin_view = self::admin_view(); |
| 149 | 191 | |
| 150 | 192 | // Ensure initialization on plugin activation. |
| 151 | 193 | if ( ! did_action( 'init' ) ) { |
| 152 | - add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init() | |
| 194 | + // phpcs:ignore Squiz.PHP.CommentedOutCode | |
| 195 | + add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init(). | |
| 153 | 196 | add_action( 'init', array( $store, 'init' ), 1, 0 ); |
| 154 | 197 | add_action( 'init', array( $logger, 'init' ), 1, 0 ); |
| 155 | 198 | add_action( 'init', array( $runner, 'init' ), 1, 0 ); |
| 156 | 199 | |
| @@ -190,9 +233,9 @@ | ||
| 190 | 233 | do_action( 'action_scheduler_init' ); |
| 191 | 234 | } |
| 192 | 235 | |
| 193 | 236 | if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) { |
| 194 | - require_once( self::plugin_path( 'deprecated/functions.php' ) ); | |
| 237 | + require_once self::plugin_path( 'deprecated/functions.php' ); | |
| 195 | 238 | } |
| 196 | 239 | |
| 197 | 240 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 198 | 241 | WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); |
| @@ -225,9 +268,9 @@ | ||
| 225 | 268 | /* translators: %s function name. */ |
| 226 | 269 | __( '%s() was called before the Action Scheduler data store was initialized', 'action-scheduler' ), |
| 227 | 270 | esc_attr( $function_name ) |
| 228 | 271 | ); |
| 229 | - _doing_it_wrong( $function_name, $message, '3.1.6' ); | |
| 272 | + _doing_it_wrong( esc_html( $function_name ), esc_html( $message ), '3.1.6' ); | |
| 230 | 273 | } |
| 231 | 274 | |
| 232 | 275 | return self::$data_store_initialized; |
| 233 | 276 | } |
| @@ -280,9 +323,9 @@ | ||
| 280 | 323 | 'Scheduler' => true, |
| 281 | 324 | ); |
| 282 | 325 | |
| 283 | 326 | $segments = explode( '_', $class ); |
| 284 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; | |
| 327 | + $segment = isset( $segments[1] ) ? $segments[1] : $class; | |
| 285 | 328 | |
| 286 | 329 | return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ]; |
| 287 | 330 | } |
| 288 | 331 | |
| @@ -302,25 +345,40 @@ | ||
| 302 | 345 | 'ProgressBar' => true, |
| 303 | 346 | ); |
| 304 | 347 | |
| 305 | 348 | $segments = explode( '_', $class ); |
| 306 | - $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class; | |
| 349 | + $segment = isset( $segments[1] ) ? $segments[1] : $class; | |
| 307 | 350 | |
| 308 | 351 | return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ]; |
| 309 | 352 | } |
| 310 | 353 | |
| 354 | + /** | |
| 355 | + * Clone. | |
| 356 | + */ | |
| 311 | 357 | final public function __clone() { |
| 312 | - trigger_error("Singleton. No cloning allowed!", E_USER_ERROR); | |
| 358 | + trigger_error( 'Singleton. No cloning allowed!', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error | |
| 313 | 359 | } |
| 314 | 360 | |
| 361 | + /** | |
| 362 | + * Wakeup. | |
| 363 | + */ | |
| 315 | 364 | final public function __wakeup() { |
| 316 | - trigger_error("Singleton. No serialization allowed!", E_USER_ERROR); | |
| 365 | + trigger_error( 'Singleton. No serialization allowed!', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error | |
| 317 | 366 | } |
| 318 | 367 | |
| 368 | + /** | |
| 369 | + * Construct. | |
| 370 | + */ | |
| 319 | 371 | final private function __construct() {} |
| 320 | 372 | |
| 321 | 373 | /** Deprecated **/ |
| 322 | 374 | |
| 375 | + /** | |
| 376 | + * Get DateTime object. | |
| 377 | + * | |
| 378 | + * @param null|string $when Date/time string. | |
| 379 | + * @param string $timezone Timezone string. | |
| 380 | + */ | |
| 323 | 381 | public static function get_datetime_object( $when = null, $timezone = 'UTC' ) { |
| 324 | 382 | _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' ); |
| 325 | 383 | return as_get_datetime_object( $when, $timezone ); |
| 326 | 384 | } |