class-wp-dependency.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Dependencies API: _WP_Dependency class
  4. *
  5. * @since 4.7.0
  6. *
  7. * @package WordPress
  8. * @subpackage Dependencies
  9. */
  10. /**
  11. * Class _WP_Dependency
  12. *
  13. * Helper class to register a handle and associated data.
  14. *
  15. * @access private
  16. * @since 2.6.0
  17. */
  18. class _WP_Dependency {
  19. /**
  20. * The handle name.
  21. *
  22. * @since 2.6.0
  23. * @var null
  24. */
  25. public $handle;
  26. /**
  27. * The handle source.
  28. *
  29. * @since 2.6.0
  30. * @var null
  31. */
  32. public $src;
  33. /**
  34. * An array of handle dependencies.
  35. *
  36. * @since 2.6.0
  37. * @var array
  38. */
  39. public $deps = array();
  40. /**
  41. * The handle version.
  42. *
  43. * Used for cache-busting.
  44. *
  45. * @since 2.6.0
  46. * @var bool|string
  47. */
  48. public $ver = false;
  49. /**
  50. * Additional arguments for the handle.
  51. *
  52. * @since 2.6.0
  53. * @var null
  54. */
  55. public $args = null; // Custom property, such as $in_footer or $media.
  56. /**
  57. * Extra data to supply to the handle.
  58. *
  59. * @since 2.6.0
  60. * @var array
  61. */
  62. public $extra = array();
  63. /**
  64. * Translation textdomain set for this dependency.
  65. *
  66. * @since 5.0.0
  67. * @var string
  68. */
  69. public $textdomain;
  70. /**
  71. * Translation path set for this dependency.
  72. *
  73. * @since 5.0.0
  74. * @var string
  75. */
  76. public $translations_path;
  77. /**
  78. * Setup dependencies.
  79. *
  80. * @since 2.6.0
  81. * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
  82. * to the function signature.
  83. *
  84. * @param ...$args Dependency information.
  85. */
  86. public function __construct( ...$args ) {
  87. list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = $args;
  88. if ( ! is_array( $this->deps ) ) {
  89. $this->deps = array();
  90. }
  91. }
  92. /**
  93. * Add handle data.
  94. *
  95. * @since 2.6.0
  96. *
  97. * @param string $name The data key to add.
  98. * @param mixed $data The data value to add.
  99. * @return bool False if not scalar, true otherwise.
  100. */
  101. public function add_data( $name, $data ) {
  102. if ( ! is_scalar( $name ) ) {
  103. return false;
  104. }
  105. $this->extra[ $name ] = $data;
  106. return true;
  107. }
  108. /**
  109. * Sets the translation domain for this dependency.
  110. *
  111. * @since 5.0.0
  112. *
  113. * @param string $domain The translation textdomain.
  114. * @param string $path Optional. The full file path to the directory containing translation files.
  115. *
  116. * @return bool False if $domain is not a string, true otherwise.
  117. */
  118. public function set_translations( $domain, $path = null ) {
  119. if ( ! is_string( $domain ) ) {
  120. return false;
  121. }
  122. $this->textdomain = $domain;
  123. $this->translations_path = $path;
  124. return true;
  125. }
  126. }