# packeta/trunk/src/Packetery/Module/Api/BaseRouter.php

Packeta, version trunk. 61 lines.

- Page: https://pluginprobe.com/plugins/packeta/trunk/code/src/Packetery/Module/Api/BaseRouter.php
- Raw: https://pluginprobe.com/plugins/packeta/trunk/raw/src/Packetery/Module/Api/BaseRouter.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/Api/BaseRouter.php#L10-L20`.

```php
<?php
/**
 * Class BaseRouter
 *
 * @package Packetery
 */

declare( strict_types=1 );

namespace Packetery\Module\Api;

/**
 * Class BaseRouter
 *
 * @package Packetery
 */
class BaseRouter {

	/**
	 * Namespace.
	 *
	 * @var string
	 */
	protected $namespace;

	/**
	 * Rest base.
	 *
	 * @var string
	 */
	protected $restBase;

	/**
	 * Gets route URL.
	 *
	 * @param string $path Short relative URL path.
	 */
	public function getRouteUrl( string $path ): string {
		return get_rest_url( null, $this->namespace . $this->getRoute( $path ) );
	}

	/**
	 * Gets route.
	 *
	 * @param string $path Short relative URL path.
	 */
	public function getRoute( string $path ): string {
		return "/{$this->restBase}{$path}";
	}

	/**
	 * Register route.
	 *
	 * @param string $path   Short relative URL path.
	 * @param array  $params Route configuration.
	 */
	public function registerRoute( string $path, array $params ): void {
		register_rest_route( $this->namespace, $this->getRoute( $path ), $params );
	}
}

```
