Geen omschrijving

class-wc-queue.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * WC Queue
  4. *
  5. * @version 3.5.0
  6. * @package WooCommerce\Interface
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. exit; // Exit if accessed directly.
  10. }
  11. /**
  12. * WC Queue
  13. *
  14. * Singleton for managing the WC queue instance.
  15. *
  16. * @version 3.5.0
  17. */
  18. class WC_Queue {
  19. /**
  20. * The single instance of the queue.
  21. *
  22. * @var WC_Queue_Interface|null
  23. */
  24. protected static $instance = null;
  25. /**
  26. * The default queue class to initialize
  27. *
  28. * @var string
  29. */
  30. protected static $default_cass = 'WC_Action_Queue';
  31. /**
  32. * Single instance of WC_Queue_Interface
  33. *
  34. * @return WC_Queue_Interface
  35. */
  36. final public static function instance() {
  37. if ( is_null( self::$instance ) ) {
  38. $class = self::get_class();
  39. self::$instance = new $class();
  40. self::$instance = self::validate_instance( self::$instance );
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * Get class to instantiate
  46. *
  47. * And make sure 3rd party code has the chance to attach a custom queue class.
  48. *
  49. * @return string
  50. */
  51. protected static function get_class() {
  52. if ( ! did_action( 'plugins_loaded' ) ) {
  53. wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before plugins_loaded.', 'woocommerce' ), '3.5.0' );
  54. }
  55. return apply_filters( 'woocommerce_queue_class', self::$default_cass );
  56. }
  57. /**
  58. * Enforce a WC_Queue_Interface
  59. *
  60. * @param WC_Queue_Interface $instance Instance class.
  61. * @return WC_Queue_Interface
  62. */
  63. protected static function validate_instance( $instance ) {
  64. if ( false === ( $instance instanceof WC_Queue_Interface ) ) {
  65. $default_class = self::$default_cass;
  66. /* translators: %s: Default class name */
  67. wc_doing_it_wrong( __FUNCTION__, sprintf( __( 'The class attached to the "woocommerce_queue_class" does not implement the WC_Queue_Interface interface. The default %s class will be used instead.', 'woocommerce' ), $default_class ), '3.5.0' );
  68. $instance = new $default_class();
  69. }
  70. return $instance;
  71. }
  72. }