class-admin-asset-analysis-worker-location.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Represents a way to determine the analysis worker asset location.
  9. */
  10. final class WPSEO_Admin_Asset_Analysis_Worker_Location implements WPSEO_Admin_Asset_Location {
  11. /**
  12. * @var WPSEO_Admin_Asset_Location $asset_location.
  13. */
  14. private $asset_location;
  15. /**
  16. * @var WPSEO_Admin_Asset $asset.
  17. */
  18. private $asset;
  19. /**
  20. * Constructs the location of the analysis worker asset.
  21. *
  22. * @param string $flat_version The flat version of the asset.
  23. * @param string $name The name of the analysis worker asset.
  24. */
  25. public function __construct( $flat_version = '', $name = 'analysis-worker' ) {
  26. if ( $flat_version === '' ) {
  27. $asset_manager = new WPSEO_Admin_Asset_Manager();
  28. $flat_version = $asset_manager->flatten_version( WPSEO_VERSION );
  29. }
  30. $this->asset_location = WPSEO_Admin_Asset_Manager::create_default_location();
  31. $this->asset = new WPSEO_Admin_Asset( array(
  32. 'name' => $name,
  33. 'src' => 'wp-seo-' . $name . '-' . $flat_version,
  34. ) );
  35. }
  36. /**
  37. * Retrieves the analysis worker asset.
  38. *
  39. * @return WPSEO_Admin_Asset The analysis worker asset.
  40. */
  41. public function get_asset() {
  42. return $this->asset;
  43. }
  44. /**
  45. * Determines the URL of the asset on the dev server.
  46. *
  47. * @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
  48. * @param string $type The type of asset. Usually JS or CSS.
  49. *
  50. * @return string The URL of the asset.
  51. */
  52. public function get_url( WPSEO_Admin_Asset $asset, $type ) {
  53. return $this->asset_location->get_url( $asset, $type );
  54. }
  55. }