PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Api / BaseRouter.php

BaseRouter.php in Packeta 2.1, at src/Packetery/Module/Api/BaseRouter.php

61 lines 1007 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class BaseRouter
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Api;
11
12 /**
13 * Class BaseRouter
14 *
15 * @package Packetery
16 */
17 class BaseRouter {
18
19 /**
20 * Namespace.
21 *
22 * @var string
23 */
24 protected $namespace;
25
26 /**
27 * Rest base.
28 *
29 * @var string
30 */
31 protected $restBase;
32
33 /**
34 * Gets route URL.
35 *
36 * @param string $path Short relative URL path.
37 */
38 public function getRouteUrl( string $path ): string {
39 return get_rest_url( null, $this->namespace . $this->getRoute( $path ) );
40 }
41
42 /**
43 * Gets route.
44 *
45 * @param string $path Short relative URL path.
46 */
47 public function getRoute( string $path ): string {
48 return "/{$this->restBase}{$path}";
49 }
50
51 /**
52 * Register route.
53 *
54 * @param string $path Short relative URL path.
55 * @param array $params Route configuration.
56 */
57 public function registerRoute( string $path, array $params ): void {
58 register_rest_route( $this->namespace, $this->getRoute( $path ), $params );
59 }
60 }
61