# packeta/trunk/src/Packetery/Module/Views/UrlBuilder.php

Packeta, version trunk. 37 lines.

- Page: https://pluginprobe.com/plugins/packeta/trunk/code/src/Packetery/Module/Views/UrlBuilder.php
- Raw: https://pluginprobe.com/plugins/packeta/trunk/raw/src/Packetery/Module/Views/UrlBuilder.php
- Modified: 2025-03-10T10:47:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/packeta/trunk/code/src/Packetery/Module/Views/UrlBuilder.php#L10-L20`.

```php
<?php

declare( strict_types=1 );

namespace Packetery\Module\Views;

use Packetery\Module\Framework\WpAdapter;

class UrlBuilder {
	/**
	 * @var WpAdapter
	 */
	private $wpAdapter;

	public function __construct( WpAdapter $wpAdapter ) {
		$this->wpAdapter = $wpAdapter;
	}

	/**
	 * Builds asset URL.
	 *
	 * @param string $asset Relative asset path without leading slash.
	 *
	 * @return string|null
	 */
	public function buildAssetUrl( string $asset ): ?string {
		$url      = $this->wpAdapter->pluginDirUrl( PACKETERY_PLUGIN_DIR . '/packeta.php' ) . $asset;
		$filename = PACKETERY_PLUGIN_DIR . '/' . $asset;

		if ( ! file_exists( $filename ) ) {
			return null;
		}

		return $this->wpAdapter->addQueryArg( [ 'v' => md5( (string) filemtime( $filename ) ) ], $url );
	}
}

```
